{"id":492,"date":"2019-06-18T12:19:28","date_gmt":"2019-06-18T04:19:28","guid":{"rendered":"http:\/\/www.laihp.top\/wordpress\/?p=492"},"modified":"2023-02-10T16:42:46","modified_gmt":"2023-02-10T08:42:46","slug":"zabbix%e5%ae%89%e8%a3%85%e9%85%8d%e7%bd%ae%e4%b8%8e%e9%92%89%e9%92%89%e6%8a%a5%e8%ad%a6","status":"publish","type":"post","link":"https:\/\/www.laihp.top\/zqb\/?p=492","title":{"rendered":"zabbix\u5b89\u88c5\u914d\u7f6e\u4e0e\u9489\u9489\u62a5\u8b66\u53ca\u5199\u5165log\u65e5\u5fd7web\u5c55\u793a"},"content":{"rendered":"<h2>\u5b89\u88c5\u6bd4\u8f83\u7b80\u5355\uff0c\u5b98\u7f51\u5b89\u88c5\u5373\u53ef\uff1a<\/h2>\n<p><a href=\"https:\/\/www.zabbix.com\/documentation\/4.0\/zh\/manual\/installation\/install_from_packages\/debian_ubuntu\">https:\/\/www.zabbix.com\/documentation\/4.0\/zh\/manual\/installation\/install_from_packages\/debian_ubuntu<\/a><\/p>\n<h2>\u9489\u9489\u62a5\u8b66\uff1a<\/h2>\n<pre><code class=\"hljs python\">cd \/usr\/lib\/zabbix\/alertscripts\r\n<\/code><\/pre>\n<p>\u521b\u5efarobot.py\u6587\u4ef6<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#!\/usr\/bin\/python3.6\r\n# -*- coding: utf-8 -*-\r\n\r\nimport requests\r\nimport json\r\nimport sys\r\nimport os\r\n\r\nheaders = {'Content-Type': 'application\/json;charset=utf-8'}\r\napi_url = \"https:\/\/oapi.dingtalk.com\/robot\/send?access_token=******\" \r\n#\u4e0a\u9762\u673a\u5668\u4eba\u91cc\u9762\u590d\u5236\u5185\u5bb9\r\n\r\n\r\ndef msg(text):\r\n    json_text= {\r\n        \"msgtype\": \"text\",\r\n        \"at\": {\r\n            \"atMobiles\": [\r\n                    \"1821011****\"\r\n            ],\r\n            \"isAtAll\": False\r\n        },\r\n        \"text\": {\r\n            \"content\": text\r\n        }\r\n    }\r\n    r=requests.post(api_url,json.dumps(json_text),headers=headers).content\r\n    print(r)\r\n\r\n#msg(12345)\r\n\r\n\r\nif __name__ == '__main__':\r\n    #text = sys.argv[1]+sys.argv[2]+sys.argv[3]+sys.argv[4]\r\n    text0=sys.argv[1:]  #sys.argv[]\u83b7\u53d6\u5916\u90e8\u53c2\u6570\uff0c\u8fd4\u56de\u4e3a\u4e00\u4e2a\u5217\u8868list\u7ec4\u30020\u4e3a\u76ee\u5f55\r\n    text=' '.join(text0)\r\n    msg(text)<\/pre>\n<p>\u518d\u5728\u672c\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2arobot.sh\u6587\u4ef6\uff0c\u8fd4\u56de\u683c\u5f0f\u4fee\u6539\u540e\u7684\u62a5\u8b66\u4fe1\u606f\uff0czabbix\u8c03\u7528\u6b64\u6587\u4ef6<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#!\/bin\/bash\r\n  \r\nstri=$1$2$3$4$5$6$7\r\nstri1=${stri} | sed 's\/ \/\/g'\r\nstri2=${stri1} | sed 's\/(\/\/g'\r\nstri3=${stri2} | sed 's\/&gt;\/\/g'\r\npython3.6 \/usr\/lib\/zabbix\/alertscripts\/robot.py $stri<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">5.0\u7248\u672c\u540e\u7684zabbix\uff0c\u76f4\u63a5\u8c03\u7528py\u811a\u672c\u3002\r\n\r\n[root@mzl ~]# cat \/usr\/lib\/zabbix\/alertscripts\/zq1.py \r\n#!\/usr\/bin\/python\r\n# -*- coding: utf-8 -*-\r\n\r\nimport requests\r\nimport json\r\nimport sys\r\n\r\nurl = 'https:\/\/oapi.dingtalk.com\/robot\/send?access_token=************'\r\n\r\ntext0=sys.argv[1:]  #sys.argv[]\u83b7\u53d6\u5916\u90e8\u53c2\u6570\uff0c\u8fd4\u56de\u4e3a\u4e00\u4e2a\u5217\u8868list\u7ec4\u30020\u4e3a\u76ee\u5f55\r\ntext1=' '.join(text0)\r\ntext2=sys.argv[1]\r\n\r\n\r\nheaders = {\r\n\r\n    \"Content-Type\": \"application\/json\",\r\n    \"Chartset\": \"utf-8\"\r\n}\r\n\r\n# \u8981\u53d1\u9001\u7684\u6587\u672c\u662fjson\u683c\u5f0f\r\nrequest_data = {\r\n    \"msgtype\": \"markdown\",\r\n    \"markdown\": {\"title\": \"{}\".format(text2),\r\n                 \"text\": \"{}\".format(text1) \r\n                 },\r\n    \"at\": {\r\n        \"atMobiles\": [],\r\n        \"isAtAll\": True\r\n    }\r\n\r\n}\r\n\r\n# \u628ajson\u8f6c\u53d8\u4e3a\u5b57\u7b26\u4e32\u683c\u5f0f\u6570\u636e\r\nsend_data = json.dumps(request_data)\r\n# \u8fd9\u4e2a\u662f\u53d1\u9001post\u8bf7\u6c42\uff0c\u8bf7\u6c42\u9489\u9489\u63a5\u53e3\r\nresponse = requests.post(url=url, headers=headers, data=send_data)\r\n# \u8bb2\u6c42\u6210\u529f\u540e\u8fd4\u56de\u7684\u6570\u636e\r\ncontent = response.content.decode()\r\n# \u6253\u5370\r\nprint(content)\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>\u6700\u540e\u5728zabbix\u9875\u9762\u6765\u8c03\u7528\u6b64sh\u6587\u4ef6\u5373\u53ef\u3002\u5982\u4e0b\u56fe\uff1a\u586b\u4e0a\u9700\u8981\u4f20\u5165\u7684\u62a5\u8b66\u4fe1\u606f{ALERT.MESSAGE}<\/p>\n<p><a href=\"http:\/\/www.laihp.top\/wordpress\/wp-content\/uploads\/2019\/06\/zabbixdingding.png\" target=\"_blank\" rel=\"noopener\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-493 size-full\" src=\"http:\/\/www.laihp.top\/wordpress\/wp-content\/uploads\/2019\/06\/zabbixdingding.png\" alt=\"\" width=\"960\" height=\"514\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<h2>\u5199\u5165log\u65e5\u5fd7web\u5c55\u793a<\/h2>\n<p>1\u3001\u9996\u5148Apache\u521b\u5efa\u4e00\u4e2a\u76ee\u5f55list\u7684web\u5c55\u793a\u3002http:\/\/www.laihp.top\/zqb\/?p=317<\/p>\n<p>2\u3001robot.sh\u7528\u4e8e\u5904\u7406\u62a5\u8b66\u4fe1\u606f\u7ed9robot.py\u9489\u9489\u53ca\u628a\u5927\u4e8e1M\u7684log\u6587\u4ef6\u653e\u5230\u53e6\u5916\u4e00\u4e2a\u76ee\u5f55\u4e0b\u3002<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"bash\">root@zqubuntu:\/usr\/lib\/zabbix\/alertscripts# ll\r\ntotal 20\r\ndrwxr-xr-x 2 root root 4096 Dec  3 16:19 .\/\r\ndrwxr-xr-x 4 root root 4096 Nov 16  2018 ..\/\r\n-rwxr-xr-x 1 root root  904 Dec  6  2018 robot.py*\r\n-rwxr-xr-x 1 root root  238 Dec  2 18:35 robot.sh*<\/code><\/pre>\n<p>\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<p>&nbsp;<\/p>\n<p>[scfc id=&#8221;scfctxt&#8221; title=&#8221;+++robot.sh&#8212;&#8220;]<\/p>\n<pre class=\"pure-highlightjs\"><code class=\"null\">#!\/bin\/bash\r\n\r\n\r\n#####\r\nstart1=$(date +%y-%m-%d-%H%M%S)\r\n\r\nfilename=\/var\/www\/html\/zabbixalert.log\r\n\r\nfilesize=`ls -l $filename | awk '{ print $5 }'`\r\n\r\n#delname=`ls -R \/data\/share\/.recycle\/ |awk '{print $0}'`\r\n\r\nmaxsize=$((1024*10))\r\n\r\nif [ $filesize -gt $maxsize ]\r\n\r\nthen\r\n                echo \"mvthisfile---------------------\" &gt;&gt; \/var\/www\/html\/zabbixalert.log\r\n                cp \/var\/www\/html\/zabbixalert.log \/var\/www\/html\/zabbixhistory\/zabbixalert.log$start1.log\r\n                echo \"newfile---------------------\" &gt; \/var\/www\/html\/zabbixalert.log\r\n                chmod 777 \/var\/www\/html\/zabbixalert.log\r\nelse\r\n                echo \"thislogfilesize----[$filesize B]\" &gt;&gt; \/var\/www\/html\/zabbixalert.log\r\nfi\r\n\r\n#####\r\n\r\n\r\nstri=$1$2$3$4$5$6$7\r\nstri1=${stri} | sed 's\/ \/\/g'\r\nstri2=${stri1} | sed 's\/(\/\/g'\r\nstri3=${stri2} | sed 's\/&gt;\/\/g'\r\npython3.6 \/usr\/lib\/zabbix\/alertscripts\/robot.py $stri\r\necho $stri &gt;&gt; \/var\/www\/html\/zabbixalert.log<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>[\/scfc]<\/p>\n<p>\u8fd0\u884c\u6548\u679c\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-844\" src=\"http:\/\/www.laihp.top\/zqb\/wp-content\/uploads\/2019\/06\/zabbixbaojingtest.png\" alt=\"\" width=\"1098\" height=\"475\" srcset=\"https:\/\/www.laihp.top\/zqb\/wp-content\/uploads\/2019\/06\/zabbixbaojingtest.png 1098w, https:\/\/www.laihp.top\/zqb\/wp-content\/uploads\/2019\/06\/zabbixbaojingtest-300x130.png 300w, https:\/\/www.laihp.top\/zqb\/wp-content\/uploads\/2019\/06\/zabbixbaojingtest-768x332.png 768w, https:\/\/www.laihp.top\/zqb\/wp-content\/uploads\/2019\/06\/zabbixbaojingtest-1024x443.png 1024w\" sizes=\"auto, (max-width: 1098px) 100vw, 1098px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h1><span style=\"color: #ff0000;\"><strong>zabbix-agent \u5b89\u88c5<\/strong><\/span><\/h1>\n<p>\u9996\u5148\u5728\u5ba2\u6237\u7aef\u5b89\u88c5agent\uff1a<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#\u5982\u679c\u4e3b\u673a\u8054\u7f51\u7684\u8bdd\uff0c\u53ef\u4ee5\u9009\u62e9\u76f4\u63a5yum\u5b89\u88c5\r\nroot@ubuntu:~# apt install zabbix-agent\r\nroot@ubuntu:~# vim  \/etc\/zabbix\/zabbix_agentd.conf \r\n\r\nLogFileSize=0\r\nEnableRemoteCommands=1 #\u5141\u8bb8\u8fdc\u7a0b\u6267\u884c\u547d\u4ee4\r\nLogRemoteCommands=1    #\u5f00\u542f\u8fdc\u7a0b\u64cd\u4f5c\u65e5\u5fd7\r\nServer=zabbix-server-ip    #\u88ab\u52a8\u6a21\u5f0f\uff0cZABBIX\u670d\u52a1\u5668IP\u5730\u5740\r\nServerActive=zabbix-server-ip     #\u4e3b\u52a8\u6a21\u5f0f\uff0cZABBIX\u670d\u52a1\u5668IP\u5730\u5740\r\nHostname=localhost-ip     #\u4e3b\u673a\u540d\u6216IP\u5730\u5740\r\n\r\nroot@ubuntu:~# systemctl restart zabbix-agent\r\nroot@ubuntu:~# systemctl enable zabbix-agent<\/pre>\n<p>\u7136\u540e\u518dzabbix\u6dfb\u52a0\u8be5\u5ba2\u6237\u7aef\u5373\u53ef<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<h2>\u6982\u8ff0<\/h2>\n<p>\u5728\u4f7f\u7528Zabbix\u76d1\u63a7ICMP\u591a\u4e2a\u4e3b\u673a\u65f6\uff0c\u4f1a\u51fa\u73b0Zabbix icmp pinger processes more than 75% busy\u7684\u62a5\u9519\u3002\u4e3b\u8981\u539f\u56e0\u4e3aICMP\u7684\u7ebf\u7a0b\u592a\u5c11\u5bfc\u81f4\uff0c\u53ef\u4ee5\u901a\u8fc7\u66f4\u6539\u914d\u7f6e\u6587\u4ef6\u8fdb\u884c\u8c03\u4f18\u3002<\/p>\n<p><a href=\"https:\/\/blog.wlzs.cn\/wp-content\/uploads\/blog.wlzs.cn-blog.wlzs_.cn-image-214.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" src=\"https:\/\/blog.wlzs.cn\/wp-content\/uploads\/blog.wlzs.cn-blog.wlzs_.cn-image_thumb-214.png\" alt=\"image\" width=\"644\" height=\"129\" border=\"0\" \/><\/a><\/p>\n<h2><a name=\"toc-2\"><\/a>\u89e3\u51b3\u65b9\u5f0f<\/h2>\n<p>\u7f16\u8f91\/etc\/zabbix\/zabbix_server.conf\u6587\u4ef6\uff0c\u5c06StartPingers\u66f4\u6539\u4e3a\u5408\u9002\u7684\u5927\u5c0f\u503c\u3002<\/p>\n<p><a href=\"https:\/\/blog.wlzs.cn\/wp-content\/uploads\/blog.wlzs.cn-blog.wlzs_.cn-image-215.png\"><img loading=\"lazy\" decoding=\"async\" title=\"image\" src=\"https:\/\/blog.wlzs.cn\/wp-content\/uploads\/blog.wlzs.cn-blog.wlzs_.cn-image_thumb-215.png\" alt=\"image\" width=\"644\" height=\"408\" border=\"0\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>\u91cd\u542fZabbix\u670d\u52a1<\/p>\n<div class=\"cnblogs_code\">\n<div id=\"urvanov-syntax-highlighter-63e600870b8c5853362740\" class=\"urvanov-syntax-highlighter-syntax crayon-theme-sublime-text urvanov-syntax-highlighter-font-liberation-mono urvanov-syntax-highlighter-os-pc print-yes notranslate urvanov-syntax-highlighter-wrapped\" data-settings=\" no-popup minimize scroll-mouseover wrap\">\n<div class=\"crayon-toolbar\" data-settings=\" show\"><\/div>\n<\/div>\n<\/div>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<hr \/>\n<p>\u9644\u4e00\u4e2a\u7fa4\u6656NAS\u7684\u6a21\u677f\uff1a<a href=\"http:\/\/www.laihp.top\/zqb\/wp-content\/uploads\/2019\/06\/zbx_export_SynoDiskStation_1.zip\">zbx_export_SynoDiskStation_1<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b89\u88c5\u6bd4\u8f83\u7b80\u5355\uff0c\u5b98\u7f51\u5b89\u88c5\u5373\u53ef\uff1a https:\/\/www.zabbix.com\/documentation\/4.0 &#8230; <a title=\"zabbix\u5b89\u88c5\u914d\u7f6e\u4e0e\u9489\u9489\u62a5\u8b66\u53ca\u5199\u5165log\u65e5\u5fd7web\u5c55\u793a\" class=\"read-more\" href=\"https:\/\/www.laihp.top\/zqb\/?p=492\" aria-label=\"\u7ee7\u7eed\u9605\u8bfbzabbix\u5b89\u88c5\u914d\u7f6e\u4e0e\u9489\u9489\u62a5\u8b66\u53ca\u5199\u5165log\u65e5\u5fd7web\u5c55\u793a\">\u9605\u8bfb\u66f4\u591a<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-492","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.laihp.top\/zqb\/index.php?rest_route=\/wp\/v2\/posts\/492","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.laihp.top\/zqb\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.laihp.top\/zqb\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.laihp.top\/zqb\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.laihp.top\/zqb\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=492"}],"version-history":[{"count":19,"href":"https:\/\/www.laihp.top\/zqb\/index.php?rest_route=\/wp\/v2\/posts\/492\/revisions"}],"predecessor-version":[{"id":2180,"href":"https:\/\/www.laihp.top\/zqb\/index.php?rest_route=\/wp\/v2\/posts\/492\/revisions\/2180"}],"wp:attachment":[{"href":"https:\/\/www.laihp.top\/zqb\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=492"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.laihp.top\/zqb\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=492"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.laihp.top\/zqb\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=492"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}