Wolfgang Wagner has written this really good how-to about debugging Nagios plugins. It can be a pain to find out when you add or write a new check. The solution is to let a script (capture.pl) that takes care of redirecting STDOUT and STDERR to a logfile make the call.
So this is how the check I wanted to debug was looking like:
# 'check_alive_by_ssh_login' command definition
define command{
command_name check_alive_by_ssh_login
command_line $USER1$/capture_plugin.pl /usr/bin/ssh -q -p $ARG1$ $HOSTADDRESS$
}
And the output looked like this:
2009-7-24 11:14:4 ------ debugging cmd=[/usr/bin/ssh '-q' '-p' '220' 'xxx.xxx.xxx.xxx'] output=[Permission denied, please try again. Permission denied (publickey,password,keyboard-interactive). ]
… meaning basically there was something wrong with the ssh public key for that host. This tool has already saved me hours of testing so I'm happy to link it.