About Me

My photo
Kalyan Kumar Pasupuleti B-Tech(Information Technology). • RedHat Certified Engineer(RHCE) • Directory Services and Authentication Certificate of Expertise(LDAP) • Red Hat SELinux Policy Administration Certificate of Expertise(SELinux) • Network Services Security Certificate of Expertise (Network Services) • RedHat Certified Virtualization Administrator(RHCVA) • Red Hat Certified Security Specialist (RHCSS) Working as Cloud DevOps engineer

Sunday, March 3, 2013

How to Monitoring Linux/Unix Machines using Nagios

Install Nagios using URL: http://boosturfuture.blogspot.in/2013/02/installation-and-configuration-of.html

After installation follow below procedure:


First define the contacts in the file /usr/local//nagios/etc/objects/contacts.cfg


define contact{
        contact_name                    nagiosadmin
        use                                     generic-contact
        alias                                   Nagios Admin
        email                           <enter the notifying email ids separated by commas>
        }


define contactgroup{
        contactgroup_name       admins
        alias                               Nagios Administrators
        members                       nagiosadmin
        }

The notification will be sent to members mentioned in the nagiosadmin contacts.

 

There are 2 ways to define services:

1.    Service definition for local machine.

2.    Service definition for remote host

Service definition for local machine

Before proceeding first you need to define a hostgroup as shown below:

define hostgroup{
        hostgroup_name      groupname1
        members                  server1,server2
}

Now define a host:

define host {
               use                         generic-host
               host_name             server1                  ; IP address/hostname of the machine
               alias                       server1                  ; A longer name associated with the host
               address                  XX.XX.XX.XX        ; IP address of the host
               hostgroups             groupname1          ; Host groups this host is associated with
               }

 

Now it is the time for defining services to be monitored on the defined host:

Service definition for PING
define service{
        use                             generic-service,srv-pnp         ; Name of service template to use
        hostgroup_name        groupname1
        service_description    PING
        check_command        check_ping!100.0,20%!500.0,60%
        contact_groups           admins
        }

Service definition for website check

define service{
       use                              generic-service,srv-pnp
       host_name                  server1
       contact_groups           admins
       service_description     www.your website.com
       check_command         check_website! www.your website.com '
        }

Service definition for remote host
Before proceeding you need to install a NRPE plugin on the remote host.

NRPE is an addon that allows you to execute plugins on remote Linux/Unix hosts. This is useful if you need to monitor local resources/attributes like disk usage, CPU load, memory usage, etc. on a remote host. Similiar functionality can be accomplished by using the check_by_ssh plugin, although it can impose a higher CPU load on the monitoring machine - especially if you are monitoring hundreds or thousands of hosts.
Download the NRPE plugin on the Remote Host using below URL:

http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.13.tar.gz

Now extract the tar ball: tar xvfz nrpe-2.13.tar.gz

# cd nrpe-2.13
# ./configure
# make all
# make install-plugin
Now I want to check the remote machine disk space.
Remote Host Configuration after installing NRPE

1.    Define a NRPE command in the config file /usr/local/nagios/etc/nrpe.cfg as shown below:
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /

2.    Save and quit.



Configuration on the Nagios server


Now define the host and the service as shown below:


define Remote hostgroup{
        hostgroup_name      Remote Host Groupname1
        members                  Remote server1,Remote server2
}



define host {
               use                         generic-host
               host_name             Remote Host1       ; IP address/hostname of the machine
               alias                       Remote Host1       ; A longer name associated with the host
               address                  XX.XX.XX.XX        ; IP address of the host
               hostgroups             Remote Host Groupname1  ; Host groups this host is associated with
               }


define service{
        use                             generic-service,srv-pnp         ; Name of service template to use
        hostgroup_name        Remote Host Groupname1
        service_description    Disk Size-Root
        check_command        check_nrpe!check_disk!20%!10%!/
        contact_groups           admins
        }

The above service definition confirms that we are checking the desk space for the members of the Remote Host Groupname1 group.
You can also define the service for a individual hosts instead of using groups.

Now check for the configuration errors using below command
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
If there are no errors restart the Nagios service
# /etc/init.d/nagiosd restart

Now Login to the Web Interface using the below URL:

http://<nagios server IP>/Nagios

You'll be prompted for the username (nagiosadmin) and password you specified earlier.
Observe the defined hosts and services in the GUI.

No comments:

Post a Comment