zabbix3.4搭建钉钉报警
1.在钉钉群里添加一个自定义的机器

在设置说明中无需开启Outgoing机制

红色箭头指的信息很重要后面脚本会用到
2.脚本
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Author: aiker@gdedu.ml
# My blog http://m51cto.51cto.blog.com
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=37e23308d1b84eb4ac34566e03c4c4e74bxxxxxxxxxxxxxx"
def msg(text):
json_text= {
"msgtype": "text",
"at": {
"atMobiles": [
"13xxxxxxx80"
],
"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)
chmod +x dingdingrobot.py
脚本测试,python2
python dingdingrobot.py 123
参考博客:https://blog.51cto.com/m51cto/2051945

浙公网安备 33010602011771号