Minggu, 07 April 2019

Check CPU Nagios Using SNMP on Centos


SNMP stands for simple network management protocol. It is a way that servers can share information about their current state, and also a channel through which an administer can modify pre-defined values. While the protocol itself is very simple, the structure of programs that implement SNMP can be very complex.

If you still didn’t install Nagios Core , check the following articles. How to Install and Configure Nagios on CentOS

In this article we will show you how to install and configure SNMP in the remote server and how to add the host to Nagios Core.

Scenario

In this tutorial i am going to use two systems as mentioned below.

Nagios server (host):

Operating system : CentOS 6 minimal server
IP Address       : 192.168.1.150/24

Nagios client (remote):

Operating System : CentOS 6 minimal server
IP Address       : 192.168.1.152/24



Installing SNMP Agent on remote machine


  1. Install SNMP and SNMP Utilities

  2. yum -y install net-snmp net-snmp-utils

  3. Add a Basic Configuration

  4. mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.orig
    cp /dev/null /etc/snmp/snmpd.conf
    vim /etc/snmp/snmpd.conf

    Insert the following text into the new /etc/snmp/snmpd.conf

    # Map 'idv90we3rnov90wer' community to the 'ConfigUser'
    # Map '209ijvfwer0df92jd' community to the 'AllUser'
    #       sec.name        source          community
    com2sec ConfigUser      default         idv90we3rnov90wer
    com2sec AllUser         default         209ijvfwer0df92jd
    # Map 'ConfigUser' to 'ConfigGroup' for SNMP Version 2c
    # Map 'AllUser' to 'AllGroup' for SNMP Version 2c
    #                       sec.model       sec.name
    group   ConfigGroup     v2c             ConfigUser
    group   AllGroup        v2c             AllUser
    # Define 'SystemView', which includes everything under .1.3.6.1.2.1.1 (or .1.3.6.1.2.1.25.1)
    # Define 'AllView', which includes everything under .1
    #                       incl/excl       subtree
    view    SystemView      included        .1.3.6.1.2.1.1
    view    SystemView      included        .1.3.6.1.2.1.25.1.1
    view    AllView         included        .1
    # Give 'ConfigGroup' read access to objects in the view 'SystemView'
    # Give 'AllGroup' read access to objects in the view 'AllView'
    #                       context model   level   prefix  read            write   notify
    access  ConfigGroup     ""      any     noauth  exact   SystemView      none    none
    access  AllGroup        ""      any     noauth  exact   AllView         none    none

    Exit vim, and restart the SNMP service to reload the new configuration file:

    on Centos 6.x

    service snmpd restart

    on Centos 7.x

    systemctl restart snmpd

    Configure SNMP to start when the server boots:

    on Centos 6.x

    chkconfig snmpd on

    on Centos 7.x

    systemctl enable snmpd

  5. Test the SNMP Configuration

  6. from localhost on remote

    snmpwalk -v 2c -c 209ijvfwer0df92jd -O e 127.0.0.1

    from nagios host

    snmpwalk -v 2c -c 209ijvfwer0df92jd -O e 192.168.1.152


Configure Nagios To Monitor The Linux Host

  1. Install plugins check_cpu for snmp download from below

  2. https://exchange.nagios.org/directory/Plugins/Operating-Systems/Solaris/check_cpu/details

    Put check_cpu into your Nagios libexec directory
    (e.g. /usr/local/Nagios/libexec, or wherever Nagios is installed on your server)

    Create the symbolic links, being careful not to overwrite any files by the same name already there

    ln -s check_cpu check_load
    ln -s check_cpu check_ram
    ln -s check_cpu check_swap

    (these symlinks dictate how the script is run, as it can check CPU, RAM, load and swap, depending on how it is invoked)

  3. Insert the following text into /usr/local/nagios/etc/objects/commands.conf


  4. #snmp check_cpu

    define command{
    command_name check_cpu
    command_line $USER1$/check_cpu -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ -p $ARG3$
    }

    define command{
    command_name check_swap
    command_line $USER1$/check_swap -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ -p $ARG3$
    }

    define command{
    command_name check_ram
    command_line $USER1$/check_ram -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ -p $ARG3$ -o $ARG4$
    }

    define command{
    command_name check_load
    command_line $USER1$/check_load -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ -p $ARG3$
    }



  5. Insert the following text into /usr/local/nagios/etc/servers/hostname.cfg


  6. define host{

    use                             linux-server
    host_name                       hostname
    alias                           hostname
    address                         192.168.10.70
    max_check_attempts              5
    check_period                    24x7
    notification_interval           30
    notification_period             24x7

    }


    # Check CPU with check_cpu snmpd

    define service{
            use                             local-service         ; Name of service template to use
            host_name                       hostname
            service_description             Check CPU
            check_command                   check_cpu!70%!80%!209ijvfwer0df92jd
            }

    define service{
            use                             local-service         ; Name of service template to use
            host_name                       hostname
            service_description             Check Swap Memory
            check_command                   check_swap!70!90!209ijvfwer0df92jd
            }

    define service{
            use                             local-service         ; Name of service template to use
            host_name                       hostname
            service_description             Check Memory
            check_command                   check_ram!70!90!209ijvfwer0df92jd
            }

    define service{
            use                             local-service         ; Name of service template to use
            host_name                       hostname
            service_description             Check Load Average
            check_command                   check_load!60,70,80!70,80,90!209ijvfwer0df92jd
            }

  7. Restart Nagios

  8. Next, verify Nagios Configuration files for any errors.

    /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
    Total Warnings: 0
    Total Errors:   0

    Finally, restart Nagios.

    On Centos 6.x

    service nagios restart

    On Centos 7.x

    systemctl restart nagios

    Log into the web interface via : http://[SERVER_IP]/nagios , enter your login information and check for new Linux hosts added in nagios core service.
    That’s all.

    Congratulations! Enjoy your Monitoring platform Nagios Core.


Tidak ada komentar: