{"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":"\n\n\n
\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
\n\u6211\u4eec\u73b0\u5728\u4e3b\u8981\u6765\u8bb2\u89e3Zabbix\u7684\u8bbe\u7f6e\u5b9e\u73b0<\/p>\n

\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

\u6267\u884c\u4e00\u4e0b\uff1a<\/p>\n

\r\nchmod +x dingding.py # \u52a0\u6267\u884c\u6743\u9650\r\npython dingding.py a b \"\u6d4b\u8bd5\"\r\n<\/pre>\n

\u6211\u4eec\u770b\u9489\u9489\u80fd\u4e0d\u80fd\u6536\u5230\u544a\u8b66\uff08\u8bb0\u5f97\u9489\u9489\u8981\u52a0\u670d\u52a1\u5668\u7684\u516c\u7f51ip\u7684\u767d\u540d\u5355\uff09
\n\"\"
\nZabbix\u7684\u914d\u7f6e\u5982\u4e0b\uff1a
\n\uff081\uff09\u914d\u7f6e\u62a5\u8b66\u5a92\u4ecb\u7c7b\u578b\uff1a
\n\u914d\u7f6e---> \u62a5\u8b66\u5a92\u4ecb\u7c7b\u578b\uff0c\u811a\u672c\u53c2\u6570\u5982\u4e0b\uff1a<\/p>\n

\r\n{ALERT.SENDTO}\r\n{ALERT.SUBJECT}\r\n{ALERT.MESSAGE}\r\n<\/pre>\n

\u622a\u56fe\u5982\u4e0b:
\n\"\"
\n\uff082\uff09\u914d\u7f6e\u52a8\u4f5c
\n \u914d\u7f6e--->\u52a8\u4f5c--->\u521b\u5efa\u52a8\u4f5c,\u628a\u5fae\u4fe1\u544a\u8b66\u6216\u8005\u90ae\u4ef6\u544a\u8b66\u7684\u201c\u64cd\u4f5c\u201d\u548c\u6062\u590d\u64cd\u4f5c\u5185\u5bb9\u62f7\u8d1d\u8fc7\u6765\u5373\u53ef\u3002
\n\"\"
\n\uff083\uff09\u6700\u540e\u914d\u7f6e\u7528\u6237
\n\u914d\u7f6e--->\u7528\u6237---> \u62a5\u8b66\u5a92\u4ecb\uff0c\u628a\u9489\u9489\u52a0\u8fdb\u6765\u5373\u53ef\u3002 \u5176\u4e2d\u6536\u4ef6\u4eba\u8981\u5199\u81ea\u5df1\u7684\u7535\u8bdd\u53f7\u7801\u3002
\n\"\"
\nZabbix\u7684\u914d\u7f6e\u5c31\u914d\u7f6e\u5b8c\u4e86\u3002\u6211\u4eec\u770b\u4e00\u4e0b\u544a\u8b66\u7684\u6548\u679c\u56fe
\n\"\"<\/p>\n

\u603b\u7ed3
\n<\/strong><\/div>\n

\u5230\u6b64\u8fd9\u7bc7\u5173\u4e8eZabbix \u914d\u7f6e\u9489\u9489\u544a\u8b66\u7684\u6587\u7ae0\u5c31\u4ecb\u7ecd\u5230\u8fd9\u4e86<\/p>\n","protected":false},"excerpt":{"rendered":"

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\u8fc7Pytho […]<\/p>\n","protected":false},"author":1893,"featured_media":177776,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-177765","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/177765","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/users\/1893"}],"replies":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/comments?post=177765"}],"version-history":[{"count":1,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/177765\/revisions"}],"predecessor-version":[{"id":177777,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/177765\/revisions\/177777"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media\/177776"}],"wp:attachment":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media?parent=177765"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/categories?post=177765"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/tags?post=177765"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}