zabbix利用python3脚本进行钉钉报警
1.新建脚本dingding.py内容如下 注意需要用unix格式 不然会报错/usr/bin/python3^M
#!/usr/bin/python3
import requests
import json
import sys
import os
headers = {'Content-Type': 'application/json;charset=utf-8'}
api_url = "机器人url"
def msg(text):
json_text= {
"msgtype": "text",
"at": {
"atMobiles": [
"需要在群里艾特的人的手机号"
],
"isAtAll": False
},
"text": {
"content": text
}
}
print (requests.post(api_url,json.dumps(json_text),headers=headers).content)
if __name__ == '__main__':
text = sys.argv[1]
msg(text)
2.pip3 install requests 安装requests
3.chmod 777 /usr/lib/zabbix/alertscripts/dingding.py 授权
chmod 777 /usr/lib/zabbix/alertscripts/dingding.py
注意如下图需要添加读写权限
4.安装编译的一大堆 yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel libffi-devel gcc make
5.参考链接 https://www.cnblogs.com/shipment/p/13347279.html#1-%E5%9C%A8%E9%92%89%E9%92%89%E4%B8%AD%E5%88%9B%E5%BB%BA%E7%BE%A4%E8%81%8A%E5%9C%A8%E7%BE%A4%E9%87%8C%E9%9D%A2%E6%B7%BB%E5%8A%A0%E8%87%AA%E5%AE%9A%E4%B9%89%E6%9C%BA%E5%99%A8%E4%BA%BA