最簡單方式就是在alert配置頁面,將title設(shè)置成集群的名字
就是所謂的script方法,雖然官方import介紹script只是可以用在企業(yè)版本里面,可是我發(fā)現(xiàn)在我們的非企業(yè)版本里面也是可以用的,而且一旦配置,報警將會同時發(fā)出兩份兒。
腳本大致原理是 我們提供一個腳本alert.sh, cdh alert publisher在調(diào)用的時候會執(zhí)行
“` /xxx/alert.sh xxx.json ““
我們alert.sh會將xxx.json作為變量傳遞給我們的處理函數(shù)alert.py,然后將alert.py執(zhí)行后得到的消息作為message,然后再調(diào)用sendemail來發(fā)送右鍵.
官網(wǎng)參考: https://www.cloudera.com/documentation/enterPRise/5-5-x/topics/cm_ag_alert_script.html
腳本 : alert.sh#!/bin/bashcd /opt/cm-5.5.0/sbinecho $1 >> /tmp/list.alertalertstring=`./alert.py $1`echo $alertstring#./sendemail -f myalter@vip.126.com -t wangyg@iiot.ac.cn -s smtp.vip.126.com -u "[Alert] MM CDH服務(wù)" -xu myalter -xp q3UHwna4nfO0G2xf -o message-charset=utf-8 -m "$alertstring"# 發(fā)送給誰tos="wangyg@iiot.ac.cn"./sendemail -f xxx -t xxx -s smtp.exmail.QQ.com -u "[Alert] CDH服務(wù)" -xu 賬號 -xp 密碼 -o message-charset=utf-8 -m "$alertstring"alert.py#!/usr/bin/env python#coding: utf8import sysimport jsonmyfile=sys.argv[1]with open(myfile) as data_file: data = json.load(data_file)for i in range(0,len(data)): print "Alert %s"%(i) print "集群名字:", print data[i]["body"]["alert"]["attributes"]["CLUSTER_DISPLAY_NAME"][0] print "報警描述:", print data[i]["body"]["alert"]["attributes"]["ALERT_SUMMARY"][0] print "/n"sendemail https://github.com/mogaal/sendemail新聞熱點
疑難解答