CDH和HDP配置自帶的郵件告警


一、CDH配置CM進行郵件告警

1、修改Cloudera Management Service的配置

輸入"alert"進行搜索:

基本配置如下

image

郵件服務器主機名稱: 根據自己實際情況選擇,可用smtp.163.com、smtp.qq.com等;
郵件服務器用戶名:    對應郵件服務器的郵箱賬號,比如  xxx@qq.com等;
郵件服務器密碼:      對應用戶名的密碼,如果使用QQ郵箱作為“郵件服務器用戶名”,那么這里的密碼要填寫QQ郵箱的授權碼,具體獲取授權碼的方法可百度,很簡單;
郵件發件人地址:      發件人地址一般可以與郵件服務器用戶名一樣;
郵件收件人:             接收報警信息的地址,可為任意可用郵件地址,只要網絡能通,如果使用多個收件箱,可以用英文逗號分割;

其他配置,看自己需求更改即可;


2、保存配置,重啟Cloudera Management Service

image


3、測試告警

如果是測試集群,可直接停止掉某個關鍵服務,看是否能收到告警郵件;

也可以使用 【管理->警報->發送測試警報】

image

image

這里我使用”發送測試警報”的方式:

點擊“發送測試警報”,然后稍等一下,已收到告警郵件

image



二、HDP中配置Ambari進行郵件告警

1、登錄ambari管理頁面,找到Manage Notifications選項

image

2、點擊+ 創建一個告警

image


3、配置告警

image

image

Email To:  郵件接收郵箱地址,如果使用多個收件箱,可以用英文逗號分割;

SMTP Server:郵件服務器地址;

SMTP Port:25

Email From:用於發送郵件的地址;

選中”Use authentication”,填寫發件箱地址和密碼;


4、定義發送郵件格式

下載 alert-templates.xml ,地址:

https://github.com/apache/ambari/blob/branch-2.1/ambari-server/src/main/resources/alert-templates.xml

這里列出alert-templates.xml 文件的全部內容:

<?xml version="1.0" encoding="UTF-8"?>
<!--
   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
