wget "https://raw.githubusercontent.com/Pesticles/Zabbix-Bind9-Statistics-Collection/master/bind-stats.py"
mv bind-stats.py /usr/local/bin
chmod +x /usr/local/bin/bind-stats.py

cp /etc/bind/named.conf /etc/bind/named.conf.old
echo -e "statistics-channels {
 	inet 127.0.0.1 port 8653 allow { 127.0.0.1; };
};
" >> /etc/bind/named.conf

systemctl restart bind9

echo -e "UserParameter=bind.discoverzones,/usr/local/bin/bind-stats.py discoverzones
UserParameter=bind.json,/usr/local/bin/bind-stats.py json
UserParameter=bind.jsonzone[*],/usr/local/bin/bind-stats.py jsonzone -z \$1
UserParameter=bind.counter[*],/usr/local/bin/bind-stats.py counter -c \$1
UserParameter=bind.zonecounter[*],/usr/local/bin/bind-stats.py zonecounter -z \$1 -c \$2
UserParameter=bind.zonemaintenancecounter[*],/usr/local/bin/bind-stats.py zonemaintenancecounter -c \$1
UserParameter=bind.resolvercounter[*],/usr/local/bin/bind-stats.py resolvercounter -c \$1
UserParameter=bind.socketcounter[*],/usr/local/bin/bind-stats.py socketcounter -c \$1
UserParameter=bind.incounter[*],/usr/local/bin/bind-stats.py incounter -c \$1
UserParameter=bind.outcounter[*],/usr/local/bin/bind-stats.py outcounter -c \$1
UserParameter=bind.memory[*],/usr/local/bin/bind-stats.py memory -c \$1
UserParameter=bind.cache[*],/usr/local/bin/bind-stats.py cache -c \$1
" > /etc/zabbix/zabbix_agentd.d/userparameter_bind.conf

systemctl restart zabbix-agent
