Utility to debug Nagios plugins




Über mich

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:

  • status.cgi returns "return code 129 out of bounds - plugin maybe missing" (or any other code)
  • status.cgi returns "no output"
  • debugging plugins to log the returned data while still delivering it to Nagios

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:

-rwx------ 1 root root 63 Mar 24 09:01 demo_no_access.pl

This results in a crital state because the nagios service user can not access the file owned by root. screenshot

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' '']
output=[sh: /usr/local/bin/demo_no_access.pl: Permission denied

(c) Wolfgang Wagner, Vienna, 2007,2008