Nagios Tips

Nagios is one of the tools we use to monitor websites and services.
Here are a few tips that we have found useful when working with it:

1. Sometimes, when adding a new check, that check fails because of mis-configuration. An easy way to begin debugging it is to modify the check command so that it logs the command to a file rather than running the check.

Example.
/etc/nagios/checkcommands.cfg contains:
  
define command {   
  command_name check_ftp_file_transfer
  command_line $USER5$/check_ftp.pl -H $ARG1$ \
    -u $ARG2$ -p $ARG3$ -f $ARG4$
}


It can be changed to:
define command {   
  command_name check_ftp_file_transfer
  command_line /bin/echo $USER5$/check_ftp.pl \
     -H $ARG1$ -u $ARG2$ \
     -p $ARG3$ -f $ARG4$ >> /tmp/nagios.log   
}

then nagios can be instructed to force a check of the service. Rather than actually check the service, it will write to the /tmp/nagios.log the command that it normally would have executed to perform the check, for example:
  /path/to/nagios/plugins/check_ftp.pl \
     -H ftp.some.domain -u someuser \
     -p password -f some_file 

That command can then be run directly from the command line to see what error is returned. This approach is also useful when debugging checks that use check_by_ssh or nrpe to test local services on remote computers.

2. The standard check_ftp plugin doesn't provide a way to test user logins or file transfers, but a user-contributed perl script at NagiosExchange does, using the Net::FTP module available on CPAN - see check_ftp.pl