钉钉报警--zabbix
创建钉钉机器人创建脚本钉钉报警脚本[root@zabbix-server ~]# cd /usr/lib/zabbix/alertscripts[root@zabbix-server alertscripts]# vim dingding.py#!/usr/bin/python# -*- coding: utf-8 -*-# Author: sxdswc999imp...
·
创建钉钉机器人
创建脚本钉钉报警脚本
[root@zabbix-server ~]# cd /usr/lib/zabbix/alertscripts
[root@zabbix-server alertscripts]# vim dingding.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Author: sxdswc999
import requests
import json
import sys
import os
headers = {'Content-Type': 'application/json;charset=utf-8'}
api_url = "" #机器人的Webhook地址
def msg(text):
json_text= {
"msgtype": "text",
"text": {
"content": text
},
"at": {
"atMobiles": [
"" #手机号
],
"isAtAll": False
}
}
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 a+x dingding.py
添加python 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
测试脚本是否可行
zabbix端页面配置
更多推荐
已为社区贡献3条内容
所有评论(0)