Cacti DNS availability test script

Here’s a script I wrote for Cacti so that I can graph DNS availability (you need to drop it in /usr/share/cacti/site/scripts):

#!/usr/bin/perl
## DNS Availability Script for Cacti
## Developer: paul.roberts@n3k.co.uk
#
my $domain = $ARGV[0];  # Domain name to query
my $ns     = $ARGV[1];  # Name server to query
my $digs   = $ns ? "@\Q$ns\E" : "";
my $digcmd = "dig $digs \Q$domain\E a";
my $dig    = qx<$digcmd>;
my $status;
my $value=0;

for (split /\n/, $dig) {
   if (/^;;.*status:\s+(\S+)\s*,/) {
      $status = $1;
   }
}

if ($status ne ‘NOERROR’) {
   # Status=bad
   $value+=0;

} else {
   # Status=ok
   $value+=100;
}

print "$value\n";

exit 0;

Advertisements
This entry was posted in Computers and Internet. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s