Nagios Monitoring over SSH

2018, Jul 28

Nagios can monitor remote servers via NRPE or SSH. If your communication between servers is limited, and only SSH and few other ports are open, you can make a command in Nagios that connect over SSH and check the server with local nagios plugins.

You need to install Nagios Core on management host, and nagios plugins on the monitored server.

On Nagios Core:

  • Define this in commands.cfg (/usr/local/nagios/etc/objects/commands.cfg):
# 'check_with_ssh' command definition
define command {
    command_name                     check_with_ssh
    command_line                     $USER1$/check_by_ssh -H $HOSTADDRESS$ -C $ARG1$
  • For every check command, you will use a combination of checkwithssh command (just created) and a local plugin on the remote server (checkjmx/ checkhttp/ check_disk/ etc.
  • Example of defined service:
define service {
    use                              generic-service
    host_name                        my-server
    service_description              Current Load
    check_command                    check_with_ssh!"/usr/local/nagios/libexec/check_load -w 2.0,2.0,2.0 -c 4.0,4.0,4.0"
  • As you can see, you’re using a local nagios plugin, that is on the remote server.
  • Create a SSH key pair for nagios user.

On the server you’re monitoring:

  • Create user nagios.
  • Place the public key of management server in authorized_keys on the server you’re monitoring.
  • Download and install Nagios plugins
curl -L -O
tar xvf nagios-plugins-*.tar.gz
cd nagios-plugins-*
./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl
make install