创建钉钉机器人
登录钉钉客户端,创建一个群,把需要收到报警信息的人员都拉到这个群内.然后点击群右上角的"群机器人"->"添加机器人"->"自定义",记录该机器人的webhook值!
zabbix-server
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
[root@king ~]# cat /usr/local/zabbix/etc/zabbix_server.conf |grep ^AlertScriptsPath AlertScriptsPath=/usr/local/zabbix/lib/zabbix/alertscripts 进入到/usr/local/zabbix/alertscripts下编写dingding.py脚本(脚本中包含钉钉机器人的webhook值): [root@king ~]# cd /usr/local/zabbix/lib/zabbix/alertscripts [root@king alertscripts]# cat dingding.py #!/usr/bin/env python #coding:utf-8 #zabbix钉钉报警 import requests,json,sys,os,datetime webhook="https://oapi.dingtalk.com/robot/send?access_token=8ea7abd3db4b49a9e898e911920d4899c526ae78f5794c977cfca8b6c0bjsdd" #说明:这里改为自己创建的机器人的webhook的值 user=sys.argv[1] text=sys.argv[3] data={ "msgtype": "text", "text": { "content": text }, "at": { "atMobiles": [ user ], "isAtAll": False } } headers = {'Content-Type': 'application/json'} x=requests.post(url=webhook,data=json.dumps(data),headers=headers) if os.path.exists("/usr/local/zabbix/log/dingding.log"): f=open("/usr/local/zabbix/log/dingding.log","a+") else: f=open("/usr/local/zabbix/log/dingding.log","w+") f.write("\n"+"--"*30) if x.json()["errcode"] == 0: f.write("\n"+str(datetime.datetime.now())+" "+str(user)+" "+"发送成功"+"\n"+str(text)) f.close() else: f.write("\n"+str(datetime.datetime.now()) + " " + str(user) + " " + "发送失败" + "\n" + str(text)) f.close() 赋予脚本执行权限 [root@king alertscripts]# chmod +x dingding.py 创建上面脚本中的日志路径 [root@king alertscripts]# mkdir /usr/local/zabbix/log/ [root@king alertscripts]# touch /usr/local/zabbix/log/dingding.log [root@king alertscripts]# chown zabbix.zabbix /usr/local/zabbix/log/dingding.log
测试,查看钉钉是否收到消息
[root@king alertscripts]# ./dingding.py test gaojing "test"
登录zabbix,并且配置
最后停掉php的服务,检测是否收到信息。
本文来自博客园,作者:topass123,转载请注明原文链接:https://www.cnblogs.com/topass123/articles/12537147.html