Based on the previous article《Zabbix 5.0 LTS URL Health Monitoring》environment, realizing enterprise WeChat (Webhook) to automatically send alarm information.
I. Creating an Enterprise WeChat Robot
-
Start by creating a bot in your business WeChat group and get its WebHook address. Right-click on the group chat card to add a group bot.
Obtain a WebHook address similar to the one shown below. Note that this WebHook address is very important and should not be disclosed.# The value of the key is unique /cgi-bin/webhook/send?key=b55ed8ad-6765-4e8b-827c-xxxxxxxxxxx
II. Medium of creation
Steps: Configure -- Alarm Media Types -- Create Media Type -- Add
Script content (fixed style)
var Qiyeweixin = {
key: null,
message: null,
msgtype: "markdown",
proxy: null,
sendMessage: function () {
var params = {
msgtype: ,
markdown: {
content: ,
},
},
data,
response,
request = new CurlHttpRequest(),
url =
"/cgi-bin/webhook/send?key=" +
;
if () {
();
}
("Content-Type: application/json");
data = (params);
// Remove replace() function if you want to see the exposed key in the log file.
(
4,
"[Qiyeweixin Webhook] URL: " + (, "<BOT KEY>")
);
(4, "[Qiyeweixin Webhook] params: " + data);
response = (url, data);
(4, "[Qiyeweixin Webhook] HTTP code: " + ());
try {
response = (response);
} catch (error) {
response = null;
}
if (() !== 200 || !== 0) {
if (typeof === "string") {
throw ;
} else {
throw "Unknown error. Check debug log for more information.";
}
}
},
};
try {
var params = (value);
if (typeof === "undefined") {
throw 'Incorrect value is given for parameter "Key": parameter is missing';
}
= ;
if () {
= ;
}
= ;
= + "\n" + ;
();
return "OK";
} catch (error) {
(4, "[Qiyeweixin Webhook] notification failed: " + error);
throw "Sending failed: " + error + ".";
}
III. Creation of actions
Steps: Configuration -- Action -- New Trigger Condition -- Add
Custom message
Fault message: {}
Server: {HOSTNAME1} Occurrence: {} Fault!
Alarm host: {HOSTNAME1}
Alarm time: {} {}
Alarm level: {}
Alarm message: {}
Alert item: {TRIGGER.KEY1}
Problem details: {}: {}
Current Status: {}: {ITEM.VALUE1}
Event ID: {}
Recovery Information: {}
Server: {} Occurrence: {} Fault Recovery!
Alert host: {}
Alert address: {}
Monitor Item: {}
Monitor values: {}
Alarm Level: {}
Current status: {}
Alarm message:{}
Alarm time:{} {}
Event ID: {}
Update information: {}
Server: {} occurred: {} fault update!
Alert Host: {}
Alert address: {}
Monitor Item: {}
Monitor values: {}
Alarm Level: {}
Current status: {}
Alarm message:{}
Alarm time:{} {}
Event ID: {}
IV. Configuring users
Verification results
Web Scenarios - Step -- Intentionally misspelling a URL triggers an alert.