#!/usr/bin/perl -w # $Id: check_lockerd 54 2007-01-23 14:36:56Z wsnyder $ ###################################################################### # # Copyright 2006-2007 by Wilson Snyder . This # program is free software; you can redistribute it and/or modify it under # the terms of either the GNU Lesser General Public License or the Perl # Artistic License. # # 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. # ###################################################################### require 5.006_001; use lib '../blib/lib'; # testing use Getopt::Long; use Pod::Usage; use strict; use vars qw ($Debug); use lib "/usr/lib/nagios/plugins" ; use utils qw(%ERRORS &print_revision &support &usage); use IPC::Locker; #====================================================================== # main our $PROGNAME = "check_lockerd"; my %opt_req_params = ( host => "localhost", ); autoflush STDOUT 1; autoflush STDERR 1; Getopt::Long::Configure('bundling'); if (! GetOptions ( "h|help" => \&print_usage, "v|debug" => \&debug, "V|version" => \&version, "p|port=i" => sub {$opt_req_params{port} = $_[1];}, "H|host|hostname=s" => sub {$opt_req_params{host} = $_[1];}, )) { usage("Bad options passed, use --help for more information.\n"); } check_lockerd(%opt_req_params); #---------------------------------------------------------------------- sub print_usage { print_revision($PROGNAME, '$Id: check_lockerd 54 2007-01-23 14:36:56Z wsnyder $'); pod2usage(-verbose=>2, -exitval => 2); support(); exit $ERRORS{'OK'}; } sub version { print_revision($PROGNAME, '$Id: check_lockerd 54 2007-01-23 14:36:56Z wsnyder $'); exit $ERRORS{'OK'}; } sub debug { $Debug = 1; $IPC::Locker::Debug = 1; } ####################################################################### sub check_lockerd { my %params = (@_); # Config requestor my $locker = new IPC::Locker (%params); # Send a request to the server, get reply & trap errors my $res = $locker->ping_status(); if ($res && $res->{ok}) { print "LOCKERD OK - $res->{status}\n"; exit $ERRORS{OK}; } else { print "LOCKERD CRITICAL - $res->{status}\n"; exit $ERRORS{CRITICAL}; } } ####################################################################### __END__ =pod =head1 NAME check_lockerd - Under Nagios, check the lockerd daemon on the specified host. =head1 SYNOPSIS check_lockerd --host hostname -p port =head1 DESCRIPTION Check_lockerd is a nagios plugin for the IPC::Locker daemon. Add to Nagios's checkcommands.cfg: define command{ command_name check_lockerd command_line $USER1$/check_lockerd -H $HOSTADDRESS$ } A quicker, but less accurate check is possible using the default Nagios check_tcp plugin as follows: define command{ command_name check_lockerd command_line $USER1$/check_tcp -H $HOSTADDRESS$ -p 1751 } =head1 ARGUMENTS =over 4 =item --help Displays this message and program version and exits. =item --host Specifies host name to check for a process. =item --port Specifies the port number to contact the "lockerd" on. (default 1752) =back =head1 DISTRIBUTION The latest version is available from CPAN and from L. Copyright 2006-2007 by Wilson Snyder. This package is free software; you can redistribute it and/or modify it under the terms of either the GNU Lesser General Public License or the Perl Artistic License. =head1 AUTHORS Wilson Snyder =head1 SEE ALSO L, L, L, L =cut ###################################################################### ### Local Variables: ### compile-command: "./check_lockerd " ### End: