View FAQ

[ Return To FAQ Index | Search The FAQs ]


FAQ Database : Plugins : Developer Information

Title:Plugin Debugging - Improved
FAQ ID:F0379
Submitted By:Alex Edwards 
Last Updated:03/27/2007

Description:Debugging Nagios plugins is difficult from within the Nagios environment. Only the first line of output is logged, and command line arguments are not logged. 

Solution:Use the following code as a 'proxy' check command called, say, ./libexec/check_debug.sh and don't forget to make it executable with chmod +x
--------------------------------------------------

#!/bin/bash

OUTPUT=/tmp/nagios_debug.log

echo `date` $* >> $OUTPUT

# Command should be first argument
RESULT=`$* 2>&1`
EXITCODE=$?

(
echo $RESULT
echo "Exit code: $EXITCODE"
) | tee -a $OUTPUT

exit $EXITCODE


--------------------------------------------------

You can then modify your EXISTING check_command definition, by prepending the name of the debug check_command as follows.

define command{
        command_name    check-host-alive
        command_line    $USER1$/check_debug.sh $USER1$/check_ping -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 1
        }

Output will be comprehensively logged to /tmp/nagios_debug.log

When everything is working ok, revert back to the plain command definition.

Supplied by Alex Edwards.

Wolfgang Wagner mentioned another solution for debugging plugins - "capture_plugin.pl" captures STDOUT and STDERR of a nagios plugin. It writes the captured output to a temp. file. Then the output and return code is returned to Nagios for further processing.

The source of the perl script can be downloaded at http://www.waggy.at/nagios/capture_plugin.htm


Keywords:plugin debugging development