Thursday 7 July 2011

Nagios


Nagios

Nagios is a monitoring tool, which is used for monitoring Hosts, Application and Services. In the event of a failure, Nagios can alert to technical staff of a problem.
Nagios-Plugins: Plugins are like a tools which are release time-to-time by Nagios team for bug fixes, services etc.
Nagios-nrpe: Nagios Remote Plugin Executer. The nrpe add-on plugin is designed to allow we to execute Nagios Plugin on remote Linux/Unix machine. The main reason for doing this is to allow Nagios to monitor “local resources” (like CPU load, Memory usage etc.) or remote machines.
It is possible to execute Nagios plugins on remote Linux/Unix machine through ssh. There is a check_by_ssh plugin that allows us.
The nrpe add-on consists of two pieces:
1.    The check_nrpe plugin, which resides on the local machines.
2.    The nrpe daemon, which runs on the remote Linux/Unix machine.
Configuration files in Nagios:
1.   nagios.cfg: This is the main Nagios configuration file. It contain global settings fir the packages. It defines directory locations of packages, various components, the users and group, content for the daemon, log file rotation settings, various time out and performance related settings.
2.   Object configuration files: This class of files specifies which hosts and services are monitored. In addition, they can be used to define host and service test commands, host group alert and their recipient’s event handlers.
3.   cgi.cfg: This file holds settings related to the Nagios displays, including paths to webpage items and scripts. It also defines allowed access to Nagios data and commands.
4.   resource.cfg: This file defines global macros that may be used within configuration file for clarity and security purpose. Such as to hide passwords from view in CGI program.


Installing Nagios:
Download the latest version of Nagios from http://www.nagios.org/download and extract is at /home directory or anywhere.
Requirements: httpd, php, gcc and gd packages.
            Create a group named as nagcmd and user named as nagios.
# groupadd nagcmd
# useradd –G nagcmd,apache nagios
# id nagios
# passwd nagios
# tar –zxvf nagios-version.tar.gz        (It will make a nagios-version folder)
# cd nagios-version
# ./configure - -with-command-group=nagcmd
# make all
# make install
# make install-init                                   (It install the init script in /etc/rc.d/init.d)
# make install-config                             (It install sample config files in /usr/local/Nagios/etc)
# make install-commandmode        (It install and configure permissions on the directory for holding the external command file)
            We can change the nagios admin email id line no. 35 in contacts.cfg file according to requirement.
# vi /usr/local/nagios/etc/objects/contacts.cfg
# make install-webconf                        (It install Nagios/Apache configuration file)
# htpasswd –c /usr/local/nagios/etc/htpasswd.users nagiosadmin
   passwd:********
# vi /etc/httpd/conf/httpd.conf
            Go to line no. 391 and add the “index.php”
Example:
DirectoryIndex index.html index.html.var index.php
# chkconfig - -level 35 httpd on
# service httpd restart
            Installing Nagios Plugins: Download the nagios-plugin from the same website and extract them also at /home directory and move in to the nagios-plugin-version directory.
            All Nagios plugins are resides in “/usr/local/nagios/libexec” directory. If any plugins are missing relatded to configured services then these service are show critical and status information display “plugin may be missing”.
# cd nagios-plugin-version
            To install these plugin you need to run these commands.
# ./configure - -with-nagios-user=nagios - -with-nagios-group=nagios
# make
# make install
            To compile the nagios run this command
# /usr/local/nagios/bin/nagios –v /usr/local/nagios/etc/nagios.cfg
# chkconfig - -level 35 nagios on
# usermod –d /usr/local/nagios nagios
# service nagios restart
            Check the nagios running process.
# ps –aux | grep nagios
# chcon –R –t httpd_sys_content_t /usr/local/nagios/sbin
# chcon –R –t httpd_sys_content_t /usr/local/nagios/share
            Login to the web interface. http://localhost/nagios
            Check for nagios log:
# tail –f /usr/local/nagios/var/nagios.log

          Add the services in nagios:
# vi /usr/local/nagios/etc/objects/commands.cfg
            Define command {
                        Command_name        check_oracle
                        Command_line            $USER$/check_oracle –tns XE
                        }
            :wq      Save and quit the file.
# vi /usr/local/nagios/etc/objects/localhost.cfg
            Define services {
                        use                                            local service
                        host_name                               localhost
                        service_description                oracle
                        check_command                    check_oracle
                        notification_enable                 0
                        }
            :wq      Save and quit the file.
            Compile the programme:
