Page 1 of 1

Re: [Nagios-devel] Nagios::Cmd perl module

Posted: Mon Sep 22, 2003 8:28 am
by Guest
--=-97yPWPSqqpMNHA3aDe/M
Content-Type: text/plain; charset=iso-8859-13
Content-Transfer-Encoding: quoted-printable

I fixed some stuff in the module and actually tested it this time before
sending it out.

You can now pass your named arguments without {} brackets. It also
doesn't attempt to set defaults for anything. It's all documented in
the POD.

Nagios::Cmd(3) User Contributed Perl Documentation Nagios::Cmd=
(3)

NAME
Nagios::Cmd

DESCRIPTION
Nagios::Cmd is a module to take care of the logistics involved in su=
b-
mitting a command to Nagios=FFs command pipe. flock(2) is used to i=
nsure
that parallel calls to this module don=FFt corrupt each other (unlik=
ely
in any case).

To turn on this module=FFs debugging, set it=FFs $debug directly bef=
ore
calling any methods:
$Nagios::Cmd::debug =3D 1;

To get a list of valid commands and their arguments, run the followi=
ng
command:
perl -MNagios::Cmd -e =FFNagios::Cmd::Help=FF
perl -MNagios::Cmd -e =FFNagios::Cmd::Help(ADD_HOST_COMMENT)=FF

You might need to specify an include path for Nagios::Cmd since it m=
ost
likely won=FFt be in your standard perl include directories:
perl -I/opt/nagios/libexec -MNagios::Cmd -e =FFNagios::Cmd::Help=FF

Examples:

use lib =FF/opt/nagios/libexec=FF;
use Nagios::Cmd;
my $cmd =3D Nagios::Cmd->new( "/var/opt/nagios/rw/nagios.cmd" );
my $cmd_args =3D {
host =3D> $host,
persistent =3D> 1,
author =3D> "Al Tobey",
comment =3D> "This host is very stable."
};
$cmd->ADD_HOST_COMMENT( $cmd_args );

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

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

# -- OR --

use lib =FF/opt/nagios/libexec=FF;
use Nagios::Cmd =FFnagios_cmd=FF;
my $time =3D CORE::time(); # use CORE:: if you have Time::HiRes ove=
rriding time()

# submit a custom command to the pipe
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 subm=
it-
ting all kinds of noise to Nagios, set $Nagios::Cmd::debug =3D 1, which will
allow the command file to be a regular file instead of a pipe. You can al=
so
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()
By default, this subroutine is NOT exported. See the example above if you
don=FFt already know how to get it. Use this command if you need to use a =
com-
mand 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.

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

LICENSE
GPL

AUTHOR
Albert P Tobey

perl v5.8.1 2003-09-22 Nagios::Cmd=
(3)


On Fri, 2003-09-19 at 17:18, Al Tobey wrote:
> For submission under the GPL, a quick module I threw together for
> submitting commands to the Nagios command pipe.





--=-97yPWPSqqpMNHA3aDe/M
Content-Disposition: attachment; filename=Cmd.pm
Content-Type: text/plain; name=Cmd.pm; charset=iso-8859-1
Content-Transfer-Encoding: 7bit

###########################################################################
# #
# Nagios::Cmd #
# Written by Albert Tobey #
# Copyright 2003, Albert P Tobey #
# #
# This program is free software; you can redistribute it and/or modify it #
# under the terms of the GNU General Public License as published by the #
# Free Software Foundation; either version 2, or (at your op

...[email truncated]...


This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]