CDH 5.11.0
Article catalog
Configure enterprise wechat early warning function
1. Sign up for a new shampoo wechat account
https://work.weixin.qq.com/wework_admin/register_wx?from=myhome
2. Add an address book group, that is, alert group, and add alert person
3. Create a new application, alert application
Group can be specified when adding an app
4. This is used for early warning (enterprise ID, AgentId, Secret)
My business:
5. Configure script to send alert
alert.sh
#!/usr/bin/env bash CLUSTER=`cat $1 | python /opt/cloudera/alert.py` echo $CLUSTER
alert.py
#!/usr/bin/env python #coding: utf8 import os import time import urllib2 import json import sys reload(sys) sys.setdefaultencoding('utf-8') myfile = sys.stdin data = json.load(myfile) for i in range(0, len(data)): alert = data[i]["body"]["alert"]["attributes"] alertSummary = alert["ALERT_SUMMARY"] for summary in alertSummary: print "ALERT_SUMMARY: ", print summary healthResult = alert["HEALTH_TEST_RESULTS"] for result in healthResult: print "content: ", print result["content"] print "testName: ", print result["testName"] print "" # Enterprise ID wxid = "wwXXX" # App ID depid = "100001111" # Authentication password secret = "U37SXXXXXXXXXXX" msg = result["content"] # Get current time date_time = time.strftime("%Y-%m-%d %X") url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=" + \ wxid + "&corpsecret=" + secret request = urllib2.Request(url) response = urllib2.urlopen(request) recv_info = response.read() recv_info = eval(recv_info) wx_token = recv_info['access_token'] msg_url = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=" + wx_token send_msg = { "touser": "@all", "msgtype": "text", "agentid": depid, "text": {"content": msg}, "safe": 0 } send_msg_json = json.dumps(send_msg) request_post = urllib2.urlopen(msg_url,send_msg_json) recv_msg = request_post.read()
Cloudera Management Service configuration
Path fill in alert script path
Restart Cloudera Management Service!
test
Because some services of the test environment cluster have been suspended, you can directly check the logs to see whether the configuration is effective:
tail -200f mgmt-cmf-mgmt-ALERTPUBLISHER-zt01.log.out
The log shows that the alert script has been executed successfully. View the wechat: