#!/usr/local/bin/perl
# DNS plugin
# Copyright (c) 2001 Mark van Eijk <mark@luon.net>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# use strict here to ensure 'decent' coding
use strict;
use Getopt::Std;
# add extra use-clauses here
use Net::DNS;
# if extra options are needed add them in the next few lines
# use the $opt_? syntax
use vars qw($opt_p $opt_t $opt_h);
getopts("p:t:h:");
# fill in standard port for plugin
my $port = $opt_p || 53;
my $TIMEOUT = $opt_t || 5;
my $host = $opt_h || "localhost";
exit &serviceGET($host, $port, $TIMEOUT);
sub serviceGET
{
my ($server, $port, $serviceTIMEOUT) = @_;
# return failure status code by default
my $serviceOK = 1;
eval
{
# set timeout alarm
local $SIG{ALRM} = sub { die "Timeout Alarm" };
alarm $serviceTIMEOUT;
# do something usefull here to check service and generate exit code
# create resolver
my $res = new Net::DNS::Resolver;
# set port
$res->port($port);
# set nameserver
$res->nameservers($host);
# query DNS for mailhost of specific domain
my $result = $res->search("luon.net", "SOA");
# cancel alarm
alarm 0;
if ($result)
{
# change status code to OK
$serviceOK = 0;
}
};
#check for timeout
if ($@ and ($@ =~ /Timeout Alarm/))
{
# change status code to TIMEOUT
$serviceOK = 2;
}
# exit with service status code
return $serviceOK;
}
syntax highlighted by Code2HTML, v. 0.9.1