cloudera 管理员调整报警标题的两种方法

来源:互联网 发布:焊接机器人模拟软件 编辑:程序博客网 时间:2024/06/05 00:00

方法1

最简单方式就是在alert配置页面,将title设置成集群的名字

这里写图片描述

方法2

就是所谓的script方法,虽然官方import介绍script只是可以用在企业版本里面,可是我发现在我们的非企业版本里面也是可以用的,而且一旦配置,报警将会同时发出两份儿。

脚本大致原理是 我们提供一个脚本alert.sh, cdh alert publisher在调用的时候会执行

“`
/xxx/alert.sh xxx.json
““

我们alert.sh会将xxx.json作为变量传递给我们的处理函数alert.py,然后将alert.py执行后得到的消息作为message,然后再调用sendemail来发送右键.

官网参考:
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服务" -xu myalter -xp q3UHwna4nfO0G2xf -o message-charset=utf-8 -m "$alertstring"# 发送给谁tos="wangyg@iiot.ac.cn"./sendemail -f xxx -t xxx -s smtp.exmail.qq.com -u "[Alert]  CDH服务" -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
0 0
原创粉丝点击