Nagios::Cmd
A module for reading a fifo or regular file similar to the way Nagios does.
use Nagios::Cmd; use Nagios::Cmd::Read; use POSIX qw/mkfifo/; my $fifo = '/var/tmp/test.pipe'; mkfifo( $fifo, 600 ); my $writer = Nagios::Cmd->new( $fifo ); my $reader = Nagios::Cmd::Read->new( $fifo ); $writer->service_check('SSH', 'localhost', 0, 'version 1 waiting'); print $reader->readcmd(), " was written to $fifo\n";
Pass in the name of a fifo to open and read from. The fifo must already exist.
my $reader = Nagios::Cmd::Read->new( $fifo );
Same as new, but can be any type of file such as regular files or /dev/null.
my $reader = Nagios::Cmd::Read->new_anyfile( '/tmp/commands.txt' );
Read a single command. Just like in Nagios, the filehandle is kept open for the duration of the program. If the target file is a regular file, sysseek() will be used to rewind to the top of the file (which may not be what you want).
To turn of seeking for regular files, call $object->seek(undef);.
Turn seek on/off. Default is off.
$reader->seek(undef); # turn off seeking $reader->seek(1); # turn it back on Nagios::Cmd::Read::seek(undef);
Turn use of flock() on/off. Setting it to a defined value will enable flock()ing of filehandles before reading. Setting to undef turns it off.
$reader->lock(1); # turn on use of flock() around reads $reader->lock(undef); # turn it off Nagios::Cmd::Read::lock(1);
Al Tobey <tobeya@cpan.org>
To install Nagios::Cmd, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Nagios::Cmd
CPAN shell
perl -MCPAN -e shell install Nagios::Cmd
For more information on module installation, please visit the detailed CPAN module installation guide.