Search Exchange

Search All Sites

Nagios Live Webinars

Let our experts show you how Nagios can help your organization.

Contact Us

Phone: 1-888-NAGIOS-1
Email: sales@nagios.com

Login

Remember Me

Directory Tree

check_bind.sh

Current Version
1.3
Last Release Date
2009-05-20
Compatible With
  • Nagios 2.x
  • Nagios 3.x
Hits
131439
Files:
FileDescription
check_bind.shThe plugin (v1.3)
LICENSEGNU GPLv2 License
check_bind.phpPNP Template
Nagios CSP

Meet The New Nagios Core Services Platform

Built on over 25 years of monitoring experience, the Nagios Core Services Platform provides insightful monitoring dashboards, time-saving monitoring wizards, and unmatched ease of use. Use it for free indefinitely.

Monitoring Made Magically Better

  • Nagios Core on Overdrive
  • Powerful Monitoring Dashboards
  • Time-Saving Configuration Wizards
  • Open Source Powered Monitoring On Steroids
  • And So Much More!
check_bind.sh
sh compliant script to check whether BIND is running and to get the performance data via rndc stats (PNP Template included)
Description
check_bind.sh is a Nagios plugin to check the bind daemon whether it's running via its pid file and then gets the statistics via rndc stats. The user that run the script needs the ability to 'sudo rndc stats'! The timeframe in which the rndc stats output is updated is controlled by the check interval. The output shows amount of requests of various types occured during the last check interval. The script itself is written sh-compliant and free software under the terms of the GPLv2 (or later).

BIND9 versions 9.3 and 9.5 or greater are now supported as well. I didn't have the time yet to do more testing. It works for me under Gentoo with BIND 9.4 and 9.6 and under Debian Lenny with BIND 9.5 as well. If something doesn't work, please contact me via mike@matejunkie.com or via a blog comment at [http://www.matejunkie.com/]. Thanks in advance.
I finally solved the mawk/gawk problem with a little help from a user of this plugin. It should run now with either gawk or mawk without any problems.

-h/--help Output
check_bind.sh -p/--path_pid /var/run/named -n/--name_pid named.pid -r/--path-rndc /usr/sbin -s/--path-stats /var/bind -V/--bind-version 9.3/9.4/9.5 -N

Options:
-p/--path-pid)
Path where the pid file for bind is stored. You might need to alter this to your distribution's way of dealing with pid files. Default is: /var/run/named
-n/--name_pid)
Name of the pid file. Default is: named.pid
-r/--path-rndc)
Path where the rndc binary is located. Default is: /usr/sbin
-s/--path-stats)
Path where the named.stats file is stored. Default is: /var/bind
-t/--path-tmp)
Path where the temporary named.stats excerpt is being stored. Default is: /tmp
-V/--bind-version)
Specifies the bind version you're running. Currently there's BIND 9.3, 9.4 and 9.5 supported. Default is: 9.4
-N/--no-pid-check)
If you don't want that the script checks for the pid file, use this option. Default is: off

Output example
user@host ~ $ ./check_bind.sh
Bind9 is running. 640 successfull requests, 0 referrals, 3 nxdomains since last check. | 'success'=640 'referral'=0 'nxrrset'=236 'nxdomain'=3 'recursion'=1 'failure'=0 'duplicate'=0 'dropped'=0

Changelog
* 2009-05-20
* Bugfix for more awk compliance
* 2009-05-14
* Small bugfix for two exit codes
* 2009-05-03
* The plugin now supports BIND versions 9.3 and 9.5+.
* The named.stats file is now initially parsed via awk and the excerpts are being copied to a temp directory for further use instead of frequently tail'ing the named.stats
* The temporary directory is configurable via -t/--path-tmp as well
* The path to the rndc binary is now configurable via -r/--path-rndc
* You're now able to deactivate the pid check via -N/--no-pid-check

* 2009-04-06
* Did some slight debugging on the option parsing. The -s/--path-stats option was missing. Should be working now just fine.
Reviews (4)
Just my +2 Cents. The script doesnt' truncate the stats file from rndc stats command. As result after several years I noticed that /var/named/data/named_stats.txt increased to 1,5G and when the script within icinga tries to run this script it take about 2 minutes before tac command load all the file into the memory to perform awk action. Of course icinga tries to kill the script after 60 seconds timeout and produces error. I have modified a script a little a bit, so the named statistics file will be purged everytime after check_bind.sh is executed:

[root@dns2 ~]# diff -u /usr/lib64/nagios/plugins/site/privileged/check_bind.sh ./check_bind.sh
--- /usr/lib64/nagios/plugins/site/privileged/check_bind.sh 2021-11-08 15:20:32.365380038 +0100
+++ ./check_bind.sh 2021-11-09 13:44:52.301734327 +0100
@@ -143,6 +143,7 @@
then
sudo chroot $path_chroot $path_rndc/rndc stats
else
+ test -f $path_stats/named_stats.txt && truncate --size 0 $path_stats/named_stats.txt
sudo $path_rndc/rndc stats
fi
}
This check calls sudo to run /usr/sbin/rndc stats. This may be an issue if "Defaults requiretty" is set in /etc/sudoers, and you run the command through sh without opening a session at the remote host.

To resolve this, either remove "Defaults requiretty" from /etc/sudoers, or modify the script so that it doesn't call sudo.
bysaniks, December 2, 2012
Works with BIND 9.6.-ESV-R5-P1
To work on FreeBSD replace "tac" in line 151 to "tail-r".
bydylan22, December 1, 2011
1 of 1 people found this review helpful
The script required a few tweeks to work. 1-put nagios in the named group, 2-add "sudo rndc stats"

That was it and it worked fine.

I wish there was an option to send a test query though... how about --test-query test.domain.com

That would send an alert because the query failed. (Having a PID doesn't always mean bind is working properly.)