capture_plugin.pl
2008-09-09capture_plugin.pl - What it does
This little perl-scripts captures STDOUT and STDERR of a nagios plugin. It writes the captured output to a temp. file.
Then the output is returned to Nagios for further processing.
This allows to track down some problems when using plugins within Nagios. You'll get some information if you have
problems accessing files, can view the expanded command-line parameters of service checks, view the performance data returned
in a text file, etc.
It did help me several times - so feel free to try this out.
When to use it?
Examples of possible area of application in case of:
How to get it?
Here you can get the script capture_plugin.pl.
How to use
Assume Nagios is running under a special user "nagios" and it is defined a service check plugin (name: capture-invalid)
define command{
command_name check_wsc_capture
command_line /usr/local/bin/demo_no_access.pl -H $HOSTADDRESS$
}
having the following rights:
This results in a crital state because the nagios service user can not access the file owned by root.

Now use the perl script as plugin like this
define command{
command_name check_wsc_capture
command_line /home/ww/capture_plugin.pl /usr/local/bin/demo_no_access.pl -H $HOSTADDRESS$
}
After the next check you can have a look in "/tmp/captured-plugins.log" for the output of the plugin. You will see that the real reason (access denied) is logged.
------- 2007-2-24 9:6:28 ------ debugging cmd=[/usr/local/bin/demo_no_access.pl '-H' '127.0.0.1'] output=[sh: /usr/local/bin/demo_no_access.pl: Permission denied ] retcode=126
(c) Wolfgang Wagner, Vienna, 2007,2008