Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Monitoring Tools»How to Monitor Remote Linux System with Nagios via SSH

    How to Monitor Remote Linux System with Nagios via SSH

    RahulBy 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.

    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
    Previous ArticleHow to Get Default Windows Password in AWS Instance
    Next Article How to Extract Certificate and Private Key from PFX File

    Related Posts

    (Resolved) userauth_pubkey: key type ssh-rsa not in PubkeyAcceptedAlgorithms

    Updated:May 10, 20221 Min Read

    Adding a New SSH Key in GitHub

    Updated:April 1, 20223 Mins Read

    How to Create SFTP Only User in Debian 11

    Updated:September 26, 20214 Mins Read

    How to Disable Strict Host Key Checking in SSH

    Updated:September 25, 20212 Mins Read

    How To Set Up SSH Keys in Linux

    5 Mins Read

    How To Set Up SSH Tunneling

    5 Mins Read

    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

    Recent Posts
    • How to Enable / disable Firewall in Windows
    • How to Install JAVA on Ubuntu 22.04
    • Switching Display Manager in Ubuntu – GDM, LightDM & SDDM
    • Changing the Login Screen Background in Ubuntu 22.04 & 20.04
    • How To Install PHP (8.1, 7.4 or 5.6) on Ubuntu 22.04
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

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