CDH configuration enterprise wechat early warning

Keywords: JSON Python

CDH 5.11.0

Article catalog

Configure enterprise wechat early warning function

1. Sign up for a new shampoo wechat account

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

#!/usr/bin/env bash

CLUSTER=`cat $1 | python /opt/cloudera/`


#!/usr/bin/env python

#coding: utf8

import os

import time

import urllib2

import json

import sys



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 = "" + \

        wxid + "&corpsecret=" + secret

    request = urllib2.Request(url)

    response = urllib2.urlopen(request)

    recv_info =

    recv_info = eval(recv_info) 

    wx_token = recv_info['access_token']

    msg_url = "" + 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 =

Cloudera Management Service configuration

Path fill in alert script path

Restart Cloudera Management Service!


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:

Posted by kof20012 on Mon, 11 May 2020 07:20:40 -0700