首先建钉钉群,添加一个自定义机器人拿到webhook
zabbix添加一个报警媒介
搞一个shell脚本来启动Python脚本(直接用zabbix调Python脚本不行,不知道什么原因)
vim dingding.sh echo "$1" > /tmp/dingding.log python /etc/zabbix/alertscripts/dingding.py "$1"
#!/usr/bin/env python #coding: utf-8 import json,urllib2,sys def dingding(message): url = "https://oapi.dingtalk.com/robot/send?access_token=xxxx" header = { "Content-Type": "application/json", "charset": "utf-8" } data = { "msgtype": "text", "text": { "content": message } } sendData = json.dumps(data) request = urllib2.Request(url,data = sendData,headers = header) urlopen = urllib2.urlopen(request) return urlopen.read() def main(): message = sys.argv[1] dingding(message) if __name__ == "__main__": main()
来源:https://www.cnblogs.com/37yan/p/7602580.html