{"id":177765,"date":"2020-05-02T08:04:25","date_gmt":"2020-05-02T00:04:25","guid":{"rendered":"https:\/\/gulass.cn\/?p=177765"},"modified":"2020-04-22T16:06:05","modified_gmt":"2020-04-22T08:06:05","slug":"zabbix-ding-w","status":"publish","type":"post","link":"https:\/\/gulass.cn\/zabbix-ding-w.html","title":{"rendered":"Zabbix \u914d\u7f6e\u9489\u9489\u544a\u8b66\u529f\u80fd"},"content":{"rendered":"
\u5bfc\u8bfb<\/td>\n | \u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4ecb\u7ecd\u4e86Zabbix \u914d\u7f6e\u9489\u9489\u544a\u8b66\u529f\u80fd\u7684\u5b9e\u73b0\u4ee3\u7801\uff0c\u672c\u6587\u901a\u8fc7\u5b9e\u4f8b\u4ee3\u7801\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u7684\u975e\u5e38\u8be6\u7ec6\uff0c\u5bf9\u5927\u5bb6\u7684\u5b66\u4e60\u6216\u5de5\u4f5c\u5177\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u501f\u9274\u4ef7\u503c,\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e0b<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n \u9700\u6c42<\/strong><\/div>\n Zabbix\u914d\u7f6e\u9489\u9489\u544a\u8b66\u548cPrometheus\u914d\u7f6e\u9489\u9489\u544a\u8b66\u7c7b\u4f3c\u3002\u53ea\u4e0d\u8fc7Zabbix\u901a\u8fc7\u9489\u9489\u544a\u8b66\u662f\u901a\u8fc7Python\u811a\u672c\u5b9e\u73b0\u3002\u800cPrometheus\u662f\u901a\u8fc7\u9489\u9489\u7684\u4e8c\u8fdb\u5236\u5305\u5b9e\u73b0\u3002 \u9489\u9489Webhook\u4ee3\u7801\u5b9e\u73b0<\/strong><\/div>\n vim \/usr\/local\/zabbix\/share\/zabbix\/alertscripts\/dingding.py<\/p>\n \r\n#!\/usr\/bin\/env python\r\n#coding:utf-8\r\n \r\nimport requests,json,sys,os,datetime\r\nwebhook=\"https:\/\/oapi.dingtalk.com\/robot\/send?access_token=6e5bcfee12bc6fa7f3c6bd16b7d6c333d86266cecadd3fe5e77a29cedae9f9\" #\u8bf4\u660e\uff1a\u8fd9\u91cc\u6539\u4e3a\u81ea\u5df1\u521b\u5efa\u7684\u673a\u5668\u4eba\u7684webhook\u7684\u503c\r\n \r\nuser=sys.argv[1]\r\ntext=sys.argv[3]\r\ndata={\r\n \"msgtype\": \"text\",\r\n \"text\": {\r\n \"content\": text\r\n },\r\n \"at\": {\r\n \"atMobiles\": [\r\n user\r\n ],\r\n \"isAtAll\": False\r\n }\r\n}\r\nheaders = {'Content-Type': 'application\/json'}\r\nx=requests.post(url=webhook,data=json.dumps(data),headers=headers)\r\nif os.path.exists(\"\/tmp\/dingding.log\"):\r\n f=open(\"\/tmp\/dingding.log\",\"a+\")\r\nelse:\r\n f=open(\"\/tmp\/dingding.log\",\"w+\")\r\nf.write(\"\\n\"+\"--\"*30)\r\nif x.json()[\"errcode\"] == 0:\r\n f.write(\"\\n\"+str(datetime.datetime.now())+\" \"+str(user)+\" \"+\"\u53d1\u9001\u6210\u529f\"+\"\\n\"+str(text))\r\n f.close()\r\nelse:\r\n f.write(\"\\n\"+str(datetime.datetime.now()) + \" \" + str(user) + \" \" + \"\u53d1\u9001\u5931\u8d25\" + \"\\n\" + str(text))\r\n f.close()\r\n<\/pre>\n |