Nagios::NRPE::Daemon - A Nagios NRPE Daemon
use Nagios::NRPE::Daemon; use IPC::Cmd qw(can_run run run_forked); # create the commandlist we accept my $commandlist = }; my $callback = sub { my ($self,$check,@options) = @_; my $commandlist = $self->commandlist(); if ($commandlist->{$check}) { my $args = $commandlist->{$check}->{args}; my $i = 0; foreach (@options) { $i++; $args =~ "s/\$ARG$i\$/$_/"; } my $buffer; if (scalar run(command => $commandlist->{$check}->{bin} . " " . $args, verbose => 0, buffer => \$buffer, timeout => 20)) { return $buffer; } } }; my $daemon = Nagios::NRPE::Daemon->new( listen => "127.0.0.1", port => "5666", pid_dir => '/var/run', ssl => 0, commandlist => { "check_cpu" => { bin => "/usr/lib/nagios/plugin/check_cpu", args => "-w 50 -c 80" } }, callback => $callback ); =head1 DESCRIPTION
A simple daemon implementation with the capabillity to add your own callbacks and hooks in case you want to build your own NRPE Server.
This software is copyright (c) 2013 by Andreas Marschke <andreas.marschke@googlemail.com>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
Takes the following options as a hashref:
Listen on this IP Address
Port to listen on
The pidfile for this daemon
Use ssl (1|0)
A hashref of the allowed commands on the daemon
A sub executed everytime a check should be run. Giving the daemon full control what should happen.
my $callback = sub { my ($self,$check,@options) = @_; my $commandlist = $self->commandlist(); if ($commandlist->{$check}) { my $args = $commandlist->{$check}->{args}; my $i = 0; foreach (@options) { $i++; $args =~ "s/\$ARG$i\$/$_/"; } my $buffer; if (scalar run(command => $commandlist->{$check}->{bin} . " " . $args, verbose => 0, buffer => \$buffer, timeout => 20)) { return $buffer; } } };
Starts the server and enters the Loop listening for packets
A hashref of elements that are valid commands. An example for it is:
"check_cpu" => { bin => "/usr/lib/nagios/plugin/check_cpu", args => "-w 50 -c 80" }
args can contain $ARG1$ elements like normal nrpe.cfg command elements.
args
A shorthand function returning either an encrypted or unencrypted socket depending on wether ssl is set to 1 or 0.
6 POD Errors
The following errors were encountered while parsing the POD:
Expected text after =item, not a bullet
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.