Nagios::Passive - submit passive check results to nagios
my $nw = Nagios::Passive->create( command_file => $command_file, service_description => $service_description, check_name => $check_name, host_name => $hostname, return_code => 0, # 1 2 3 output => 'looks (good|bad|horrible) | performancedata' ); $nw->submit;
This is the factory class, currently it creates either a Nagios::Passive::CommandFile or a Nagios::Passive::ResultPath object. Which object is created depends on the keys of the hash you supply to the the create method.
This method returns either a Nagios::Passive::CommandFile or a Nagios::Passive::ResultPath object.
If there is a key named
checkresults_dir, a Nagios::Passive::ResultPath
checkresults_dir
command_file, a Nagios::Passive::CommandFile
command_file
object ist created.
Other required keys are host_name and check_name.
host_name
check_name
host_name is the hostname for which you want to report a check result to nagios.
The typical output of a nagios plugin looks like this:
CHECK_NAME STATUS - MESSAGE
CHECK_NAME is replaced by check_name. MESSAGE is replaced by output.
output
STATUS can either be set by setting return_code to 0,1,2 or 3 (See nagios documentation for details) or by using the set_thresholds and set_status methods. return_code default's to 0 if not set somehow.
return_code
set_thresholds
set_status
service_description is optional, if it's omitted the check result belongs to the host check of host_name.
service_description
All of the attributes (except the required ones) can also be set afterwards, by calling the setter methods of the same name, i.e.:
$nw->return_code(0); $nw->output("everything ok"); # results to: CHECK_NAME OK - everything ok
On the object you gathered from the create method, you can perform the following operations.
create
Sets MESSAGE to STRING. If STRING is omitted, it returns the current value of output.
Equivalent to:
$nw->output($nw->output . STRING)
$nw->set_thresholds( warning => ':91', critical => ':97', );
This creates a Nagios::Plugin::Threshold object. It can be used to set the return_code with set_status.
Sets the return_code according the the threshold object created with set_thresholds and the given VALUE. For example:
$nw->set_thresholds(warning => ':4', critical => ':8'); $nw->set_status(6); $nw->output("6 is a warning"); # return_code is now 1, and the output shown in nagios will be # CHECK_NAME WARNING - 6 is a warning
This can be used to add performance data to the check result. Read Nagios::Plugin::Performance to get the idea of how to use this.
This writes the data out. In case of the CommandFile this will write the result into nagios' external_command_file. In case of ResultPath this will drop a file into nagios' check_result_path.
This module is in an early stage of development, the API is likely to brake in the future.
Nagios::Passive::ResultPath interacts with an undocumented feature of Nagios. This feature may disappear in the future.
Development takes place on github:
http://github.com/datamuc/Nagios-Passive
Danijel Tasov, <data@cpan.org>
Copyright (C) 2009, Danijel Tasov
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Nagios::Passive, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Nagios::Passive
CPAN shell
perl -MCPAN -e shell install Nagios::Passive
For more information on module installation, please visit the detailed CPAN module installation guide.