The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Nagios::Plugin::Simple - Simple and Minimalistic Nagios Plugin Package

SYNOPSIS

use Nagios::Plugin::Simple;
my $nps=Nagios::Plugin::Simple->new;
$nps->ok("I'm OK") if &ok;
$nps->warning("I'm a bit sickly") if &sick;
$nps->critical("Barf...");
$nps->unknown("Huh?");

In the true spirit of Perl you can even do a one-liner.

perl -MNagios::Plugin::Simple -e 'Nagios::Plugin::Simple->new->ok("")';echo $?

DESCRIPTION

This is the package that I use mostly because I feel the Nagios::Plugin is too encompassing. I feel that it is the scripts responsibility to handle arguments and thus this package does not do that nor will do that. If you want argument handling use one of the GetOpt packages.

USAGE

use Nagios::Plugin::Simple;
my $nps=Nagios::Plugin::Simple->new;
if (&ok) {$nps->ok("good!")} else {$nps->critical("bad!")};

CONSTRUCTOR

new

my $nps=Nagios::Plugin::Simple->new();

METHODS

initialize

ok

Exits script with ok status code.

$nps->ok("I'm OK");

Prints "OK: %s" and exits with a code 0.

STDOUT => "OK: I'm OK\n",  EXIT=>0

warning

Exits script with warning status code.

$nps->warning("I'm a bit sickly");

Prints "Warning: %s" and exits with a code 1.

STDOUT => "Warning: I'm a bit sickly\n",  EXIT=>1

critical

Exits script with critical status code.

$nps->critical("Barf...");

Prints "Critical: %s" and exits with a code 2.

STDOUT => "Critical: Barf...\n",  EXIT=>2

unknown

Exits script with unknown status code.

$nps->unknown("Huh?")

Prints "Unknown: %s" and exits with a code 3.

STDOUT => "Unknown: Huh?\n",  EXIT=>3

code

Exits script by status code. This works best if your status is actually stored as a code 0, 1, 2, or 3 in a variable.

$nps->code($code => $string);

Examples:

$nps->code(0 => "I'm OK!");
$nps->code(1 => "I'm a bit sickly");
$nps->code(2 => "Barf...");
$nps->code(3 => "Huh?")

Prints ``$status: %s'' and exits with $code.

status

Exits script by status string. This works best if your string is actually stored as "OK", "Warning", etc in a variable

$nps->status($status    => $string);

Examples:

$nps->status("OK"       => "I'm OK!");
$nps->status("Warning"  => "I'm a bit sickly");
$nps->status("Critical" => "Barf...");
$nps->status("Unknown"  => "Huh?")

Prints ``$status: %s'' and exits with correct code.

codes

Returns a hash of the Nagios status codes.

my %codes=$nps->codes;           #(OK=>0, Warning=>1, Critical=>2, Unknown=>3)
my $codes=$nps->codes;           #{OK=>0, Warning=>1, Critical=>2, Unknown=>3}
my %status=reverse $self->codes; #(0=>"OK", 1=>"Warning", ...)

BUGS

SUPPORT

AUTHOR

Michael R. Davis
CPAN ID: MRDVT
STOP, LLC
account=>perl,tld=>com,domain=>michaelrdavis
http://www.stopllc.com/

COPYRIGHT

This program is free software licensed under the...

The BSD License

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

SEE ALSO

Nagios::Plugin, Getopt::Std, Getopt::Long