NAME
Nagios::Nrpe - Small module for creating & using NAGIOS NRPE checks.
DESCRIPTION
The main objective of this module is to allow one to rapidly create and use new custom NAGIOS NRPE checks. This is done in two ways. Firstly, this module allows one to create new check scripts on the fly. Secondly, the module gives the user a number of necessary and/or commonly found features one might use in NRPE checks. Thus removing much of the repetitive boilerplate when creating new checks. Hopefully this is achieved in such a way as to avoid too many dependencies. Finally, this over-engineered bit of code was dreamt up out of a desire to have consistent ad hoc NAGIOS NRPE scripts. More effort to setup than value added? Well...
VERSION
version 0.008
SYNOPSIS
# Example check script for yum package updates.
use Nagios::Nrpe;
my $nrpe = Nagios::Nrpe->new( verbose => 1,
log => 'off', );
$nrpe->log_info('Starting yum update notify check.');
open ( my $fh, '-|', '/usr/bin/yum check-update' )
|| $nrpe->exit_warning('yum command failed');
my $yum_info = do { local $/; <$fh> };
close ( $fh );
$nrpe->log_info('YUM: ' . $yum_info);
my $exit_code = ( $? >> 8 );
$nrpe->log_debug("YUM exit code: $exit_code");
( $exit_code == 0 ) ? $nrpe->exit_ok('OK')
: ( $exit_code == 100 ) ? $nrpe->exit_warning('new updates available')
: $nrpe->exit_unknown('unknown status');
Creating a new NRPE check
perl nagios_nrpe.pl -name foo
+ file: /path/to/script/foo.pl
Creates a skeleton script for the new check. The nagios_nrpe.pl script comes with this module.
OPTIONS
verbose
my $nrpe = Nagios::Nrpe->new( verbose => 1 );
When enabled will print log messages to stdout. If log is also enabled, will only print out messages enabled by the log setting. If log is disabled, will print all log levels to stdout. Disabled by default.
log
my $nrpe = Nagios::Nrpe->new( log => 'debug' );
log levels: off, error, warn, info, debug. When enabled at the appropriate level, will log to syslog. Disabled by default.
check_name
my $nrpe = Nagios::Nrpe->new( check_name => 'example' );
Used for check script generation. See nagios_nrpe.pl Also, when used within a NAGIOS NRPE check script this option is used to set the script name for log messages.
check_path
my $nrpe = Nagios::Nrpe->new( check_path => '/tmp' );
Used for check script generation. See nagios_nrpe.pl
SUBROUTINES/METHODS
exit_ok
my $nrpe = Nagios::Nrpe->new();
$nrpe->exit_ok( 'Looks good', \%stats );
Usage: Pass human readable message and then (optionally) nagios stats. The stats param must be a hashref. If log is enabled, will log the exit call at the INFO log level. This call will exit the program with the desired exit code.
Returns: Exits with a nagios "ok" exit code.
exit_warning
my $nrpe = Nagios::Nrpe->new();
$nrpe->exit_warning( 'This landing is gonna get pretty interesting', \%stats );
Usage: Pass human readable message and then (optionally) nagios stats. The stats param must be a hashref. If log is enabled, will log the exit call at the WARN log level. This call will exit the program with the desired exit code.
Returns: Exits with a nagios "warning" exit code.
exit_critical
my $nrpe = Nagios::Nrpe->new();
$nrpe->exit_critical( 'oh god, oh god, we're all going to die', \%stats );
Usage: Pass human readable message and then (optionally) nagios stats. The stats param must be a hashref. If log is enabled, will log the exit call at the ERROR log level. This call will exit the program with the desired exit code.
Returns: Exits with a nagios "critical" exit code.
exit_unknown
my $nrpe = Nagios::Nrpe->new();
$nrpe->exit_unknown( 'I donno lol!' );
Usage: Pass human readable message and then (optionally) nagios stats. The stats param must be a hashref. If log is enabled, will log the exit call at the WARN log level. This call will exit the program with the desired exit code.
Returns: Exits with a nagios "unknown" exit code.
log_error
my $nrpe = Nagios::Nrpe->new();
$nrpe->log_error( 'Insert error message here.' );
Usage: Error logging. If verbose is on will print to stdout. If log is set to "error" or higher will log to syslog.
NOTE: This will not exit your program. If you wish to log an error and exit your program see "exit_critical" or "exit_warning" instead.
Returns: Nothing.
log_warn
my $nrpe = Nagios::Nrpe->new();
$nrpe->log_warn( 'Insert warn message here.' );
Usage: Warn logging. If verbose is on will print to stdout. If log is set to "warn" or higher will log to syslog.
TE: This will not exit your program. If you wish to log an error and exit your program see "exit_critical" or "exit_warning" instead.
Returns: Nothing.
log_info
my $nrpe = Nagios::Nrpe->new();
$nrpe->log_info( 'Insert info message here.' );
Usage: Info logging. If verbose is on will print to stdout. If log is set to "info" or higher will log to syslog.
Returns: Nothing.
log_debug
my $nrpe = Nagios::Nrpe->new();
$nrpe->log_debug( 'Insert debug message here.' );
Usage: Debug logging. If verbose is on will print to stdout. If log is set to "debug" will log to syslog.
Returns: Nothing.
generate_check
my $nrpe = Nagios::Nrpe->new( check_name => foo,
check_path => '/tmp',
verbose => 0,
);
my $check_path = $nrpe->generate_check;
Usage: Generates a new NAGIOS NRPE check.
Returns: Path to newly created file.
_exit
INTERNAL USE ONLY.
Usage: Creates a valid exit state for a NAGIOS NRPE check. If log is enabled, will log exit message.
Returns: Exits the program. Do not pass go, do not collect $200.
_load_logger
INTERNAL USE ONLY.
Usage: Inits the log4perl logger.
Returns: blessed ref
_template
INTERNAL USE ONLY.
Returns: perl script template for new nagios nrpe check.
BUGS AND LIMITATIONS
Report bugs & issues, please email the author.
AUTHOR
Sarah Fuller, <sarah at averna.id.au>
LICENSE AND COPYRIGHT
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
This software is copyright (c) 2012 by Sarah Fuller.