Nagios is an amazing tool for monitoring and reporting and alerting of availability of hosts and services. I have typically only used simple SNMP checks or NRPE checks with a small agent installed on the remote host. I wanted to be able to measure a sites server room temperature via a USB probe that was on a remote box and installing NRPE or using SNMP was not an option. The only way to obtain the temperature was to run a command on the remote box. Thankfully Nagios has the inbuilt check_by_ssh command which allows nagios to connect up to a remote computer via ssh to then run the command. It does require SSH login via keys, thankfully this is also really easy to setup with ssh-keygen and ssh-copy-id.
It is important that these keys are generated as the user running nagios and a corresponding nagios user on the remote system.
On the Nagios server su into the running user for Nagios which will most likely be Nagios unless you have any customisations.
Run the command
This creates the public and private keys.
Copying the public key to the remote host is incredibly easy using ssh-copy-id
ssh-copy-id -i ~/.ssh/id_rsa.pub remote-host
ssh-copy-id appends the keys to the remote-host’s .ssh/authorized_key
Now simply test connecting via ssh by running the command
You should connect straight away without being prompted for any password. If this is the case you can now create a custom command and service in nagios to monitor the remote-host and obtain any values / information you require to monitor.