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 the remote system or we can’t install it. In that situation, there are few alternate ways to monitor a remote system. In this tutorial we are describing to check_by_ssh method.

Advertisement

nagios-with-ssh

Step 1 – Setup Key Based SSH

Firstly it’s required to make sure that the Nagios server is able to connect the 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 the 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 the remote machine without password

ssh remote.example.com

Also test to execute plugin on the remote machine using check_by_ssh, make sure it’s not prompting for password

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

If the 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. Let’s add a check to our Nagios server. Most of Nagios admins prefer to use NagiosQL web interface to configure checks and some of the admins use command line by directly edition files.

Add Check by Editing File:

Edit your service check configuration file in the editor and add the following content to run ls -l command on a 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.

Share.

4 Comments

  1. Sheen Ismhael Lim on

    Hi Raul,

    I am trying to setup check_by_ssh, however when I issue “su – nagios” the computer is asking for a password. I don’t remember the nagios setup asking for the password for a nagios user, only for the nagiosadmin.

    I only keep one password to all my account in my test environment and it does not work. Any ideas?

  2. Prashant Katti on

    Hi Rahul..

    We are exactly looking for same setup. Could you please let me know the path for service check configuration file and also once configuration file is created how we can make execute this file from linux and check the conditions on Nagios core GUI.

    Also is NagiosQL admin is a separate installable?

Exit mobile version