{"id":324,"date":"2015-04-22T19:30:19","date_gmt":"2015-04-22T18:30:19","guid":{"rendered":"http:\/\/tricker.cz\/?p=324"},"modified":"2020-02-21T11:12:46","modified_gmt":"2020-02-21T10:12:46","slug":"monitoring-bind-9-6-with-zabbix-on-ubuntu","status":"publish","type":"post","link":"https:\/\/tricker.cz\/?p=324","title":{"rendered":"Monitoring BIND 9.6 with ZABBIX on Ubuntu"},"content":{"rendered":"<p>Basic concept is simple &#8211; BIND will generate XML file with statistics, PHP script\u00a0output values we want into standalone files and we read those values with ZABBIX agent.<\/p>\n<p>We gonna need PHP to process XML statistics from BIND, install it with:<\/p>\n<pre class=\"toolbar:2 toolbar-overlay:false lang:default decode:true\">apt-get install php5-common php5-cli<\/pre>\n<p>Turn on integrated BIND webserver with statistics in configuration file <strong>named.conf<\/strong>:<\/p>\n<pre class=\"toolbar:1 lang:default decode:true\">statistics-channels {\n inet * port 8053 allow { 127.0.0.1;};\n};<\/pre>\n<p>And reload:\u00a0<strong>service bind9 reload<\/strong><\/p>\n<p>Let&#8217;s say that we will have our statistics in <strong>\/home\/bindstat<\/strong>.\u00a0Save there PHP file <strong>stats.php<\/strong>:<\/p>\n<pre class=\"toolbar:1 lang:php decode:true\" title=\"\/home\/bindstat\/stats.php\">&lt;?php\n \n  $path = dirname(__FILE__).\"\/\";\n  $xml = simplexml_load_file($path.\"stats.xml\");\n \n  $save = array(\"Requestv4\", \"ReqEdns0\", \"ReqTCP\", \"Response\",\n                \"TruncatedResp\", \"RespEDNS0\", \"QrySuccess\",\n                \"QryAuthAns\", \"QryNoauthAns\", \"QryReferral\",\n                \"QryNxrrset\", \"QrySERVFAIL\", \"QryNXDOMAIN\",\n                \"QryRecursion\", \"QryDuplicate\", \"QryDropped\",\n                \"QryFailure\", \"XfrReqDone\");\n \n  foreach($xml-&gt;bind-&gt;statistics-&gt;server-&gt;nsstat as $stat)\n  {\n \n    if(in_array($stat-&gt;name, $save))\n    {\n      $f = fopen($path.$stat-&gt;name, \"w\");\n      fwrite($f, $stat-&gt;counter, strlen($stat-&gt;counter));\n      fclose($f);\n    }\n\n  }<\/pre>\n<p>Edit crontab and add lines to download statistics and parse them:<\/p>\n<pre class=\"toolbar:1 lang:default decode:true \">*\/1 * * * * curl -s http:\/\/127.0.0.1:8053\/ &gt; \/home\/bindstat\/stats.xml &amp;&amp; \/usr\/bin\/php5 -f \/home\/bindstat\/stats.php<\/pre>\n<p>Make sure we have proper rights and owners:<\/p>\n<pre class=\"toolbar:1 lang:default decode:true\">chmod 0660 \/home\/bindstat\/*\nchown zabbix \/home\/bindstat\/*<\/pre>\n<p>Finally add file for ZABBIX agent <strong>\/etc\/zabbix\/zabbix_agentd.d\/bind.conf<\/strong> with content:<\/p>\n<pre class=\"toolbar:2 lang:default decode:true\">UserParameter=bind.status[*],head -n 1 \/home\/bindstat\/bind\/$1<\/pre>\n<p>And restart:\u00a0<strong>\/etc\/init.d\/zabbix-agent reload<\/strong><\/p>\n<p><a href=\"http:\/\/tricker.cz\/assets\/zbx_bind.xml\">To use with ZABBIX start with this template from ZABBIX 2.0 with basic items and triggers. <\/a><a href=\"https:\/\/tricker.cz\/assets\/zbx_export_templates-bind-zbx44.xml\">Also you can download template from Zabbix 4.4 here.<\/a><\/p>\n<p>Enjoy!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Basic concept is simple &#8211; BIND will generate XML file with statistics, PHP script\u00a0output values we want into standalone files and we read those values with ZABBIX agent. We gonna need PHP to process XML statistics from BIND, install it&#8230; <a class=\"more-link\" href=\"https:\/\/tricker.cz\/?p=324\">Pokra\u010dovat ve \u010dten\u00ed &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24],"tags":[],"_links":{"self":[{"href":"https:\/\/tricker.cz\/index.php?rest_route=\/wp\/v2\/posts\/324"}],"collection":[{"href":"https:\/\/tricker.cz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tricker.cz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tricker.cz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tricker.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=324"}],"version-history":[{"count":17,"href":"https:\/\/tricker.cz\/index.php?rest_route=\/wp\/v2\/posts\/324\/revisions"}],"predecessor-version":[{"id":566,"href":"https:\/\/tricker.cz\/index.php?rest_route=\/wp\/v2\/posts\/324\/revisions\/566"}],"wp:attachment":[{"href":"https:\/\/tricker.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=324"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tricker.cz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=324"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tricker.cz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=324"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}