Monday, February 17, 2014

Installation of Nagios on CentOS

Installation of NAGIOS

Installation of perquisites:

 
Before Installing Nagios make sure that following are installed:


root@nagiospm# yum install httpd gcc glibc glibc-common gd gd-devel php

Apache needs to be started at system startup, start the apache.
root@nagiospm #chkconfig httpd on
root@nagiospm #service httpd start


Disable Se-Linux As shown below:
root@nagiospm #vi /etc/sysconfig/selinux
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#       enforcing - SELinux security policy is enforced.
#       permissive - SELinux prints warnings instead of enforcing.
#       disabled - SELinux is fully disabled.
SELINUX=disabled
# SELINUXTYPE= type of policy in use. Possible values are:
#       targeted - Only targeted network daemons are protected.
#       strict - Full SELinux protection.
SELINUXTYPE=targeted

# SETLOCALDEFS= Check local definition changes
SETLOCALDEFS=0

Now open up a browser and see if your web server is running: http://ipaddress. You should see the Apache 2test page. 


Install Nagios:
 
 [me@mymachine ~] yum install nagios nagios-plugins nagios-plugins-nrpe nagios-devel
It'll go ahead and pull down a few other packages for dependencies as well.
 

Configure the Nagios Apache file
ScriptAlias /nagios/cgi-bin "/usr/lib/nagios/cgi"
<Directory "/usr/lib/nagios/cgi">
#       SSLRequireSSL
        Options ExecCGI
        AllowOverride None
        Order allow,deny
        Allow from all
#       Order deny,allow
#       Deny from all
#       Allow from 127.0.0.1
        AuthName "Nagios Access"
        AuthType Basic
        AuthUserFile /etc/nagios/htpasswd.users
        Require valid-user
Alias /nagios "/usr/share/nagios"
<Directory "/usr/share/nagios">
#       SSLRequireSSL
        Options None
        AllowOverride None
        Order allow,deny
        Allow from all
#       Order deny,allow
#       Allow from 127.0.0.1
        AuthName "Nagios Access"
        AuthType Basic
        AuthUserFile /etc/nagios/htpasswd.users
        Require valid-user
</Directory>

Set up the password file:
[me@mymachine ~] htpasswd -c /etc/nagios/htpasswd.users nagiosadmin
New password: password123
Re-type new password: password123
Adding password for user nagiosadmin

Installation of Nagios is completed now we will configure Nagios.

   
Set up the CGI file
[me@mymachine ~] cd /etc/nagios
[me@mymachine nagios] vim cgi.cfg

# AUTHENTICATION USAGE
use_authentication=1

# SYSTEM/PROCESS INFORMATION ACCESS
authorized_for_system_information=nagiosadmin

# CONFIGURATION INFORMATION ACCESS
authorized_for_configuration_information=nagiosadmin

# SYSTEM/PROCESS COMMAND ACCESS
authorized_for_system_commands=nagiosadmin

# GLOBAL HOST/SERVICE VIEW ACCESS
authorized_for_all_services=nagiosadmin
authorized_for_all_hosts=nagiosadmin

# GLOBAL HOST/SERVICE COMMAND ACCESS
authorized_for_all_service_commands=nagiosadmin
authorized_for_all_host_commands=nagiosadmin


Setting up nagios.cfg

# You can specify individual object config files as shown below:
cfg_file=/etc/nagios/objects/commands.cfg
cfg_file=/etc/nagios/objects/contacts.cfg
cfg_file=/etc/nagios/objects/timeperiods.cfg
cfg_file=/etc/nagios/objects/templates.cfg
cfg_file=/etc/nagios/objects/device.cfg  
Now go to objects directory and create the above files.

Object configuration files
Time periods:
root@nagiospm # vim timeperiods.cfg

# '24x7' timeperiod definition
define timeperiod{
        timeperiod_name 24x7
        alias           24 Hours A Day, 7 Days A Week
        sunday          00:00-24:00
        monday          00:00-24:00
        tuesday         00:00-24:00
        wednesday       00:00-24:00
        thursday        00:00-24:00
        friday          00:00-24:00
        saturday        00:00-24:00
        }

# 'workhours' timeperiod definition
define timeperiod{
        timeperiod_name workhours
        alias           "Normal" Working Hours
        monday          08:00-17:00
        tuesday         08:00-17:00
        wednesday       08:00-17:00
        thursday        08:00-17:00
        friday          08:00-17:00
        }

# 'nonworkhours' timeperiod definition
define timeperiod{
        timeperiod_name nonworkhours
        alias           Non-Work Hours
        sunday          00:00-24:00
        monday          00:00-09:00,17:00-24:00
        tuesday         00:00-09:00,17:00-24:00
        wednesday       00:00-09:00,17:00-24:00
        thursday        00:00-09:00,17:00-24:00
        friday          00:00-09:00,17:00-24:00
        saturday        00:00-24:00
        }

# 'none' timeperiod definition
define timeperiod{
        timeperiod_name none
        alias           No Time Is A Good Time
        }

Create Contacts/Contacts groups:
 

root@nagiospm # vim contacts.cfg

# service_notification_options are w,u,c,r,f,n
# w=warning u=unknown c=critical r=recovery f=flapping n=none
# host_notification_options d,u,r,f,n
# d=down u=unreachable r=recovery f=flapping n=none

define contact{
        contact_name                    irfan
        alias                           irfans
        service_notification_period     24x7
        host_notification_period        24x7
        service_notification_options    c,r
        host_notification_options       d,r,u
        service_notification_commands   notify-by-email
        host_notification_commands      host-notify-by-email
        email                           irfans@passwordsys.com
        }

define contact{
        contact_name                    naresh
        alias                           nareshs
        service_notification_period     24x7
        host_notification_period        24x7
        service_notification_options    c,r
        host_notification_options       d,r
        service_notification_commands   notify-by-email
        host_notification_commands      host-notify-by-email
        email                           nareshs@passwordsys.com
        }

Contact groups:

root@nagiospm # vim contactgroups.cfg

# 'einsteins' contact group definitions
define contactgroup{
        contactgroup_name       admins
        alias                   admins1
        members                 irfan,naresh
        }           

Device configuration
:

All the CPE equipment is configured in the following file, Only first few lines are showed here Same thing repeats tp all of the devices

root@nagiospm # vim contactgroups.cfg
define host{
    name                        local
    use                         generic-host
    check_period                24x7
    check_interval               5
    retry_interval              1
    max_check_attempts          10
    check_command               check-host-alive
    notification_interval       60
    notification_options        d,u,r
    contact_groups              admins
    hostgroups                  locals
    register                    0
    }
define hostgroup{
    hostgroup_name    locals
    alias             local-devices
}

define host{
    use         local
    hostgroups  locals
    host_name   v237
    address     10.4.4.237
    statusmap_image BB.png
    2d_coords       971,1680
    parents         localhost
}


Starting Nagios:

 
Check the configuration for errors and make sure it starts at the system start up.
root@nagiospm # chkconfig nagios on
root@nagiospm # nagios -v /etc/nagios/nagios.cfg

Nagios 2.4`
Copyright (c) 1999-2006 Ethan Galstad (http://www.nagios.org)
Last Modified: 05-31-2006
License: GPL

Reading configuration data...

Running pre-flight check on configuration data...

Total Warnings: 0
Total Errors:   0

Things look okay - No serious problems were detected during the pre-flight check

[me@mymachine nagios] service nagios start

Starting network monitor: nagios
 

Nagios Screen Shots:
 


Access credentials:
http://serverip/nagios/
u:nagiosadmin   
p:password123
Naresh Sameneni