How to Enable check_dns on Nagios Monitoring System

Most user who are new to Nagios doesn’t know there is a hidden plug-in called check_dns in Nagios Monitoring system. On FreeBSD server, the binary can be found at /usr/local/libexec/nagios. List the directory and you should see check_dns.

check_dns usage is as below


$ ./check_dns -H host [-s server] [-a expected-address] [-A] [-t timeout] [-w warn] [-c crit]

Try to run the command as below and you will get the query result


$ ./check_dns -H systems.takizo.com -s 8.8.8.8        
DNS OK: 0.012 seconds response time. systems.takizo.com returns 70.32.103.130|time=0.011703s;;;0.000000


Sweet, that is the DNS query plugin, it does DNS query check on your DNS host server and return the query time.
Here is how to activate the monitoring, add the check_dns plug-in into Nagios’ commands.cfg configuration file.

On FreeBSD server, it’s located at /usr/local/etc/nagios/objects/commands.cfg
Edit the file commands.cfg and add the line below


define command {
        command_name    check_dns
        command_line    $USER1$/check_dns -H $HOSTADDRESS$ -s $ARG1$
}
  • $ARG1$ is the argument you will parse into in the configuration
  • $HOSTADDRESS$ is your host on Nagios monitoring.

Next, put the line below into service check configuration file


define service {
        use                                  generic-service
        host_name                       your-dns-host
        service_description          Check Google.com on DNS Server
        check_command              check_dns!www.google.com
}

Restart your Nagios service now


$ /usr/local/etc/rc.d/nagios restart

If it’s failed, you will the red color on the monitoring status. There are a lot other plug-ins can be explore too. Have fun.