NAME

Nagios::Clientstatus - Framework for Nagios check-service programs

SYNOPSIS

use Nagios::Clientstatus;
# This is needed for logging
use Log::Log4perl qw/:easy/;
Log::Log4perl->easy_init($ERROR);
my $logger = Log::Log4perl->get_logger;

# Arguments to the program are:
# --critical=40 --warning=35 --hostname=server1.zdf --sensor_nr=4
my $version = "0.01";
my $ncli    = Nagios::Clientstatus->new(
    help_subref    => \&help,
    version        => $version,
    dont_check_commandline_args => 0, # default
    mandatory_args => [ "hostname", "sensor_nr", "critical", "warning" ],
);

# ask only one time, because it's expensive
my $temperature = &get_temperature_of_sensor(
    hostname  => $ncli->get_given_arg('hostname'),
    sensor_nr => $ncli->get_given_arg('sensor_nr'),
);

# Message for the user to read
my $msg;
my $status;

# strange case
if (   ( !defined $temperature )
    || ( defined $temperature && $temperature eq "" ) )
{
    $status = "unknown";
    $msg    = "Could not get temperature from sensor";
}
else {

    # We got a temperature
    # worst case first
    if ( $temperature > $ncli->get_given_arg('critical') ) {
        $status = "critical";
    }
    elsif ( $temperature > $ncli->get_given_arg('warning') ) {
        $status = "warning";
    }
    else {
        $status = "ok";
    }
    $msg = sprintf "Temperature is %s degrees Celsius", $temperature;
}
printf "%s - %s", uc($status), $msg;
exit $ncli->exitvalue($status);

sub help {
    print "Usage:\n";
    print "$0 --critical=40 --warning=35"
      . " --hostname=server1.zdf --sensor_nr=4";

    # When supplying help you should exit
    exit;
}

DESCRIPTION

Create a program to check the function of some service or device for Nagios. This module helps you to check the mandatory and optional arguments. It helps you to send the right output so that Nagios can check wether the service works ok or not.

METHODS

new

Create the object. Immediately check commandline arguments which are mandatory for every Nagios command.

Usage:

my $ncli = Nagios::Clientstatus->new(
    help_subref => \&help,
    version => $version,
    dont_check_commandline_args => 0, # default
    # mandatory_args is optional, maybe you don't need any
    mandatory_args => [ "url" ],
);

_get_mandatory_args

Which args MUST be given to the programm? Each argument must have a value, too.

_set_given_args

Which arguments where given to the program?

get_given_arg

Object-creator can ask for the value of an argument given to the program.

_check_commandline_args

There are arguments which must exist when calling a Nagios-checker. warning|critcal are mandatory, other mandatory were given by new.

exitvalue

Return the value the Nagios-command must return to Nagios. This is the only value which is important for the Nagios state.

Use it like this:

exit $ncli->exitvalue( $status );

or without object as class-method:

exit Nagios::Clientstatus::exitvalue( $status );

Returnvalue can be a string of these:

OK|WARNING|CRITICAL|UNKNOWN

help_example

Give the user a hint how to use this programm.

BUGS

SUPPORT

AUTHOR

Richard Lippmann
CPAN ID: HORSHACK
horshack@lisa.franken.de
http://lena.franken.de

COPYRIGHT

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the LICENSE file included with this module.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 176:

=cut found outside a pod block. Skipping to next block.