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/ and don't forget to make it executable with chmod +x



echo `date` $* >> $OUTPUT

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

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



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$/ $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 - "" 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

Keywords:plugin debugging development