

[root@zabbix_server ~]# egrep -v "^$|#" /etc/zabbix/zabbix_server.conf LogFile=/var/log/zabbix/zabbix_server.log LogFileSize=0 PidFile=/var/run/zabbix/zabbix_server.pid SocketDir=/var/run/zabbix DBHost=localhost DBName=zabbix DBUser=zabbix DBPassword=zabbix SNMPTrapperFile=/var/log/snmptrap/snmptrap.log Timeout=4 AlertScriptsPath=/usr/lib/zabbix/alertscripts ExternalScripts=/usr/lib/zabbix/externalscripts LogSlowQueries=3000
#!/usr/bin/python
# -*- coding: utf-8 -*-
import requests
import json
import sys
import os
headers = {‘Content-Type‘: ‘application/json;charset=utf-8‘}
api_url = "https://oapi.dingtalk.com/robot/send?access_token=写自己的"
def msg(text):
json_text= {
"msgtype": "text",
"at": {
"atMobiles": [
"187********"
],
"isAtAll": True
},
"text": {
"content": text
}
}
print requests.post(api_url,json.dumps(json_text),headers=headers).content
if __name__ == ‘__main__‘:
text = sys.argv[1]
msg(text)
[root@zabbix_server alertscripts]# chmod +x ding.py
[root@zabbix_server alertscripts]# ./ding.py dingding
Traceback (most recent call last):
File "./ding.py", line 4, in <module>
import requests
ImportError: No module named requests
[root@zabbix_server alertscripts]# yum -y install epel-release
[root@zabbix_server alertscripts]# yum -y install python-pip
[root@zabbix_server alertscripts]# pip install requests
[root@zabbix_server alertscripts]# ./ding.py dingding






服务器:{HOST.NAME} 发生:{TRIGGER.NAME}故障!dingding
{
告警主机:{HOST.NAME}
告警地址:{HOST.IP}
监控项目:{ITEM.NAME}
监控取值:{ITEM.LASTVALUE}
告警等级:{TRIGGER.SEVERITY}
当前状态:{TRIGGER.STATUS}
告警信息:{TRIGGER.NAME}
告警时间:{EVENT.DATE} {EVENT.TIME}
事件ID:{EVENT.ID}
}


完成钉钉告警触发!!
原文:https://www.cnblogs.com/psc0218/p/12993240.html