# /usr/local/nagios/bin/nagios –v /usr/local/nagios/etc/nagios.cfg
# service nagios restart
            If Oracle plugin is not available in “/usr/local/nagios/libexec” directory, this service is show critical. So download Oracle plugin (check_oracle) and put it in libexec directory.
            Now open the browser by 127.0.0.1/nagios. It will ask the username and password. You will see the newly added service.
            Note: If any one service plugins is not available (like bearerbox, kannel etc) then we can download a plugin which is check the service by process name. This type of plugin is a script which checks services by process name. So we can check almost services by these plugin. Require some changes in this plugin for check particular services.
            Check for plugin work properly:
# cd /usr/local/nagios/libexec
# ./check_oracle

            Install the NRPE plug-in for nagios
            Download and extract the nrpe-2.12.tar.gz file in /home directory.
# cd /nrpe-2.12
# ./configure
# make all
# make install-plugin
# make install-daemon
# make install-daemon-config
# make install-xinetd
            Now you will get the file “/usr/local/nagios/libexec/check_nrpe” plugin, and another setup files “/usr/local/nagios/etc/nrpe.cfg” & “/etc/xinetd.d/nrpe”

            Configure NRPE plug-in for nagios:
To configure nrpe we configure and install one PC as NRPE Server and other as NRPE Client.
                 NRPE Server                                             NRPE Client
1.    Nagios server                                            ----------------
2.    NRPE server                                            NRPE Client
3.    NRPE plugin                                             Nagios Plugin
First of all we configure nrpe server.
·         Install the Nagios above given steps.
·         Install NRPE server (nrpe plugin)above given steps.
When we install NRPE server it automatically installed nrpe plugins.
Now configure NRPE server.
# vi /usr/local/nagios/etc/object/command.cfg
            define command {
                        command_name       check_nrpe
                        command_line           $USER$/check_nrpe $client ip address$ $ARG1$
                        }
# vi /usr/local/nagios/etc/object/switch.cfg
            define host {
                        use                               generic-switch
                        host_name                 nrpe-client-host-name
                        alias                             any name
                        address                      nrpe-client-address
                        hostgroup                  hostgroup
                        }
            Now define host group in same file.
            define hostgroup {
                        hostgroup_name      hostgroup
                        alias                              any name
                        }
            Now define service for nrpe.
            define service {
                        use                                generic-service
                        host_name                  nrpe-client-host-name
                        check_command       check_nrpe!check_oracle
                        }
            Now configure nrpe client.
# vi /etc/xinetd.d/nrpe                                   (Go to line number 15, put the nrpe server IP)
# vi /usr/local/nagios/etc/nrpe.cfg             (Go to line number 79, put the nrpe server IP)
# vi /etc/services                                            (Add the nrpe port number)
            nrpe                 5666/tcp                      #nrpe
# service xinetd restart
# vi /usr/local/nagios/etc/nrpe.cfg
            Add the following line
            Check_command[check_oracle]=/usr/local/nagios/libexec/check_oracle - -tns XE
            :wq      Save and quite the file.
            Now open the website on nrpe server 127.0.0.1/nagios. It ask the username and password. Now new nrpe service is added.
            NRPE is completed.

            Check for Nagios is working correctly:
·         If the define service in nagios show OK and Green indication on the services, it means nagios working properly.
·         If it will show Critical and Red indication, it means service is down.
·         If it will show Unknown, It means nagios plugins not configured properly.

Change Update (Refresh rate) time: Open cgi.cfg file with vi editor which is located in “/usr/local/nagios/etc” directory. Go line number 275 and change the refresh rate. The refresh rate is in second.
# vi /usr/local/nagios/etc/cgi.cfg
            refresh_rate=2
            :wq


     Change Service check time: Open nagios.cfg file which is located in “/usr/local/nagios/etc” directory.
# vi /usr/local/nagios/etc/nagios.cfg
            589  auto_rescheduling_window=120   #180
            609 service_check_timeout=5   #60
            610 host_check_timeout=5   #30
            611 event_handler_timeout=5   #30
            612 notification_timeout=5   #30
            652 retention_update_interval=5   #60
            718 interval_length=5   #60
            1015 service_freshness_check_interval=5   #60
            1035 host_freshness_check_interval=5   #60
            1045 additional_freshness_latency=5   #15

1 comment:

Boot to UEFI Mode or legacy BIOS mode

Boot to UEFI Mode or legacy BIOS mode Choose UEFI or legacy BIOS modes while installing Windows. After Windows is installed, if you nee...