Appearance
告警
Zabbix常用告警分为三种,邮件,钉钉,企业微信
我们分别对这三种进行配置
1. 站内告警配置

2. 邮件告警
告警通知模板:
html
告警主机:{HOSTNAME1} <br>
主机IP: {HOST.IP} <br>
告警时间:{EVENT.DATE} {EVENT.TIME}<br>
告警等级:{TRIGGER.SEVERITY}<br>
告警对象:{TRIGGER.KEY1}<br>
告警信息:{TRIGGER.NAME}<br>
问题详情:{ITEM.NAME}:{ITEM.VALUE}<br>
当前状态:{TRIGGER.STATUS}<br>
事件ID:{EVENT.ID}<br>
告警恢复模板:
html
告警主机:{HOSTNAME1}<br>
主机IP: {HOST.IP} <br>
告警时间:{EVENT.DATE} {EVENT.TIME}<br>
恢复时间:{EVENT.RECOVERY.DATE} {EVENT.RECOVERY.TIME}<br>
告警等级:{TRIGGER.SEVERITY}<br>
告警对象:{TRIGGER.KEY1}<br>
告警信息:{TRIGGER.NAME}<br>
问题详情:{ITEM.NAME}:{ITEM.VALUE}<br>
当前状态:{TRIGGER.STATUS}<br>
事件ID:{EVENT.ID}<br>
创建一个邮箱告警媒介,也可以编辑原有的告警,禁用其他所有的告警方式避免出现发送失败告警

配置邮件相关信息

添加模版消息

复制模版 添加告警以及告警恢复模版即可

配置完成后需要启用触发器动作,否则不会往邮箱里发送

配置接收告警的用户


此时邮箱已经可以接收到告警了
3. 钉钉告警
告警通知模板:
markdown
## 故障发现
#### 告警主机:{HOSTNAME1}
#### 主机IP: {HOST.IP}
#### 告警时间:{EVENT.DATE} {EVENT.TIME}
#### 告警等级:{TRIGGER.SEVERITY}
#### 告警对象:{TRIGGER.KEY1}
#### 告警信息:{TRIGGER.NAME}
#### 问题详情:{ITEM.NAME}:{ITEM.VALUE}
#### 当前状态:{TRIGGER.STATUS}
#### 事件ID:{EVENT.ID}
告警恢复模板:
markdown
## 故障恢复
#### 告警主机:{HOSTNAME1}
#### 主机IP: {HOST.IP}
#### 告警时间:{EVENT.DATE} {EVENT.TIME}
#### 恢复时间:{EVENT.RECOVERY.DATE} {EVENT.RECOVERY.TIME}
#### 告警等级:{TRIGGER.SEVERITY}
#### 告警对象:{TRIGGER.KEY1}
#### 告警信息:{TRIGGER.NAME}
#### 问题详情:{ITEM.NAME}:{ITEM.VALUE}
#### 当前状态:{TRIGGER.STATUS}
#### 事件ID:{EVENT.ID}
测试机器人是否可用
sh
[root@zbx ~]# curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=7f994c0c-36fb-4604-a83c-71cddb8c73b2' -H 'Content-Type:application/json' -d '{"msgtype":"text","text":{"content":"报警"}}'

脚本:
js
var Dingding = {
params: {},
proxy: null,
setParams: function (params) {
if (typeof params !== 'object') {
return;
}
Dingding.params = params;
},
request: function () {
var data = {
msgtype: "markdown",
markdown: {
title: "报警",
text: Dingding.params.Message,
},
at: {
atUserIds: [Dingding.params.To],
isAtAll: false,
},
},
response,
url = Dingding.params.URL,
request = new HttpRequest();
request.addHeader('Content-Type: application/json');
if (typeof Dingding.HTTPProxy !== 'undefined' && Dingding.HTTPProxy !== '') {
request.setProxy(Dingding.HTTPProxy);
}
if (typeof data !== 'undefined') {
data = JSON.stringify(data);
}
Zabbix.Log(4, "[Dingding Webhook] message is: " + data);
response = request.post(url, data);
Zabbix.log(4, '[ Dingding Webhook ] Received response with status code ' +
request.getStatus() + '\n' + response);
if (response !== null) {
try {
response = JSON.parse(response);
}
catch (error) {
Zabbix.log(4, '[ Dingding Webhook ] Failed to parse response received from Dingding');
response = null;
}
}
if (request.getStatus() !== 200 || response.errcode !== 0) {
var message = 'Request failed with status code '+request.getStatus();
if (response !== null && typeof response.errmsg !== 'undefined') {
message += ': '+ JSON.stringify(response.errmsg) ;
}
throw message + '. Check debug log for more information.';
}
return response;
},
};
try {
var params = JSON.parse(value);
if (typeof params.URL !== 'undefined'
&& typeof params.Message !== 'undefined') {
Zabbix.log(4, '[ Dingding Webhook ] webhookURL "' + params.URL +
'" sendto "'+ params.To )+'"';
}
else {
throw 'Missing parameter. URL, message, to parameter is required'
}
if (params.HTTPProxy) {
Dingding.proxy = params.HTTPProxy;
}
Dingding.setParams(params);
Dingding.request();
return 'OK';
}catch (error) {
Zabbix.log(3, '[ Dingding Webhook ] ERROR: ' + error);
throw 'Sending failed: ' + error;
}
4. 企业微信告警
js
var Wechat = {
params: {},
proxy: null,
setParams: function (params) {
if (typeof params !== 'object') {
return;
}
Wechat.params = params;
},
request: function () {
var data = {
msgtype: "markdown",
markdown: {
content: "## 通知:\n " + Wechat.params.Message,
},
},
response,
url = Wechat.params.URL,
request = new HttpRequest();
request.addHeader('Content-Type: application/json');
if (typeof data !== 'undefined') {
data = JSON.stringify(data);
}
Zabbix.Log(4, "[Wechat Webhook] message is: " + data);
response = request.post(url, data);
Zabbix.log(4, '[ Wechat Webhook ] Received response with status code ' +
request.getStatus() + '\n' + response);
if (response !== null) {
try {
response = JSON.parse(response);
}
catch (error) {
Zabbix.log(4, '[ Wechat Webhook ] Failed to parse response received from Wechat');
response = null;
}
}
if (request.getStatus() !== 200 || response.errcode !== 0) {
var message = 'Request failed with status code '+request.getStatus();
if (response !== null && typeof response.errmsg !== 'undefined') {
message += ': '+ JSON.stringify(response.errmsg) ;
}
throw message + '. Check debug log for more information.';
}
return response;
},
};
try {
var params = JSON.parse(value);
if (typeof params.URL !== 'undefined'
&& typeof params.Message !== 'undefined') {
Zabbix.log(4, '[ Wechat Webhook ] webhookURL "' + params.URL +
'" sendto "'+ params.To )+'"';
}
else {
throw 'Missing parameter. URL, message, to parameter is required'
}
if (params.HTTPProxy) {
Wechat.proxy = params.HTTPProxy;
}
Wechat.setParams(params);
Wechat.request();
return 'OK';
}catch (error) {
Zabbix.log(3, '[ Wechat Webhook ] ERROR: ' + error);
throw 'Sending failed: ' + error;
}