{"id":389,"date":"2025-11-14T17:19:01","date_gmt":"2025-11-14T09:19:01","guid":{"rendered":"https:\/\/0x0.pub\/?p=389"},"modified":"2025-11-14T17:19:01","modified_gmt":"2025-11-14T09:19:01","slug":"zabbix-%e5%91%8a%e8%ad%a6%e6%8e%a8%e9%80%81%e9%a3%9e%e4%b9%a6%e8%84%9a%e6%9c%ac%e5%92%8c%e6%b6%88%e6%81%af%e6%a8%a1%e6%9d%bf","status":"publish","type":"post","link":"https:\/\/0x0.pub\/?p=389","title":{"rendered":"Zabbix \u544a\u8b66\u63a8\u9001\u98de\u4e66\u811a\u672c\u548c\u6d88\u606f\u6a21\u677f"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1.\u98de\u4e66\u544a\u8b66\u811a\u672c<\/h2>\n\n\n\n<p class=\"has-small-font-size\"><strong>\u5c06\u4ee5\u4e0bwebhook URL\uff08<\/strong>https:\/\/open.feishu.cn\/open-apis\/bot\/v2\/hook\/12345678<strong>\uff09\u548c\u7b7e\u540d\u6821\u9a8c\u7801\uff08<\/strong>access_token=&#8221;12345678&#8243;<strong>\uff09\u66ff\u6362\u4e3a\u81ea\u5df1\u7684\u98de\u4e66\u673a\u5668\u4eba<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted has-small-font-size\">\u5728\/usr\/lib\/zabbix\/alertscripts\u76ee\u5f55\u4e0b\u521b\u5efa\u4e24\u4e2a\u98de\u4e66\u811a\u672c\uff0c\nfeishu1.py\u4e3a\u544a\u8b66\u65f6\u89e6\u53d1 \u4ee5\u4e0b\u4ee3\u7801\u4e2d \"template\": \"red\" \nfeishu2.py\u4e3a\u6062\u590d\u65f6\u89e6\u53d1 \u4ee5\u4e0b\u4ee3\u7801\u4e2d \"template\": \"green\"\n<\/pre>\n\n\n\n<pre class=\"wp-block-code\" style=\"font-size:clamp(0.875rem, 0.875rem + ((1vw - 0.2rem) * 0.294), 1rem);\"><code>#!\/usr\/bin\/python3\n# -*- coding: utf-8 -*-\nimport requests\nimport json\nimport sys\nimport os\nimport datetime\nimport base64\nimport hashlib\nimport hmac\nfrom time import time\n\n\nclass FeiShuNotify:\n    def __init__(self, subject, message, access_token=None):\n        timestamp, sign = FeiShuNotify.encode(access_token)\n        self.content = {'timestamp': timestamp, 'sign': sign}\n        self.subject = subject\n        self.message = message\n        self.timestamp = timestamp\n        self.sign = sign\n\n    @staticmethod\n    def encode(access_token):\n        \"\"\"\n        \u98de\u4e66\u673a\u5668\u4ebawebhook\u7b7e\u540d\u9a8c\u8bc1\u52a0\u5bc6\u65b9\u6cd5\n        :return:\n        \"\"\"\n        # timestamp = str(round(time() * 1000))\n        timestamp = str(int(time()))\n        # \u62fc\u63a5timestamp\u548csecret\n        string_to_sign = '{}\\n{}'.format(timestamp, access_token)\n        hmac_code = hmac.new(string_to_sign.encode(\"utf-8\"), digestmod=hashlib.sha256).digest()\n        # \u5bf9\u7ed3\u679c\u8fdb\u884cbase64\u5904\u7406\n        sign = base64.b64encode(hmac_code).decode('utf-8')\n        return timestamp, sign\n\n    def to_json(self):\n        \"\"\"\n        \u98de\u4e66\u6d88\u606f\u5361\u7247\u8fd4\u56de\u683c\u5f0f\n        :return:\n        \"\"\"\n        return {\n            \"msg_type\": \"interactive\",\n            \"card\": {\n                \"config\": {\n                    \"wide_screen_mode\": True\n                },\n                \"header\": {\n                    \"title\": {\n                        \"tag\": \"plain_text\",\n                        \"content\": self.subject\n                    },\n                    \"template\": \"red\"\n                },\n                \"elements\": &#091;\n                    {\n                        \"tag\": \"markdown\",\n                        \"content\": self.message,\n                    }\n                ]\n            },\n            'timestamp': self.timestamp,\n            'sign': self.sign\n        }\n\n\ndef send_message(message, subject):\n    \"\"\"\n    \u5411\u98de\u4e66webhook url\u53d1\u9001\u544a\u8b66\u6d88\u606f\n    :param message:\n    :param subject:\n    :return:\n    \"\"\"\n    payload_message = FeiShuNotify(subject, message, access_token=\"12345678\").to_json()\n    headers = {\n        'Content-Type': 'application\/json'\n    }\n\n    response = requests.request(\"POST\",\n                            \"https:\/\/open.feishu.cn\/open-apis\/bot\/v2\/hook\/12345678\",\n                                headers=headers, data=json.dumps(payload_message))\n    return response\n\n\nif __name__ == '__main__':\n    text = sys.argv&#091;3]\n    subject = sys.argv&#091;2]\n    send_message(text, subject)<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">2.Zabbix\u914d\u7f6e\u544a\u8b66<\/h2>\n\n\n\n<p>1. \u6dfb\u52a0\u544a\u8b66\u5a92\u4ecb<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">\u7c7b\u578b\u4e3a\u811a\u672c\uff0c\u811a\u672c\u540d\u79f0\u4e3a\u4e0a\u9762\u521b\u5efa\u7684feishu1.py\uff0c\u811a\u672c\u53c2\u6570\u5982\u4e0b\u3002<br>\u518d\u521b\u5efa\u7b2c2\u4e2a\u5a92\u4ecb\uff0c\u540d\u79f0\u4e3a\u98de\u4e66\u673a\u5668\u4eba\u6062\u590d\uff0c\u811a\u672c\u540d\u79f0\u4e3afeishu2.py\u3002<\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"712\" height=\"544\" src=\"https:\/\/0x0.pub\/wp-content\/uploads\/2025\/11\/image-1.png\" alt=\"\" class=\"wp-image-395\" srcset=\"https:\/\/0x0.pub\/wp-content\/uploads\/2025\/11\/image-1.png 712w, https:\/\/0x0.pub\/wp-content\/uploads\/2025\/11\/image-1-300x229.png 300w\" sizes=\"auto, (max-width: 712px) 100vw, 712px\" \/><\/figure>\n\n\n\n<p>2. \u7ba1\u7406\u5458\u7528\u6237\u7ed1\u5b9a\u65b0\u589e\u76842\u4e2a\u544a\u8b66\u5a92\u4ecb\u5e76\u542f\u7528<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"811\" height=\"241\" src=\"https:\/\/0x0.pub\/wp-content\/uploads\/2025\/11\/image-2.png\" alt=\"\" class=\"wp-image-396\" srcset=\"https:\/\/0x0.pub\/wp-content\/uploads\/2025\/11\/image-2.png 811w, https:\/\/0x0.pub\/wp-content\/uploads\/2025\/11\/image-2-300x89.png 300w, https:\/\/0x0.pub\/wp-content\/uploads\/2025\/11\/image-2-768x228.png 768w\" sizes=\"auto, (max-width: 811px) 100vw, 811px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">3.\u63a8\u9001\u6d88\u606f\u6a21\u677f<\/h2>\n\n\n\n<p>1. zabbix \u544a\u8b66-\u52a8\u4f5c-\u89e6\u53d1\u5668\u52a8\u4f5c\uff0c\u521b\u5efa\u65b0\u52a8\u4f5c\uff0c\u8bbe\u7f6e\u52a8\u4f5c\u89e6\u53d1\u6761\u4ef6\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1037\" height=\"321\" src=\"https:\/\/0x0.pub\/wp-content\/uploads\/2025\/11\/image-3.png\" alt=\"\" class=\"wp-image-397\" srcset=\"https:\/\/0x0.pub\/wp-content\/uploads\/2025\/11\/image-3.png 1037w, https:\/\/0x0.pub\/wp-content\/uploads\/2025\/11\/image-3-300x93.png 300w, https:\/\/0x0.pub\/wp-content\/uploads\/2025\/11\/image-3-768x238.png 768w\" sizes=\"auto, (max-width: 1037px) 100vw, 1037px\" \/><\/figure>\n\n\n\n<p>2. \u914d\u7f6e\u64cd\u4f5c\u548c\u6062\u590d\u64cd\u4f5c\uff0c\u53d1\u9001\u6d88\u606f\u7ed9Admin \u901a\u8fc7\u5a92\u4ecb\u544a\u8b66\u548c\u6062\u590d2\u4e2a\u811a\u672c\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1039\" height=\"538\" src=\"https:\/\/0x0.pub\/wp-content\/uploads\/2025\/11\/image-4.png\" alt=\"\" class=\"wp-image-398\" srcset=\"https:\/\/0x0.pub\/wp-content\/uploads\/2025\/11\/image-4.png 1039w, https:\/\/0x0.pub\/wp-content\/uploads\/2025\/11\/image-4-300x155.png 300w, https:\/\/0x0.pub\/wp-content\/uploads\/2025\/11\/image-4-768x398.png 768w\" sizes=\"auto, (max-width: 1039px) 100vw, 1039px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"605\" height=\"713\" src=\"https:\/\/0x0.pub\/wp-content\/uploads\/2025\/11\/image-5.png\" alt=\"\" class=\"wp-image-399\" style=\"width:620px;height:auto\" srcset=\"https:\/\/0x0.pub\/wp-content\/uploads\/2025\/11\/image-5.png 605w, https:\/\/0x0.pub\/wp-content\/uploads\/2025\/11\/image-5-255x300.png 255w\" sizes=\"auto, (max-width: 605px) 100vw, 605px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"577\" height=\"593\" src=\"https:\/\/0x0.pub\/wp-content\/uploads\/2025\/11\/image-6.png\" alt=\"\" class=\"wp-image-400\" srcset=\"https:\/\/0x0.pub\/wp-content\/uploads\/2025\/11\/image-6.png 577w, https:\/\/0x0.pub\/wp-content\/uploads\/2025\/11\/image-6-292x300.png 292w\" sizes=\"auto, (max-width: 577px) 100vw, 577px\" \/><\/figure>\n\n\n\n<p>3. \u6d88\u606f\u6a21\u677f\u4e2d\u7684<strong><mark style=\"background-color:#454545;color:#0693e3\" class=\"has-inline-color\">\u8bbe\u5907\u8fd0\u884c\u65f6\u95f4<\/mark><\/strong>\u9700\u8981\u5728\u6570\u636e\u91c7\u96c6-\u6a21\u677f\u4e2d\u542f\u7528\u7684\u89e6\u53d1\u5668\u8868\u8fbe\u5f0f\u6700\u524d\u9762\u52a0\u4e00\u4e2auptime\u7684\u8868\u8fbe\u5f0f\uff0c\u4ee5\u4fbf\u5728\u6d88\u606f\u6a21\u677f\u4e2d\u4f7f\u7528{ITEM.VALUE1}\u83b7\u53d6\u5230\u544a\u8b66\u4e3b\u673a\u7684\u8fd0\u884c\u65f6\u95f4\uff0c\u76f8\u5e94\u7684<strong><mark style=\"background-color:#454545;color:#0693e3\" class=\"has-inline-color\">\u5f53\u524d\u72b6\u6001<\/mark><\/strong>\u503c\u5c31\u9700\u8981\u4f7f\u7528{ITEM.VALUE2}\uff0c\u81ea\u52a8\u53d1\u73b0\u89c4\u5219\u4e2d\u542f\u7528\u7684\u89e6\u53d1\u5668\u4e5f\u9700\u8981\u6dfb\u52a0\u6b64\u8868\u8fbe\u5f0f\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"642\" height=\"338\" src=\"https:\/\/0x0.pub\/wp-content\/uploads\/2025\/11\/image-8.png\" alt=\"\" class=\"wp-image-402\" srcset=\"https:\/\/0x0.pub\/wp-content\/uploads\/2025\/11\/image-8.png 642w, https:\/\/0x0.pub\/wp-content\/uploads\/2025\/11\/image-8-300x158.png 300w\" sizes=\"auto, (max-width: 642px) 100vw, 642px\" \/><\/figure>\n\n\n\n<p>4. \u98de\u4e66\u63a8\u9001\u6d88\u606f\u6548\u679c\u5c55\u793a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"389\" height=\"731\" src=\"https:\/\/0x0.pub\/wp-content\/uploads\/2025\/11\/image.png\" alt=\"\" class=\"wp-image-407\" style=\"width:620px;height:auto\" srcset=\"https:\/\/0x0.pub\/wp-content\/uploads\/2025\/11\/image.png 389w, https:\/\/0x0.pub\/wp-content\/uploads\/2025\/11\/image-160x300.png 160w\" sizes=\"auto, (max-width: 389px) 100vw, 389px\" \/><\/figure>\n\n\n\n<p>5. \u6d88\u606f\u6a21\u677f\u5185\u5bb9<\/p>\n\n\n\n<pre class=\"wp-block-code has-small-font-size\"><code>\u4e3b\u9898  zabbix\u544a\u8b66\u901a\u77e5\n\n\u544a\u8b66\u65f6\u95f4\uff1a**&lt;font color='red'&gt;{EVENT.DATE}  {EVENT.TIME}&lt;\/font&gt;**\n\u5f53\u524d\u65f6\u95f4\uff1a**&lt;font color='grey'&gt;{DATE}  {TIME}&lt;\/font&gt;**\n\u544a\u8b66\u7ea7\u522b\uff1a**&lt;font color='grey'&gt;{TRIGGER.SEVERITY}&lt;\/font&gt;**\n\u4e3b\u673a\u540d\u79f0\uff1a**&lt;font color='red'&gt;{HOST.NAME}&lt;\/font&gt;**\n\u4e3b  \u673a IP\uff1a**&lt;font color='grey'&gt;{HOST.IP}&lt;\/font&gt;**\n\u4e3b\u673a\u5206\u7ec4\uff1a**&lt;font color='red'&gt;{TRIGGER.HOSTGROUP.NAME}&lt;\/font&gt;**\n\u95ee\u9898\u540d\u79f0\uff1a**&lt;font color='red'&gt;{EVENT.NAME}&lt;\/font&gt;**\n\u63cf\u8ff0\u4fe1\u606f\uff1a**&lt;font color='grey'&gt;{TRIGGER.DESCRIPTION}&lt;\/font&gt;**\n\u5f53\u524d\u72b6\u6001\uff1a**&lt;font color='red'&gt;{TRIGGER.STATUS}:{ITEM.VALUE2} &lt;\/font&gt;**\n\u4e8b  \u4ef6 ID\uff1a**&lt;font color='grey'&gt;{EVENT.ID}&lt;\/font&gt;**\n&#091;\u786e\u8ba4\u544a\u8b66\u548c\u67e5\u770b\u8be6\u60c5](http:\/\/10.32.129.85\/)\n\n\n\n\u4e3b\u9898  zabbix\u6062\u590d\u901a\u77e5\n\n\u544a\u8b66\u65f6\u95f4\uff1a**&lt;font color='green'&gt;{EVENT.DATE}  {EVENT.TIME}&lt;\/font&gt;**\n\u5f53\u524d\u65f6\u95f4\uff1a**&lt;font color='grey'&gt;{DATE}  {TIME}&lt;\/font&gt;**\n\u544a\u8b66\u7ea7\u522b\uff1a**&lt;font color='grey'&gt;{TRIGGER.SEVERITY}&lt;\/font&gt;**\n\u4e3b\u673a\u540d\u79f0\uff1a**&lt;font color='green'&gt;{HOST.NAME}&lt;\/font&gt;**\n\u4e3b  \u673a IP\uff1a**&lt;font color='grey'&gt;{HOST.IP}&lt;\/font&gt;**\n\u4e3b\u673a\u5206\u7ec4\uff1a**&lt;font color='green'&gt;{TRIGGER.HOSTGROUP.NAME}&lt;\/font&gt;**\n\u95ee\u9898\u540d\u79f0\uff1a**&lt;font color='green'&gt;{EVENT.NAME}&lt;\/font&gt;**\n\u63cf\u8ff0\u4fe1\u606f\uff1a**&lt;font color='grey'&gt;{TRIGGER.DESCRIPTION}&lt;\/font&gt;**\n\u5f53\u524d\u72b6\u6001\uff1a**&lt;font color='green'&gt;{TRIGGER.STATUS}:{ITEM.VALUE2}&lt;\/font&gt;**\n\u6545\u969c\u65f6\u957f\uff1a**&lt;font color='grey'&gt;{EVENT.AGE}&lt;\/font&gt;**\n\u4e8b  \u4ef6 ID\uff1a**&lt;font color='grey'&gt;{EVENT.ID}&lt;\/font&gt;**\n\u8bbe\u5907\u8fd0\u884c\u65f6\u95f4\uff1a**&lt;font color='green'&gt;{ITEM.VALUE1}&lt;\/font&gt;**\n&#091;\u786e\u8ba4\u544a\u8b66\u548c\u67e5\u770b\u8be6\u60c5](http:\/\/10.32.129.85\/)<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">4.\u53c2\u8003\u94fe\u63a5<\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">\u811a\u672c\u4ee3\u7801\u53c2\u8003\uff1a<a href=\"https:\/\/www.zhihu.com\/tardis\/zm\/art\/701508832?source_id=1003\">\u7f51\u7edc\u5de5\u7a0b\u5e08\u7684zabbix\u4e4b\u65c5(\u5b9e\u6218) -- zabbix\u5bf9\u63a5\u98de\u4e66<\/a><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1.\u98de\u4e66\u544a\u8b66\u811a\u672c \u5c06\u4ee5\u4e0bwebhook URL\uff08https:\/\/open.feishu.cn\/open-api [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[60,62,61],"class_list":{"0":"post-389","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-note","7":"tag-zabbix","9":"tag-61"},"_links":{"self":[{"href":"https:\/\/0x0.pub\/index.php?rest_route=\/wp\/v2\/posts\/389","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/0x0.pub\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/0x0.pub\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/0x0.pub\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/0x0.pub\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=389"}],"version-history":[{"count":8,"href":"https:\/\/0x0.pub\/index.php?rest_route=\/wp\/v2\/posts\/389\/revisions"}],"predecessor-version":[{"id":408,"href":"https:\/\/0x0.pub\/index.php?rest_route=\/wp\/v2\/posts\/389\/revisions\/408"}],"wp:attachment":[{"href":"https:\/\/0x0.pub\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=389"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/0x0.pub\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=389"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/0x0.pub\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=389"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}