#!/usr/local/bin/perl # template plugin (can be used to make plugins) # Copyright (c) 2000 Mark van Eijk # Paul van Tilburg # 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 # 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 || 0; 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 # cancel alarm alarm 0; }; #check for timeout if ($@ and ($@ =~ /Timeout Alarm/)) { # change status code to TIMEOUT $serviceOK = 2; } # exit with service status code return $serviceOK; }