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::Nrpe - Small framework for creating and using custom 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.001

SYNOPSIS

    # Example check script for yum package updates.
    use Nagios::Nrpe;

    my $nrpe = Nagios::Nrpe->new( verbose => 0, log => 0, );

    $nrpe->info('Starting yum update notify check.');

    open ( my $fh, '-|', '/usr/bin/yum check-update' ) || $nrpe->error('yum failed');

        my $yum_info = { verbose => do { local $/; <$fh> } };

    close ( $fh );

    $nrpe->info('YUM: ' . $yum_info);

    my $exit_code = ( $? >> 8 );

    $nrpe->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');

OPTIONS

verbose

    my $nrpe = Nagios::Nrpe->new( verbose => 1 );

When enabled all info & debug messages will print to stdout. If log is also turned on, will log syslog. Disabled by default.

log

    my $nrpe = Nagios::Nrpe->new( log => 1 );

When enabled all info & debug messages 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

check_path

    my $nrpe = Nagios::Nrpe->new( check_path => '/tmp' );

Used for check script generation. See nagios_nrpe.pl

config_file

    my $nrpe = Nagios::Nrpe->new( check_path => '/var/tmp/config.yaml' );

Loads yaml config file. Default loads internal module config file.

SUBROUTINES/METHODS

exit_ok

    my $nrpe = Nagios::Nrpe->new();
    $nrpe->exit_ok( 'Looks good', 'stat1=123;stat2=321;' );

Usage: Pass human readable message and then (optionally) nagios stats. 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_ok( 'Looks interesting', 'stat1=123;stat2=321;' );

Usage: Pass human readable message and then (optionally) nagios stats. 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_ok( 'oh god, oh god, we're all going to die', 'stat1=123;stat2=321;' );

Usage: Pass human readable message and then (optionally) nagios stats. 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_critical( 'I donno lol!' );

Usage: Pass human readable message and then (optionally) nagios stats. This call will exit the program with the desired exit code.

Returns: Exits with a nagios "unknown" exit code.

_exit

    INTERNAL USE ONLY.

Usage: Creates a valid exit state for a NAGIOS NRPE check.

Returns: exits program. Do not pass go, do not collect $200.

_load_config

    INTERNAL USE ONLY.

Usage: Loads the yaml config file.

Returns: hashref

_load_logger

    INTERNAL USE ONLY.

Usage: Inits the log4perl logger.

Returns: blessed ref

error

    my $nrpe = Nagios::Nrpe->new();
    $nrpe->error( 'Not working, oh noes!' );

Usage: Error messaging. If verbose is on will print to stdout. If log is on will log to syslog. Please note, an error message call will cause the program to exit with a critical nagios exit code.

Returns: exits program.

info

    my $nrpe = Nagios::Nrpe->new();
    $nrpe->info( 'Insert info message here.' );

Usage: Info messaging. If verbose is on will print to stdout. If log is on will log to syslog.

Returns: Nothing;

debug

    my $nrpe = Nagios::Nrpe->new();
    $nrpe->debug( 'Insert debug message here.' );

Usage: Debug messaging. If verbose is on will print to stdout. If log is on will log to syslog.

Returns: Nothing;

generate_check

    my $nrpe    = Nagios::Nrpe->new(  check_name => foo,
                                      check_path => '/tmp',
                                      verbose    => 1,
                                   );
    
    my $check_path = $nrpe->generate_check;

Usage: Generates a new NAGIOS NRPE check.

Returns: Path to newly created file.

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.