Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Monitoring Tools»Nagios»How to Monitor Remote Linux System with Nagios via SSH

    How to Monitor Remote Linux System with Nagios via SSH

    By RahulFebruary 5, 20142 Mins ReadUpdated:September 21, 2019

    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.

    check-by-ssh-nagiosql3

    check_by_ssh monitoring nagios NRPE SSH
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    How to Install and Secure OpenSSH Server on Pop!_OS

    Bash Script to Monitor Disk Space and Notify

    Shell Script to Monitor Disk Space and Send Alert

    SSH Connection Refused (Problem & Solution)

    (Resolved) SSH Connection Refused on Ubuntu & Debian

    View 4 Comments

    4 Comments

    1. Sheen Ismhael Lim on August 10, 2017 9:14 am

      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?

      Reply
      • Rahul K. on August 11, 2017 4:19 am

        Try with sudo command or first switch to root user and then switch to nagios user.

        $ sudo su – nagios

        Reply
    2. Tamer on May 30, 2017 7:51 pm

      In case anyone else could not become the nagios user, I used this:
      su – nagios -s /bin/bash

      Reply
    3. Prashant Katti on February 23, 2017 3:42 pm

      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?

      Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Error: EACCES: permission denied, scandir (Resolved)
    • How To Install Python 3.11 on Ubuntu 22.04 / 20.04
    • How to Install Python 3.11 on Amazon Linux 2
    • An Introduction to the “./configure” Command: Compiling Source Code in Linux
    • How to Install PHP 8.x on Pop!_OS
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.