Tuesday, 8 March 2016

Add Linux Host In Nagios


SERVER SIDE CONFIGURATION:


01. Go to config file location.

]# cd /usr/local/nagios/etc/servers


02. Create a new file and paste contents of sample file (sample file is attached with this folder). Now, comment or remove services that you don't need.

]# vim something-hostname.cfg


03. Add this host to hostgroup.

]# vim hostgroup.cfg


define host{
        use                     linux-server
        host_name               MOMS-WEB2-54.169.82.120
        alias                   MOMS-WEB2-54.169.82.120
        address                 54.169.82.120
        contact_groups          awsmoms,admins
        }

define service{
        use                     generic-service
        host_name               MOMS-WEB2-54.169.82.120
        service_description    PING
    check_command        check_ping!1000.0,40%!3000.0,80%
        contact_groups          awsmoms,admins
        }

define service{
        use                             generic-service
        host_name                       MOMS-WEB2-54.169.82.120
        service_description             MEMORY
        check_command                   check_nrpe!check_mem
        contact_groups              awsmoms,admins
        }

define service{
        use                             generic-service
        host_name                       MOMS-WEB2-54.169.82.120
        service_description             CPU
        check_command                   check_nrpe!check_cpu_perf
        contact_groups              awsmoms,admins
       }

define service{
        use                             generic-service
        host_name                       MOMS-WEB2-54.169.82.120
        normal_check_interval           30
        service_description             CPU Load
        check_command                   check_nrpe!check_load
        contact_groups              awsmoms,admins
        }

define service{
        use                             generic-service
        host_name                       MOMS-WEB2-54.169.82.120
        normal_check_interval           30
        service_description             PROCESSES
        check_command                   check_nrpe!check_total_procs
        contact_groups              awsmoms,admins
        }

define service{
        use                             generic-service
        host_name                       MOMS-WEB2-54.169.82.120
        service_description             PROCESS-Z
        check_command                   check_nrpe!check_zombie_procs
        contact_groups              awsmoms,admins
        }

define service{
        use                             generic-service
        host_name                       MOMS-WEB2-54.169.82.120
        normal_check_interval           30
        service_description             DISK
        check_command                   check_nrpe!check_disk
        contact_groups              awsmoms,admins
        }

define service{
        use                             generic-service
        host_name                       MOMS-WEB2-54.169.82.120
        normal_check_interval           30
        service_description             USERS
        check_command                   check_nrpe!check_users
        contact_groups              awsmoms,admins
        }

define service{
        use                             generic-service
        host_name                       MOMS-WEB2-54.169.82.120
        service_description             Uptime
        check_command                   check_nrpe!check_uptime
        contact_groups              awsmoms,admins
        }

define service{
        use                             generic-service
        host_name                       MOMS-WEB2-54.169.82.120
        service_description             HTTP
        check_command                   check_tcp!80
        contact_groups              awsmoms,admins
        }

define service{
        use                             generic-service
        host_name                       MOMS-WEB2-54.169.82.120
        service_description             MYSQL
        check_command                   check_tcp!3306
        contact_groups              awsmoms,admins
        }

:wq


4. Reload configuration.


]# service nagios reload




CLIENT SIDE CONFIGURATION (login as root user):


00. Install required packages.
]# yum install openssl-devel gcc xinetd make glibc


01. Create a directory to download rpm packages.
]# mkdir ~/downloads

 
02. Go to download folder.
]# cd ~/downloads


03. Download NRPE.


04. Download Nagios Plugins.


05. Extract Nagios Plugins.
]# tar -xzf nagios-plugins-2.0.3.tar.gz


06. Go to extracted folder.


]# cd nagios-plugins-2.0.3

# useradd nagios

07. Configure plugins.
]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios


08. Compile it.
]# make && make install


09. Change ownership of nagios plugins folder.
]# chown -R nagios:nagios /usr/local/nagios/libexec


10. Now again go to downloads folder.
]# cd ~/downloads


11. Extract NRPE.
]# tar -xzf nrpe-2.14.tar.gz


12. Go to NRPE extracted folder.
]# cd nrpe-2.14


13. Configure it.
]# ./configure


14. Compile it.
]# make all


15. Install plugin configuration.
]# make install-plugin


16. Install NRPE service.
]# make install-daemon


17. Install NRPE service configuration files.
]# make install-daemon-config


18. Install xinetd service. Because NRPE runs behind xinetd service.
]# make install-xinetd


19. Edit the services file, and add below line at end of file.
]# vim /etc/services


nrpe 5666/tcp # NRPE

:wq


20. Open the file and add ip of nagios server.
]# vim /etc/xinetd.d/nrpe


only_from = 127.0.0.1 54.169.60.32  <-- nagios ip

:wq



21. Start xinetd service.
]# service xinetd start


22. Make NRPE service live after server reboot.
]# chkconfig xinetd on


Note, now open port 5666 on client machine for nagios server.



Note, 'check_mem' and 'check_cpu_perf' plugins are not installed by default. You need to download from nagios website (OR we have already downloaded in folder with this notes) and copy under "/usr/local/nagios/libexec" folder. After copy, set full permissions on it. You may set full permissions with command,



23. Change the ownership/permissions of newly uploaded plugins.
]# chmod -R 777 /usr/local/nagios/libexec/* ; chown -R nagios:nagios /usr/local/nagios/libexec/*


24. Now go to NRPE configuration directory.
]# cd /usr/local/nagios/etc/


25. Open NRPE configuration file.
]# vim nrpe.cfg



command[check_users]=/usr/local/nagios/libexec/check_users -w 4 -c 5
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 16% -c 15%
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 140 -c 150
command[check_mem]=/usr/local/nagios/libexec/check_mem -w 65,24 -c 75,25
command[check_cpu_perf]=/usr/local/nagios/libexec/check_cpu_perf
command[check_uptime]=/usr/local/nagios/libexec/check_uptime


:wq


NOTE : Above you can set % for alert.


26. Restart xinetd restart.
]# service xinetd restart


No comments: