Danijel Tašov


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'


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.


create( %ARGS )

If there is a key named

  • checkresults_dir, a Nagios::Passive::ResultPath

  • command_file, a Nagios::Passive::CommandFile

  • gearman, a Nagios::Passive::Gearman

object ist created.

If you're using checkresults_dir, you may also wan't to take a look at Nagios::Passive::BulkResult.

The gearman constructor also accepts a key for the optional shared secret.

Other required keys are host_name and 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 is replaced by check_name. MESSAGE is replaced by 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.

service_description is optional, if it's omitted the check result belongs to the host check of host_name.

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->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.

output STRING

Sets MESSAGE to STRING. If STRING is omitted, it returns the current value of output.

add_output STRING

Equivalent to:

  $nw->output($nw->output . STRING)

set_thresholds HASH

     warning => ':91',
     critical => ':97',

This creates a Monitoring::Plugin::Threshold object. It can be used to set the return_code with set_status.

set_status VALUE

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

add_perf HASH

This can be used to add performance data to the check result. Read Monitoring::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. (Well, that feature works for years now, so ....)


Development takes place on github:



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.