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::Cmd

DESCRIPTION

Nagios::Cmd is a module to take care of the logistics involved in submitting a command to Nagios's command pipe. flock(2) is used to insure that parallel calls to this module don't corrupt each other (unlikely in any case).

To turn on this module's debugging, set it's $debug directly before calling any methods: $Nagios::Cmd::debug = 1;

To get a list of valid commands and their arguments, run the following command: perl -MNagios::Cmd -e 'Nagios::Cmd::Help' perl -MNagios::Cmd -e 'Nagios::Cmd::Help(ADD_HOST_COMMENT)'

You might need to specify an include path for Nagios::Cmd since it most likely won't be in your standard perl include directories: perl -I/opt/nagios/libexec -MNagios::Cmd -e 'Nagios::Cmd::Help'

Examples:

 use lib '/opt/nagios/libexec';
 use Nagios::Cmd;
 my $cmd = Nagios::Cmd->new( "/var/opt/nagios/rw/nagios.cmd" );

 my $cmd_args = {
    host => $host,
    persistent => 1,
    author => "Al Tobey",
    comment => "This host is very stable."
 };
 $cmd->ADD_HOST_COMMENT( $cmd_args );

 $cmd->ADD_HOST_COMMENT(
    host => $host,
    persistent => 1,
    author => "Al Tobey",
    comment => "This host is very stable."
 );

 $cmd->ADD_HOST_COMMENT( $host, 1, "Al Tobey", "This host is very stable." );

 # -- OR --

 use lib '/opt/nagios/libexec';
 use Nagios::Cmd;
 my $time = CORE::time(); # use CORE:: if you have Time::HiRes overriding time()

 # submit a custom command to the pipe
 $cmd->nagios_cmd( "[$time] DEL_ALL_HOST_COMMENTS;localhost" );

PUBLIC METHODS

new()

Initiate a Nagios::Cmd object. It takes ony one argument, the full path to the nagios command file. If you want to test this module out, without submitting all kinds of noise to Nagios, set $Nagios::Cmd::debug = 1, which will allow the command file to be a regular file instead of a pipe. You can also create a test command file with the mknod(1) command.

 mknod -m 600 /var/tmp/nagios_cmd p

The cat(1) command works well as a reader on a fifo.

nagios_cmd()

Use this method if you need to use a command that is not defined in this module. Adding commands to this module is pretty trivial, so you may want to look at the %commands hash at the top of the Cmd.pm file.

 $cmd->nagios_cmd( "[".time()."] " . join(";", $COMMAND_NAME, @ARGS) );
 $cmd->nagios_cmd( "[1063919882] DISABLE_HOST_SVC_NOTIFICATIONS;localhost" );

LICENSE

GPL

AUTHOR

Albert P Tobey <albert.tobey@priority-health.com>

1 POD Error

The following errors were encountered while parsing the POD:

Around line 243:

You forgot a '=back' before '=head1'