#!/usr/bin/perl -w # # check dns daemon, freshness of wleiden-zonefile and resolving of internet-domains # # syntax: # ./check_dns --host= [--testhost=host.domain.net] # # jorg@wirelessleiden.nl - 6 november 2004 use strict; use Getopt::Long; #use Data::Dumper; # # settings # $ENV{PATH} = "/usr/bin"; my $host = "/usr/bin/host"; my $hostname2 = ""; my $testhost2 = "www.wirelessleiden.nl"; GetOptions("hostname:s" => \$hostname2, "testhost:s" => \$testhost2); my $errorcode = 0; my ($msg1, $msg2); my ($hostname) = $hostname2 =~ /([\/\w\.\-]+)/s; my ($testhost) = $testhost2 =~ /([\/\w\.\-]+)/s; if (! defined $hostname) { print "usage: ./check_dns --host= [--testhost=host.domain.net]\n"; exit 3; # unknown } if (! -e "$host") { print "$host not found\n"; exit 3; # unknown } # # check cached zones # my $result = `$host -t soa wleiden.net $hostname | tail -1`; chop($result); my ($tmp, $serial); if ("$result" =~ "connection timed out") { # named isn't running or it doesn't know anything about wleiden.net $msg1 = "No response"; $errorcode = 2; # critical } elsif ("$result" =~ "not found") { # named is running but it doesn't know anything about wleiden.net $msg1 = "Not found"; $errorcode = 2; # critical } elsif ("$result" =~ "has SOA record") { # named is running. show serial. ($tmp, $tmp, $tmp, $tmp, $tmp, $tmp, $serial) = split(/ /, $result); $msg1 = "OK"; } else { # something else. just show message. $msg1 = "$result"; $errorcode = 3; # unknown } # # check internet zones # $result = `$host $testhost $hostname >/dev/null 2>&1; echo \$?`; chop($result); if ("$result" eq "0") { $msg2 = "OK"; } else { # named isn't running or it doesn't know anything about the internet-zones $msg2 = "No response"; $errorcode = 2; # critical } # # exit # (0=ok 1=warning 2=critical 3=unknown 4=dependent) # print("Local: $msg1, Internet: $msg2"); #if (defined $serial) { # print(" (wleiden.net serial: $serial)"); #} print "\n"; exit $errorcode;