16_钉钉告警实战

钉钉企业的地址

企业钉钉

登录企业钉钉

  1. 通讯录管理里面的userid在发钉钉的时候需要用到
  2. 工作台里可以自建应用
  3. 微应用管理可以管理应用
  4. 开发账号管理可以查看密码信息

发钉钉告警的脚本(加执行权限chmod a+x zabbix_dd.py)

#!/usr/bin/python
# -*- coding:utf-8 -*-
# zabbix_dd.py
import json,sys,urllib2

appkey="xxx"
appsecret="xxx" 
agentid="xxx" 
touser=sys.argv[1]
content=sys.argv[2] 

token_url='https://oapi.dingtalk.com/gettoken?corpid='+appkey+'&corpsecret='+appsecret
tokenresponse=urllib2.urlopen(tokenurl)
tokenresult=json.loads(tokenresponse.read().decode('utf-8'))
token=tokenresult['access_token']
sendurl='https://oapi.dingtalk.com/message/send?access_token'+token
headers={
  'Content_Type':'application/json'
}
main_content={
  "touser":touser,
  "toparty":"",
  "agentid":agentid,
  "msgtype":"text",
  "text":{
    "content":content,
  }
}
main_content=json.dumps(main_content)
req=urllib2.Request(sendurl,headers=headers)
response=urllib2.urlopen(req,main_content.encode("utf-8"))
print(response.read().decode("utf-8"))

测试脚本:/usr/local/zabbix/alertscripts/zabbix_dd.py 'chiss' 'disk using > 90%'

zabbix钉钉告警配置步骤

类似微信告警

  1. 写一个钉钉告警脚本
  2. 报警媒介添加钉钉告警
  3. 用户设置报警媒介
  4. 创建触发动作