Nagios::Nrpe - Small module for creating & using NAGIOS NRPE checks.
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 0.008
# 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');
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.
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.
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.
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.
my $nrpe = Nagios::Nrpe->new( check_path => '/tmp' );
Used for check script generation. See nagios_nrpe.pl
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.
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.
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.
my $nrpe = Nagios::Nrpe->new(); $nrpe->exit_unknown( 'I donno lol!' );
Returns: Exits with a nagios "unknown" exit code.
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.
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.
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.
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.
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.
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.
Usage: Inits the log4perl logger.
Returns: blessed ref
Returns: perl script template for new nagios nrpe check.
Report bugs & issues, please email the author.
Sarah Fuller, <sarah at averna.id.au>
<sarah at averna.id.au>
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.
To install Nagios::Nrpe, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Nagios::Nrpe
CPAN shell
perl -MCPAN -e shell install Nagios::Nrpe
For more information on module installation, please visit the detailed CPAN module installation guide.