Monitoring Remote Linux System with Nagios via SSH

Monitoring Remote Linux System with Nagios via SSH

NRPE is the most popular method to monitor remote Linux systems using Nagios server. But in some cases we don’t want to install NRPE on remote system or we can’t install it. In that situation there are few alternate ways to monitor remote system. In this tutorial we are describing to check_by_ssh method.

Step 1: Setup Key Based SSH

Firstly its required to make sure that nagios server is able to connect client using ssh without prompting password. To do it create an ssh key pair on nagios server

# su - nagios
$ ssh-keygen

Copy public key remote hosts ~/.ssh/authorized_keys either manually or using following command

$ ssh-copy-id  ~/.ssh/id_rsa.pub remote.example.com

Step 2: Verify SSH Connection

Let’s check if you can ssh to remote machine without password

$ ssh remote.example.com

Also test to execute plugin on remote machine using check_by_ssh, make sure its not prompting for password

# cd /usr/lib64/nagios/plugins
# ./check_by_ssh -H remote.example.com -p 22 -C 'ls -l'

If above command executed successfully, You will see the list of remote system files.

Step 3: Configure Check in Nagios

As we have completed environment setup to check remote server by ssh. Lets add a check to our nagios server. Most of nagios admins prefers to use NagiosQL web interface to configure checks and some of admins use command line by directly edition files.

Add Check by Editing File:

Edit your service check configuration file in editor and add following content to run ls -l command on remote system. You can change this command with your preferred check command. If you used NagiosQL to manage your server, then do not edit files directly.

###############################################################################
#
# Service configuration file
#
###############################################################################

define service {
        #NAGIOSQL_CONFIG_NAME           MyRemoteServer
        host_name                       remote.example.com
        service_description             Check Any By SSH
        display_name                    Check Any By SSH
        check_command                   check_by_ssh!22!ls -l!nagios
        initial_state                   o
        max_check_attempts              5
        check_interval                  40
        retry_interval                  40
        active_checks_enabled           1
        check_period                    24x7
        event_handler                   notify-service-by-email
        notification_interval           60
        notification_period             24x7
        notifications_enabled           1
        contacts                        Admin,Support
        contact_groups                  Admin_Group
        register                        1
}

###############################################################################
#
# END OF FILE
#
###############################################################################

Add Check by NagiosQL:

Login to NagiosQL admin interface and add a new service, All the details will be similar to normal configuration except check command. Add check command option as below screenshot.

 
Enjoyed this video?
"No Thanks. Please Close This Box!"