{"id":654,"date":"2022-02-05T05:27:31","date_gmt":"2022-02-04T20:27:31","guid":{"rendered":"https:\/\/roroing.net\/?p=654"},"modified":"2022-02-05T05:27:31","modified_gmt":"2022-02-04T20:27:31","slug":"zabbix%e3%81%ae%e3%83%9b%e3%82%b9%e3%83%88%e3%82%92hosts%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%81%ab%e8%bf%bd%e8%a8%98%e3%81%99%e3%82%8b%e3%82%b7%e3%82%a7%e3%83%ab%e3%82%b9%e3%82%af%e3%83%aa%e3%83%97","status":"publish","type":"post","link":"https:\/\/roroing.net\/?p=654","title":{"rendered":"Zabbix\u306e\u30db\u30b9\u30c8\u3092hosts\u30d5\u30a1\u30a4\u30eb\u306b\u8ffd\u8a18\u3059\u308b\u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8"},"content":{"rendered":"\n<p>Zabbix\u3067\u30db\u30b9\u30c8\u3092\u5927\u91cf\u306b\u62b1\u3048\u3066\u3044\u308b\u3068\u4e00\u6c17\u306b\u30a2\u30e9\u30fc\u30c8\u767a\u751f\u3057\u305f\u3068\u304d\u306b\u78ba\u8a8d\u306b\u82e6\u52b4\u3059\u308b\u3002<br>\u4f8b\u3048\u3070\u3001\u300caaa.com\u3067\u30a2\u30e9\u30fc\u30c8\u304c\u767a\u751f\u3057\u307e\u3057\u305f\u300d\u3068\u30a2\u30e9\u30fc\u30c8\u304c\u767a\u751f\u3057\u305f\u3089\u3001<br>\u307e\u305a\u3001\u8e0f\u307f\u53f0\u30b5\u30fc\u30d0\u30fc\u306e\u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u30ed\u30b0\u30a4\u30f3\u3057\u3001aaa.com\u306eIP\u3092nslookup\u3067\u53d6\u5f97\u3059\u308b\u3002<br>\u6b21\u306b\u53d6\u5f97\u3057\u305fIP\u3067ssh\u63a5\u7d9a\u3002\u539f\u56e0\u3092\u8abf\u3079\u3066\u89e3\u6c7a\u3002\u306e\u3088\u3046\u306a\u6d41\u308c\u3002<br><br>\u4eca\u56de\u306f\u3001nslookup\u3067\u30c9\u30e1\u30a4\u30f3\u304b\u3089IP\u3092\u53d6\u5f97\u3059\u308b\u6d41\u308c\u304c\u9762\u5012\u3060\u3063\u305f\u305f\u3081\u3001\/etc\/hosts\u30d5\u30a1\u30a4\u30eb\u306b\u8ffd\u8a18\u3059\u308b\u3053\u3068\u3067\u3001<br>\u30c9\u30e1\u30a4\u30f3\u3067ssh\u63a5\u7d9a\u3067\u304d\u308b\u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u8003\u3048\u3066\u307f\u305f\u3002<br><br>mkhosts.sh<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/bin\/bash\r\nheader='Content-Type:application\/json-rpc'\r\napiurl='http:\/\/000.000.000\/zabbix\/api_jsonrpc.php'\r\njson='{\"jsonrpc\": \"2.0\",\"method\": \"user.login\",\"params\": {\"user\": \"zabbix\u306e\u30e6\u30fc\u30b6\u30fc\u540d\",\"password\": \"Zabbix\u306e\u30d1\u30b9\u30ef\u30fc\u30c9\"},\"id\": 1,\"auth\": null}'\r\n\r\nzbxauth=$(curl -sS -X POST -H \"${header}\" -d \"${json}\" ${apiurl} | jq -r \".result\")\r\necho $zbxauth\r\n\r\njson='{\"jsonrpc\": \"2.0\",\"method\": \"host.get\",\"params\": {\"output\": &#91;\"hostid\",\"host\"]},\"id\": 2,\"auth\": \"'$zbxauth'\"}'\r\necho $json | jq\r\n\r\nhostlist=`curl -sS -X POST -H \"${header}\" -d \"${json}\" ${apiurl} | jq | grep \"host\"| grep -v \"hostid\" | awk -F: '{print $2}' | sed \"s\/\\\"\/\"\"\/g\" `\r\n\r\nfor i in $hostlist \r\ndo\n\r#\u4efb\u610f\u3067nslookup\u306e\u7d50\u679c\u3092IP\u306e\u307f\u306b\u6574\u5f62\u3059\u308b\niplist=`nslookup $i | grep \"Address\" | grep -v \"\\#53\" |  awk -F: '{print $2}'` \r\necho \"$iplist $i\"| sed 's\/^&#91; \\t]*\/\/' >> \/etc\/hosts \r\ndone<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>\u5168\u4f53\u306e\u6d41\u308c\u3068\u3057\u3066\u3001Zabbix\u306eAPI\u304b\u3089\u30db\u30b9\u30c8\u540d\u3092\u53d6\u5f97\u3057\u6574\u5f62\u3059\u308b\u3002<br>\u6b21\u306b\u53d6\u5f97\u3057\u305f\u30db\u30b9\u30c8\u540d\u3092\u5f15\u6570\u306b\u3057\u3066for\u6587\u3067nslookup\u3092\u304b\u3051\u3066IP\u3092\u53d6\u5f97\u3059\u308b\u5909\u6570\u3092\u3064\u304f\u308b<br>\u6700\u5f8c\u306b\u3001echo\u3067\u300cIP \u30db\u30b9\u30c8\u540d\u300d\u306e\u5f62\u306b\u3057\u305f\u3082\u306e\u3092\u3001\/etc\/hosts\u3000\u30d5\u30a1\u30a4\u30eb\u306e\u6700\u7d42\u884c\u306b\u8ffd\u8a18\u3059\u308b\u3002<br> mkhosts.sh \u5b9f\u884c\u5f8c\u3001\/etc\/hosts\u30d5\u30a1\u30a4\u30eb\u3092\u78ba\u8a8d\u3059\u308b\u3068\u3001<br>IP \u30db\u30b9\u30c8\u540d<br>\u3068\u306a\u3063\u3066\u3044\u308b\u306f\u305a\u3002<br>\u305d\u306e\u5f8c\u3001<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>ssh \u30db\u30b9\u30c8\u540d<\/code><\/pre>\n\n\n\n<p>\u3067\u5bfe\u8c61\u306e\u30db\u30b9\u30c8\u306b\u63a5\u7d9a\u3067\u304d\u308b\u3068\u601d\u3046\u306e\u3067\u78ba\u8a8d\u3057\u3066\u307f\u3066\u307b\u3057\u3044\u3002<br><br>\u53c2\u8003<br>https:\/\/www.zabbix.com\/documentation\/4.4\/en\/manual\/api<br>https:\/\/tech-mmmm.blogspot.com\/2019\/02\/zabbix-api.html<br>https:\/\/orebibou.com\/ja\/home\/201607\/20160712_003\/<br>https:\/\/ex1.m-yabe.com\/archives\/3306<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Zabbix\u3067\u30db\u30b9\u30c8\u3092\u5927\u91cf\u306b\u62b1\u3048\u3066\u3044\u308b\u3068\u4e00\u6c17\u306b\u30a2\u30e9\u30fc\u30c8\u767a\u751f\u3057\u305f\u3068\u304d\u306b\u78ba\u8a8d\u306b\u82e6\u52b4\u3059\u308b\u3002\u4f8b\u3048\u3070\u3001\u300caaa.com\u3067\u30a2\u30e9\u30fc\u30c8\u304c\u767a\u751f\u3057\u307e\u3057\u305f\u300d\u3068\u30a2\u30e9\u30fc\u30c8\u304c\u767a\u751f\u3057\u305f\u3089\u3001\u307e\u305a\u3001\u8e0f\u307f\u53f0\u30b5\u30fc\u30d0\u30fc\u306e\u30b3\u30f3\u30bd\u30fc\u30eb\u306b\u30ed\u30b0\u30a4\u30f3\u3057\u3001aaa.com\u306e <a href=\"https:\/\/roroing.net\/?p=654\" class=\"more-link\">...<span class=\"screen-reader-text\"> \"Zabbix\u306e\u30db\u30b9\u30c8\u3092hosts\u30d5\u30a1\u30a4\u30eb\u306b\u8ffd\u8a18\u3059\u308b\u30b7\u30a7\u30eb\u30b9\u30af\u30ea\u30d7\u30c8\"<\/span> \u3092\u7d9a\u3051\u3066\u8aad\u3080<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[10,14],"tags":[],"class_list":{"0":"post-654","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-zabbix","7":"category-14","8":"h-entry","9":"hentry","10":"h-as-article"},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/roroing.net\/index.php?rest_route=\/wp\/v2\/posts\/654","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/roroing.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/roroing.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/roroing.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/roroing.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=654"}],"version-history":[{"count":2,"href":"https:\/\/roroing.net\/index.php?rest_route=\/wp\/v2\/posts\/654\/revisions"}],"predecessor-version":[{"id":656,"href":"https:\/\/roroing.net\/index.php?rest_route=\/wp\/v2\/posts\/654\/revisions\/656"}],"wp:attachment":[{"href":"https:\/\/roroing.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=654"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/roroing.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=654"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/roroing.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=654"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}