#!/usr/bin/python
# -*- coding: utf-8 -*-
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=e580dbc9d992b790f86136601d95582630afb345ebbf55b373ef5e2fdc92dd6b"
def msg(text):
json_text= {
"msgtype": "text",
"at": {
"atMobiles": [
"all"
],
"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)
指定api_url,需要在钉钉群主中添加机器人,然后将Webhook地址复制过来
如果想指定@某人的话,格式为:
"atMobiles": [
"130xxxxxxxx",
"135xxxxxxxx"
],
其次,在zabbix设置报警媒介时,需要添加这么一个参数
{ALERT.MESSAGE}