Wenn man bind
als DNS Server einsetzt, dann gibt es einen recht einfachen Weg die Statistik der Queries für Zabbix
zugänglich zu machen.
Dazu muss man erst die Statisik von bind zu aktivieren.
#/etc/bind/named.conf.local statistics-channels { inet 127.0.0.1 port 8053 allow { 127.0.0.1; }; };
und den bind neustarten.
Dann braucht es die beiden Pakete curl
und xml2
, was bei einem Debian auch schnell erledigt ist
apt-get install xml2 curl -y
Jetzt kann man mal mit folgendem Kommando testen ob man Antworten von bind
bekommt
curl http://localhost:8053/ 2>/dev/null | xml2 | grep -A1 queries
Das sollte eine solche Ausgabe erzeugen
/isc/bind/statistics/server/queries-in/rdtype/name=A /isc/bind/statistics/server/queries-in/rdtype/counter=1098 /isc/bind/statistics/server/queries-in/rdtype /isc/bind/statistics/server/queries-in/rdtype/name=NS /isc/bind/statistics/server/queries-in/rdtype/counter=34 /isc/bind/statistics/server/queries-in/rdtype /isc/bind/statistics/server/queries-in/rdtype/name=PTR /isc/bind/statistics/server/queries-in/rdtype/counter=264 /isc/bind/statistics/server/queries-in/rdtype /isc/bind/statistics/server/queries-in/rdtype/name=MX /isc/bind/statistics/server/queries-in/rdtype/counter=197 /isc/bind/statistics/server/queries-in/rdtype /isc/bind/statistics/server/queries-in/rdtype/name=TXT /isc/bind/statistics/server/queries-in/rdtype/counter=6 /isc/bind/statistics/server/queries-in/rdtype /isc/bind/statistics/server/queries-in/rdtype/name=AAAA /isc/bind/statistics/server/queries-in/rdtype/counter=156 /isc/bind/statistics/server/queries-in/rdtype /isc/bind/statistics/server/queries-in/rdtype/name=DNSKEY /isc/bind/statistics/server/queries-in/rdtype/counter=10 /isc/bind/statistics/server/queries-in/rdtype /isc/bind/statistics/server/queries-in/rdtype/name=AXFR /isc/bind/statistics/server/queries-in/rdtype/counter=136 /isc/bind/statistics/server/queries-in/rdtype /isc/bind/statistics/server/queries-in/rdtype/name=ANY /isc/bind/statistics/server/queries-in/rdtype/counter=7 /isc/bind/statistics/server/nsstat/name=Requestv4
Jetzt öffnet man die zabbix-agentd.conf
des DNS-Server und trägt folgende Userparameter ein
UserParameter=bind.queries.in[*],curl http://localhost:8053/ 2>/dev/null | xml2 | grep -A1 "/isc/bind/statistics/server/queries-in/rdtype/name=$1$" | tail -1 | cut -d= -f2 UserParameter=bind.queries.out[*],curl http://localhost:8053/ 2>/dev/null | xml2 | grep -A1 "/isc/bind/statistics/views/view/rdtype/name=$1$" | tail -1 | cut -d= -f2
Damit kann man auf dem Zabbix-Server dann folgendermassen item
s konfigurieren, um die verschiedenen Werte abzufragen
bind.queries.in[A] bind.queries.out[A]
Oder hier das Template für den Import herunterladen Damit sollte es einfacher gehen
Diskussion
Die Userparameter funktionieren so nur mit Shells welche die getrennte Umleitung von STDOUT und STDERR erlauben (z.B. bash). Bei Freebsb resp der Shell csh geben die UserParameter einen Fehler. Dann muss man dem User
zabbix
eine Shell verpassen, welche das unterstützt (via/etc/passwd
) Zudem beachten: wenn man nicht die default Shell des Systems verwendet bestehen sehr oft anderePATH
Umgebungen. Also zu Sicherheit vollständige Pfadangaben zu den Kommandoscurl
undxml2
angeben