Basic concept is simple – BIND will generate XML file with statistics, PHP script output 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 with:

apt-get install php5-common php5-cli

Turn on integrated BIND webserver with statistics in configuration file named.conf:

statistics-channels {
 inet * port 8053 allow { 127.0.0.1;};
};

And reload: service bind9 reload

Let’s say that we will have our statistics in /home/bindstat. Save there PHP file stats.php:

<?php
 
  $path = dirname(__FILE__)."/";
  $xml = simplexml_load_file($path."stats.xml");
 
  $save = array("Requestv4", "ReqEdns0", "ReqTCP", "Response",
                "TruncatedResp", "RespEDNS0", "QrySuccess",
                "QryAuthAns", "QryNoauthAns", "QryReferral",
                "QryNxrrset", "QrySERVFAIL", "QryNXDOMAIN",
                "QryRecursion", "QryDuplicate", "QryDropped",
                "QryFailure", "XfrReqDone");
 
  foreach($xml->bind->statistics->server->nsstat as $stat)
  {
 
    if(in_array($stat->name, $save))
    {
      $f = fopen($path.$stat->name, "w");
      fwrite($f, $stat->counter, strlen($stat->counter));
      fclose($f);
    }

  }

Edit crontab and add lines to download statistics and parse them:

*/1 * * * * curl -s http://127.0.0.1:8053/ > /home/bindstat/stats.xml && /usr/bin/php5 -f /home/bindstat/stats.php

Make sure we have proper rights and owners:

chmod 0660 /home/bindstat/*
chown zabbix /home/bindstat/*

Finally add file for ZABBIX agent /etc/zabbix/zabbix_agentd.d/bind.conf with content:

UserParameter=bind.status[*],head -n 1 /home/bindstat/bind/$1

And restart: /etc/init.d/zabbix-agent reload

To use with ZABBIX start with this template from ZABBIX 2.0 with basic items and triggers. Also you can download template from Zabbix 4.4 here.

Enjoy!