|
Zabbix配置-钉钉机器人报警
转自:http://blog.运维网.com/m运维网/2051945
https://www.cnblogs.com/baishuchao/p/8608818.html
https://www.cnblogs.com/91king/articles/7766384.html
首先下载钉钉通讯工具:在手机 或者电脑上 安装
创建一个至少三人的群 然后在钉钉群聊里添加一个自定义的机器人
并复制webhook的内容
https://oapi.dingtalk.com/robot/send?access_token=37e23308d1b84eb4ac34566e03c4c4e74b7eedecbcc002exxxxxxxxxxxxxxx
创建脚本
可以直接克隆git
在zabbix服务端的alertscripts目录下新建一个python脚本,内容:
123456789101112131415161718192021222324252627282930#!/usr/bin/python# -*- coding: utf-8 -*-# Author: aiker@gdedu.ml# My blog http://m运维网.运维网.blog.com import requestsimport jsonimport sysimport os headers = {'Content-Type': 'application/json;'}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 手动调试脚本:123 python使用的是python2
python dingdingrobot.py test
|
|
|