{"id":595,"date":"2020-11-18T15:05:18","date_gmt":"2020-11-18T07:05:18","guid":{"rendered":"https:\/\/www.furyblog.com\/?p=595"},"modified":"2020-11-18T15:05:19","modified_gmt":"2020-11-18T07:05:19","slug":"zabbix%e9%80%9a%e8%bf%87%e9%92%89%e9%92%89webhook%e6%8e%a8%e9%80%81%e5%91%8a%e8%ad%a6%ef%bc%88markdown%ef%bc%89","status":"publish","type":"post","link":"https:\/\/www.furyblog.com\/?p=595","title":{"rendered":"[Zabbix]\u901a\u8fc7\u9489\u9489webhook\u63a8\u9001\u544a\u8b66\uff08Markdown\uff09"},"content":{"rendered":"\n<p>\u4f20\u7edf\u7684\u9489\u9489\u7fa4\u673a\u5668\u4eba\u544a\u8b66\u4e3atext\u683c\u5f0f\uff0c\u6700\u8fd1\u7814\u7a76\u4e86\u4e0b\u4f7f\u7528markdown\u6765\u4f20\uff0c\u611f\u89c9\u6bd4text\u770b\u8d77\u6765\u66f4\u9002\u8bfb\u3002<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"458\" height=\"297\" src=\"https:\/\/www.furyblog.com\/wp-content\/uploads\/2020\/11\/5FCECD2D-C6AB-4985-8395-2DAD4127E808.png\" alt=\"\" class=\"wp-image-596\" srcset=\"https:\/\/www.furyblog.com\/wp-content\/uploads\/2020\/11\/5FCECD2D-C6AB-4985-8395-2DAD4127E808.png 458w, https:\/\/www.furyblog.com\/wp-content\/uploads\/2020\/11\/5FCECD2D-C6AB-4985-8395-2DAD4127E808-300x195.png 300w\" sizes=\"(max-width: 458px) 100vw, 458px\" \/><\/figure><\/div>\n\n\n\n<p>\u5e9f\u8bdd\u4e0d\u591a\u8bf4\uff0c\u76f4\u63a5\u5f00\u6de6\u3002<\/p>\n\n\n\n<p>\u590d\u5236\u7fa4\u673a\u5668\u4ebawebhook\u5730\u5740\uff1a<\/p>\n\n\n\n<p><code>https:\/\/oapi.dingtalk.com\/robot\/sendaccess_token=xxxxxxxxxxxxxxxxece8053e86414ee67c015e63b315304eee79<\/code><\/p>\n\n\n\n<p>Zabbix\u7aef\u9700\u5b89\u88c5Python3\u73af\u5883\uff0cZabbix\u8c03\u7528\u7684\u811a\u672c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/usr\/bin\/python3\r\nimport requests, json, sys, os, datetime\r\n\r\n#webhook = \"https:\/\/oapi.dingtalk.com\/robot\/send?access_token=xxxxxxxxxxxxxxxxxx634ece8053e86414ee67c015e63b315304eee79\"  # \u963f\u91cc\u6d4b\u8bd5\r\nwebhook = \"https:\/\/oapi.dingtalk.com\/robot\/send?access_token=xxxxxxxxxxxxxxxxxxxxxx0f64da8aaac4bb95885e277f1c48aafb462d17a60\"  # \u6b63\u5f0f\u7fa4\n\r\n#user = sys.argv&#91;1] #\u7528\u6237\r\nsubject = sys.argv&#91;1] #\u6807\u9898\r\ntext = sys.argv&#91;2] #\u6d88\u606f\r\ndata = {\r\n    \"msgtype\": \"markdown\",\r\n    \"markdown\": {\r\n        \"title\": subject,\r\n        \"text\":text\r\n    },\r\n    \"at\": {\r\n        \"atMobiles\": &#91;\r\n            \"138XXXX7526\"\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\n\r\n<\/code><\/pre>\n\n\n\n<p>\u5176\u4e2dsubject\u5bf9\u5e94\u7684\u662f\u62a5\u8b66\u5a92\u4ecb\u4e2dMessage type\u7684\u4e3b\u9898\uff0c\u5728\u9489\u9489\u4e2d\u663e\u793a\u4e3a\u6807\u9898\uff0c\u4e0d\u51fa\u73b0\u5728\u6b63\u6587\uff0c\u53ea\u5728\u6d88\u606f\u5217\u8868\u4e2d\u51fa\u73b0\uff0ctext\u5bf9\u5e94\u7684\u5c31\u662f\u6b63\u6587\u3002<\/p>\n\n\n\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u914d\u7f6eZabbix\u7684\u544a\u8b66\u914d\u7f6e<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u521b\u5efa\u65b0\u7684\u544a\u8b66\u5a92\u4ecb\uff1a\u5a92\u4ecb\u7c7b\u578b\u9009\u62e9\u811a\u672c\uff0c\u63d0\u524d\u5c06\u4e0a\u65b9\u7684\u811a\u672c\u653e\u7f6e\u4e8e<code>\/usr\/local\/share\/zabbix\/alertscripts<\/code>\u4e2d\u5e76\u5728\u811a\u672c\u540d\u79f0\u5904\u586b\u5199\u4f60\u547d\u540d\u7684\u6587\u4ef6\u540d\uff0c\u8fd9\u91cc\u8981\u6ce8\u610f\u4e00\u4e0b\u5982\u679c\u4f60\u5728Windows \u4e0b\u7f16\u8f91\uff0c\u5fc5\u987b\u5c06\u884c\u5c3e\u5e8f\u5217\u6539\u4e3aLF\uff0c\u5426\u5219Python\u6267\u884c\u4f1a\u62a5\u9519\u3002<\/li><li>\u6dfb\u52a0\u544a\u8b66\u53c2\u6570\uff1a\u6211\u8fd9\u91cc\u53ea\u7528\u5230\u4e862\u4e2a\u53c2\u6570\uff0c\u4e00\u4e2a\u662f<code>{ALERT.SUBJECT}<\/code>\u544a\u8b66\u6807\u9898\uff0c\u4e00\u4e2a\u662f<code>{ALERT.MESSAGE}<\/code>\u544a\u8b66\u6b63\u6587\uff0c\u6309\u7167\u586b\u5199\u5373\u53ef\u3002<\/li><li>\u589e\u52a0Message type\uff1a\u4e00\u822c\u589e\u52a03\u4e2a\u5c31\u8db3\u591f\u4e86\uff0c\u53d1\u73b0\u95ee\u9898\u3001\u95ee\u9898\u6062\u590d\u3001\u95ee\u9898\u66f4\u65b0\uff0c\u8be6\u7ec6\u7684\u8bbe\u7f6e\u5728\u4e0b\u65b9\u8bf4\u660e\u3002<\/li><li>\u68c0\u67e5\u5176\u4ed6\u5f71\u54cd\u544a\u8b66\u7684\u8bbe\u7f6e\uff1a1\uff0c\u52a8\u4f5c\uff1a\u8bb0\u5f97\u5f00\u542f\u52a8\u4f5c\uff0c\u4e0d\u7136Zabbix\u544a\u8b66\u6d4b\u8bd5\u53ef\u4ee5\uff0c\u4f46\u662f\u6ca1\u529e\u6cd5\u63a8\u9001\u30022\uff0c\u7528\u6237\u5f00\u542f\u544a\u8b66\uff1a\u5728\u7528\u6237\u914d\u7f6e\u4e2d\uff0c\u5173\u8054\u76f8\u5e94\u7684Message type\uff0c\u505a\u4e00\u4e0b\u7b80\u5355\u7684\u914d\u7f6e\u3002<\/li><\/ul>\n\n\n\n<p>\u91cd\u70b9\uff1a\u5173\u4e8eZabbix\u63a8\u9001\u9489\u9489\u673a\u5668\u4ebawebhook\u5728\u7f51\u4e0a\u5df2\u7ecf\u6709\u5f88\u591a\u6559\u7a0b\uff0c\u4e0a\u65b9\u53ea\u662f\u7565\u8fc7\uff0c\u4e0b\u9762\u624d\u662f\u91cd\u70b9\u3002\u4ee5\u4e0b\u914d\u7f6e\u90fd\u662f\u4e2a\u4eba\u4e60\u60ef\uff0c\u53ef\u6839\u636e\u5b9e\u9645\u60c5\u51b5\u8c03\u6574\u3002<\/p>\n\n\n\n<p>\u5728Message type\u4e2d\uff0c\u6bd4\u5982\u6211\u6dfb\u52a0\u4e00\u4e2a\u53d1\u73b0\u544a\u8b66\u7684\u4fe1\u606f\uff0c\u9ed8\u8ba4\u914d\u7f6e\u5982\u4e0b\uff1a<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"679\" height=\"413\" src=\"https:\/\/www.furyblog.com\/wp-content\/uploads\/2020\/11\/image.png\" alt=\"\" class=\"wp-image-603\" srcset=\"https:\/\/www.furyblog.com\/wp-content\/uploads\/2020\/11\/image.png 679w, https:\/\/www.furyblog.com\/wp-content\/uploads\/2020\/11\/image-300x182.png 300w\" sizes=\"(max-width: 679px) 100vw, 679px\" \/><\/figure><\/div>\n\n\n\n<p>\u8981\u5b9e\u73b0\u4ee5\u4e0a\u7684\u529f\u80fd\uff0c\u5148\u5c06\u4e3b\u9898\u6539\u4e3a\u81ea\u5df1\u60f3\u8981\u663e\u793a\u7684\u6807\u9898\uff0c\u5982\u201cZabbix-\u53d1\u73b0\u6545\u969c\u201d\uff0c\u8fd9\u6837\uff0c\u5728\u624b\u673a\u63d0\u793a\u53ca\u7535\u8111\u9489\u9489\u4e0a\u7684\u6d88\u606f\u5217\u8868\u4e2d\u90fd\u4f1a\u663e\u793a\u8fd9\u4e2a\u3002<\/p>\n\n\n\n<p>\u6211\u518d\u5c06\u539f\u6765\u7684\u6807\u9898\u5185\u5bb9<code>Problem: {EVENT.NAME}<\/code>\u590d\u5236\u5230\u6d88\u606f\u4e2d\uff0c\u4f7f\u7528###\u5c06\u5176\u4f5c\u4e3a3\u7ea7\u6807\u9898\uff0c\u6b63\u6587\u4f7f\u7528>\u7b26\u53f7\u8bbe\u4e3a\u5f15\u7528\u6587\u672c\uff0c\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u4f7f\u7528>\u4e4b\u540e\u7684\u6587\u672c\u5c06\u4f1a\u6362\u884c\uff0c\u5982\u679c\u5f15\u7528\u7684\u6587\u672c\u9700\u8981\u6362\u884c\uff0c\u5728\u7ed3\u5c3e\u5904\u589e\u52a02\u4e2a\u7a7a\u683c\u5373\u53ef\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>### Problem: {EVENT.NAME}\r\n > Problem started at {EVENT.TIME} on {EVENT.DATE}    \r\nProblem name: {EVENT.NAME}    \r\nHost: {HOST.NAME}    \r\nSeverity: {EVENT.SEVERITY}    \r\nOperational data: {EVENT.OPDATA}    \r\nOriginal problem ID: {EVENT.ID}    \r\n{TRIGGER.URL}<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f20\u7edf\u7684\u9489\u9489\u7fa4\u673a\u5668\u4eba\u544a\u8b66\u4e3atext\u683c\u5f0f\uff0c\u6700\u8fd1\u7814\u7a76\u4e86\u4e0b\u4f7f\u7528markdown\u6765\u4f20\uff0c\u611f\u89c9\u6bd4text\u770b\u8d77\u6765\u66f4\u9002\u8bfb\u3002 \u5e9f\u8bdd\u4e0d\u591a\u8bf4\uff0c\u76f4\u63a5\u5f00\u6de6\u3002 \u590d\u5236\u7fa4\u673a\u5668\u4ebawebhook\u5730\u5740\uff1a https:\/\/oapi.dingtalk.com\/robot\/sendac&#8230;<\/p>\n","protected":false},"author":1,"featured_media":597,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32,33],"tags":[],"topic":[],"class_list":["post-595","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-network-2","category-network-example"],"_links":{"self":[{"href":"https:\/\/www.furyblog.com\/index.php?rest_route=\/wp\/v2\/posts\/595","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.furyblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.furyblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.furyblog.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.furyblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=595"}],"version-history":[{"count":7,"href":"https:\/\/www.furyblog.com\/index.php?rest_route=\/wp\/v2\/posts\/595\/revisions"}],"predecessor-version":[{"id":605,"href":"https:\/\/www.furyblog.com\/index.php?rest_route=\/wp\/v2\/posts\/595\/revisions\/605"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.furyblog.com\/index.php?rest_route=\/wp\/v2\/media\/597"}],"wp:attachment":[{"href":"https:\/\/www.furyblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=595"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.furyblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=595"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.furyblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=595"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.furyblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftopic&post=595"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}