-->
<alert-templates>
  <alert-template type="EMAIL">
    <subject>
      <![CDATA[Alert Summary: OK[$summary.getOkCount()], Warning[$summary.getWarningCount()], Critical[$summary.getCriticalCount()], Unknown[$summary.getUnknownCount()]]]>
    </subject>
    <body>
      <![CDATA[
#set( $alertStates = ["OK", "WARNING", "CRITICAL", "UNKNOWN"] )
#set( $services = $summary.getServices() )
<html>
  <style type="text/css">
    html {
      font-family:sans-serif;
      -webkit-text-size-adjust:100%;
      -ms-text-size-adjust:100%;
    }
    body {
      margin:10px;
    }
    footer,header {
      display:block;
    }
    table {
      border-spacing:0;
      border-collapse:collapse;
    }
    td,th {
      padding:10px;
    }
    .panel {
      margin-bottom:20px;
      background-color:#fff;
      border:1px solid transparent;
      border-radius:4px;
      -webkit-box-shadow:0 1px 1px rgba(0,0,0,.05);
      box-shadow:0 1px 1px rgba(0,0,0,.05);
    }
    .panel-body {
      padding:15px;
    }
    .panel-heading {
      padding:10px 15px;
      border-bottom:1px solid transparent;
      border-top-left-radius:3px;
      border-top-right-radius:3px;
    }
    .panel-title {
      margin-top:0;
      margin-bottom:0;
      font-size:16px;
      color:inherit;
    }
    .panel-default {
      border-color:#ddd;
    }
    .panel-default > .panel-heading {
      color:#333;
      background-color:#f5f5f5;
      border-color:#ddd;
    }
    .panel-primary {
      border-color: #337ab7;
    }
    .panel-primary > .panel-heading {
      color: #fff;
      background-color: #337ab7;
      border-color: #337ab7;
    }
    .label {
      display:inline;
      padding:.3em 1em;
      font-size:75%;
      font-weight:bold;
      line-height:1;
      color:#fff;
      text-align:center;
      white-space:nowrap;
      vertical-align:baseline;
      border-radius:.25em;
    }
    .label-unknown {
      background-color:#777;
    }
    .label-primary {
      background-color:#337ab7;
    }
    .label-ok {
      background-color:#5cb85c;
    }
    .label-warning {
      background-color:#f0ad4e;
    }
    .label-critical {
      background-color:#d9534f;
    }
    .label-small {
      font-size:12px;
    }
    .ambari-footer{
      font-family: Arial, Helvetica, sans-serif;
      font-size: 12px;
    }
  </style>
  <div class="panel panel-primary">
    <div class="panel-heading">
      <h3 class="panel-title">Services Reporting Alerts</h3>
    </div>
    <div class="panel-body">
      <table>
        #foreach( $alertState in $alertStates )
          #if( $summary.getServicesByAlertState($alertState)  )
            <tr>
              <td>
                <span class="label label-$alertState">$alertState</span>
              </td>
              <td>
                $summary.getServicesByAlertState($alertState)
              </td>
            </tr>
          #end
        #end
      </table>
    </div>
  </div>

  #foreach( $service in $services )
  <div class="panel panel-default">
    <div class="panel-heading">
      <h3 class="panel-title">$service</h3>
    </div>
    <div class="panel-body">
      <table>
        #foreach( $alertState in $alertStates )
            #foreach( $alert in $summary.getAlerts($service,$alertState) )
              <tr>
                <td>
                  <span class="label label-$alertState">$alertState</span>
                </td>
                <td>
                  $alert.getAlertDefinition().getLabel()
                  <div class="label-small">
                    $alert.getAlertText()
                  </div>
                  <div class="label-small">
                    Cluster: $alert.getAlertDefinition().getCluster().getClusterName()
                  </div>
                  #if( $alert.getHostName() )
                    #if( $ambari.hasUrl() )
                      <div class="label-small">
                      Host: <a href=$ambari.getUrl()/#/main/hosts/$alert.getHostName()/summary>$ambari.getUrl()/#/main/hosts/$alert.getHostName()/summary</a>
                      </div>
                    #else
                      <div class="label-small">
                        Host: $alert.getHostName()
                      </div>
                    #end
                  #end
                </td>
              </tr>
            #end
        #end
      </table>
    </div>
  </div>
  #end
  <div class="ambari-footer">
    This notification was sent to $dispatch.getTargetName()
    <br/>
    Apache Ambari $ambari.getServerVersion()
    #if( $ambari.hasUrl() )
    <br/>
    Ambari Server link: <a href=$ambari.getUrl()>$ambari.getUrl()</a>
    #end
  </div>
</html>
      ]]>
    </body>
  </alert-template>
  <alert-template type="SNMP">
    <subject>
      <![CDATA[[$alert.getAlertState()] $alert.getAlertName()]]>
    </subject>
    <body>
      <![CDATA[
[Alert] $alert.getAlertName()
[Service] $alert.getServiceName()
#if( $alert.hasComponentName() )
[Component] $alert.getComponentName()
#end
#if( $alert.hasHostName() )
[Host] $alert.getHostName()
#end

$alert.getAlertText()]]>
    </body>
  </alert-template>
</alert-templates>
View Code


將alert-templates.xml 文件放到Ambari服務器的 /var/lib/ambari-server/resources/ 下;

並且賦予755權限;

chmod 755 /var/lib/ambari-server/resources/alert-templates.xml


5、修改ambari的配置文件

編輯 /etc/ambari-server/conf/ambari.properties

在文件最后一行增加: alerts.template.file=/var/lib/ambari-server/resources/alert-templates.xml


6、重啟ambari server

ambari-server restart


7、測試告警

這里是測試集群,直接停掉了hbase的Hmaster

image

稍等片刻,已收到告警:

image


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM