Friday, October 5, 2012

How to Install and configure NAGIOS for monitoring CISCO device on FEDORA


Nagios
Nagios is an open source free monitoring tool which is widely used by people to monitor their infrastructure devices and to create reports on the availability of the services. This tool has the capability to alert the status of services or devices in realtime, based on your configuration on to a web based dashboard, email, sms etc………
Ethan Galstad created this wonderful monitoring tool and is currently supported by him and a group of developers actively maintaining the plugins for it which are official and unofficial. It is licensed under GNU version 2.
Nagios has got the ability to monitor services, hosts and anything else which have the ability to send collected data via a network to specifically written plugins.  Nagios collects information with the help of SNMP and agents installed on the remote systems.
I am trying to explain over here the installation of Nagios on a Linux system running Fedora and the configuration required on it to make the application useful for monitoring your network devices like Routers, switches, firewalls, loadbalancers and services like (SMTP, POP3, HTTP, NNTP, ICMP, SNMP, FTP, SSH) with the usage of different plugins available at sites given below.

Download Sites:
Nagios Core:
Addons: (clients)
http://www.nagios.org/download/addons/
Plugins:
 or Nagios Exchange
Frontends: (GUI)


Prerequisites
Run all steps from this document with root permissions. The following command can be run to switch to a root shell.

>su – root
***  This will prompt for root user password. After entering the same the prompt will change to root.
#
Issue the command “pwd” to check the present directory
#pwd
Install the dependency packages and applications
#yum install -y wget httpd php gcc glibc glibc-common gd gd-devel make net-snmp

To start with I will detail the steps for installing the Nagios Core package from the source to a linux fedora distribution.

Step 1
You could download the source package from the links given above or by running the command given below.
Run the following commands in your terminal:
To change the directory to temporary folder
#cd /tmp

This will download Nagios core package and the required plugins.

Step 2
Creating User accounts and Group
#useradd nagios
#groupadd nagcmd
#usermod -a -G nagcmd nagios


Step 3

Extracting the downloaded packages
#tar zxvf nagios-3.4.1.tar.gz
#tar zxvf nagios-plugins-1.4.15.tar.gz

Step 4
Once you extract the file you will get a folder with the name “nagios”.  Change to the directory and configure.
#cd nagios
#./configure --with-command-group=nagcmd

#make all
#make install
#make install-init
#make install-config
#make install-commandmode
#make install-webconf


#cp -R contrib/eventhandlers/  /usr/local/nagios/libexec/
#chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers


For verifying the configuration:
#/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

This should give zero errors and zero warnings before restarting the nagios service.

Starting the Nagios service
#/etc/init.d/nagios start

Starting the Web service
#/etc/init.d/httpd start

Create a Default User for Web Access.
Add a default user for Web Interface Access:
#htpasswd –c /usr/local/nagios/etc/htpasswd.users nagiosadmin

*** You will be prompted for a password for the account

Nagios Plugin Installation

After extracting the plugin file with the tar command as explained earlier.
#cd /tmp/nagios-plugins-1.4.15
#./configure --with-nagios-user=nagios --with-nagios-group=nagios
#make
#make install


Nagios Service Setup
The following commands will register the Nagios daemon to be run upon system startup.
#chkconfig --add nagios
#chkconfig --level 35 nagios on
#chkconfig --add httpd
#chkconfig --level 35 httpd



Web Access:
After completing the steps followed above and verifying the configurations without any errors or warnings, you should be able to access the Nagios tool GUI with web by issuing the command in the url of your browser. Edit the section of the IP with the IP of your system.


**** Log in with the credentials you chose while adding the “nagiosadmin” user to the “htpasswd.users” file.



Configuration of Nagios for monitoring your critical services and devices:


Here I will introduce you to the main configuration files which are required for making the configuration changes for making the tool ready as per our requirement.
 Important configuration files and locations:
  1)  Main nagios configuration file
/usr/local/nagios/etc/nagios.cfg

**** All the below mentioned files locations and some configuration parameters are mentioned over in this file.

22)      File for storing paths for useraccount to plugins and eventhandlers
/usr/local/nagios/etc/resource.cfg
33)      For setting the configurations for the tool GUI
/usr/local/nagios/etc/cgi.cfg

44)      For defining the device or service configuration parameters.
Eg:-/usr/local/nagios/etc/objects/switch.cfg
                   /usr/local/nagios/etc/objects/Router1.cfg

55)      Defining Host Information file: (Useful for making the host or service appear on the map)
#/usr/local/nagios/etc/objects hostextinfo.cfg


66)      Defining generic service template file: (Used while creating Host or Service for inheriting the configuration)
#/usr/local/nagios/etc/objects/templates.cfg

77)      Defining Timeperiods template file: (Timeperiods used in Host and services configuration)
#/usr/local/nagios/etc/objects/timeperiods.cfg

88)      Defining commands and its syntax with parameters:
/usr/local/nagios/etc/objects/commands.cfg

99)      Defining contacts to be notified and their availability time:
#/usr/local/nagios/etc/objects/contacts.cfg


Detail of device to be monitored :
Hostname: Router1
Ip address: 1.1.1.1
SNMP String: public
Interface: GigabitEthernet0/0 , FastEthernet 0/0/0

On the Cisco Router:
access-list 2 permit 2.2.2.2
snmp-server community public RO 2
snmp-server host {Ip-address}
snmp-server enable traps snmp authentication linkdown linkup coldstart warmstart
snmp-server enable traps memory
snmp-server enable traps cpu_threshold


**** Access list number and RO number should match.
Mention any other traps which you want to be notified as per your requirement.

Create a configuration file for the device under the directory “/usr/local/nagios/etc/objects/”

Template for Network device in router.cfg
#vi /usr/local/nagios/etc/objects/router.cfg

###############################################################################
###############################################################################
#
# HOST DEFINITIONS
#
###############################################################################
###############################################################################

# Define the Router  that we'll be monitoring

define host{
        use             generic-switch          ; Inherit default values from a template
        name            myrouter
        alias           myrouters      ; A longer name associated with the switch
        hostgroups      routers                ; Host groups this switch is associated with
        register        0
        }




###############################################################################
###############################################################################
#
# HOST GROUP DEFINITIONS
#
###############################################################################
###############################################################################

# Create a new hostgroup for routerss

define hostgroup{
        hostgroup_name  routers               ; The name of the hostgroup
        alias           Network Routers        ; Long name of the group
        }
###############################################################################

To save the file Esc > Shift :wq
Save and exit the configuration

*** Please note the “register     0” parameter in the configuration. This defines that the configuration is a dummy file or template. This template will be referenced for use in other host

Before creating this file you need to make sure that you have the plugins mentioned below for working of this configuration. Locate these files in /ur/local/nagios/libexec/

Required Plugins:
check_ping
check_snmp_load.pl
check_snmp_mem_v1
check_snmp


#vi /usr/local/nagios/etc/objects/Router1.cfg

###############################################################################
###############################################################################
#
# HOST DEFINITIONS
#
###############################################################################
###############################################################################

################################################################################
define host{
        use             generic-router                ; Inherit default values from a template mentioned above
        host_name       Router1                ####### Hostname as defined on the device
        alias           WAN -Router     ; A longer name associated with the switch
        address         1.1.1.1                ###### IP address of the device
        parents         Switch2      #####  To which device is this connected.  With Exact hostname            hostgroups      WAN-Devices      ##### Group to which this device will be listed
        _COMMUNITY      public    ####  SNMP string
        }
################################################################################
###################  HOST Extended Information ####################################
define hostextinfo{
                host_name    Router1
#               2d_coords 40,40
                icon_image cisco.png        ##### Place the logo /usr/local/nagios/share/images/logos/
                vrml_image cisco.png        ##### Place the logo /usr/local/nagios/share/images/logos/
                statusmap_image  cisco.png  #### Above location
                }
#################################################################################
###############################################################################
###############################################################################
#
# SERVICE DEFINITIONS
#
###############################################################################
###############################################################################

########### Monitoring Router Uptime  ################

define service{
        use                     generic-service ; Inherit values from a template
        host_name               Router1
        service_description     Uptime
        check_command           check_snmp!-C public -o sysUpTime.0
        }
########### Monitoring Router Availability with PING  ################
define service{
        use                     generic-service ; Inherit values from a template
        host_name               Router1 ; The name of the host the service is associated with
        service_description     PING            ; The service description
        check_command           check_ping!200.0,20%!600.0,60%  ; The command used to monitor the service
        normal_check_interval   1               ; Check the service every 1 minutes under normal conditions
        retry_check_interval    1               ; Re-check the service every minute until its final/hard state is determined
        }

########### Monitoring Router CPU Load Status ################

define service{
        use                     generic-service
        host_name               Router1
        service_description     CPU_Load
        check_command           check_snmp_load.pl!public!cisco!40,40,40!60,60,60
         normal_check_interval   1
        retry_check_interval    1
        notification_options w,c,r
         contact_groups   24X7      ######## Mention the contact group name defined in contacts.cfg
         }

########### Monitoring Router Memory  ################

define service{
       use                     generic-service ; Inherit values from a template
       host_name    Router1
       service_description             Memory
       check_command check_snmp_mem_v1!public!-I!60!70  #### Warning to 60% and Critical to 70%
        normal_check_interval   1
       retry_check_interval    1
       notification_options w,c,r
       contact_groups   24X7      ######## Mention the contact group name defined in contacts.cfg
       }



########### Monitoring Interface Status ################

define service{
                use                     generic-service ; Inherit values from a template
                host_name               Router1
                service_description     GigabitEthernet0/0  ### Name of the Interface for identification
                check_command           check_snmp!-C public -o ifOperStatus.1 -r 1 -m RFC1213-MIB
}

define service{
                use                     generic-service ; Inherit values from a template
                host_name               Router1
                service_description     FastEthernet0/0/0
                check_command           check_snmp!-C public -o ifOperStatus.4 -r 1 -m RFC1213-MIB
}

#############Monitoring Bandwidth / Traffic Rate ########################
###### You need to have already MRTG running and graphing for this device interface

define service{
use         generic-service ; Inherit values from a template
host_name         Router1
service_description        FastEthernet0/0/0  Bandwidth Usage
check_command check_local_mrtgtraf!/var/lib/mrtg/1.1.1.1_4.log!AVG!1000000,2000000!5000000,5000000!10
}


############################################################################
#################   END OF FILE ###############################################

To save the file Esc > Shift :wq

Save the file Router1.cfg and exit

If you want to ensure that a specific port/interface on the router is in an up state, you could add a service definition like this. You can usually find the OIDs that can be monitored on a router by running the following command (replace 1.1.1.1 with the IP address of the switch):
#snmpwalk -v1 -c public 1.1.1.1 -m ALL .1  > Rotuer1.txt
#cat Router1.txt
Or
# vi Router1.txt
This file will contain the OID’s used by the device, which can be used while configuring.

Sample contents of Router1.txt
ifDescr.1 = STRING: GigabitEthernet0/0
ifDescr.2 = STRING: GigabitEthernet0/1
ifDescr.3 = STRING: Backplane-GigabitEthernet0/3
ifDescr.4 = STRING: FastEthernet0/0/0
ifDescr.5 = STRING: FastEthernet0/0/1
ifDescr.6 = STRING: Serial0/1/0
ifDescr.7 = STRING: Serial0/1/1


Take the number mentioned after “ifDescr.” In “ifOperStatus.”

Configurations to be done in the commands.cfg file:

Add the lines as given below for checking memory and CPU load of cisco.
#vi  /usr/local/nagios/etc/objects/commands.cfg

####################################Cisco - Load & Memory############################################

# 'Cisco_CPU' command definition
define command{
        command_name    check_snmp_load.pl
        command_line    $USER1$/check_snmp_load.pl -C $ARG1$ -H $HOSTADDRESS$ $USER7$ -T $ARG2$ -w $ARG3$ -c $ARG4$ $ARG5$
         }

#'Cisco_memory' Cisco memory check
define command{
  command_name check_snmp_mem_v1
  command_line $USER1$/check_snmp_mem.pl -H $HOSTADDRESS$ -C $ARG1$ $USER7$ $ARG2$ -w $ARG3$ -c $ARG4$ $ARG5$
}
#####################################################################################


Configurations to be done in the nagios.cfg file:
***Please take precaution that all the configuration files with uncommented should be present

# OBJECT CONFIGURATION FILE(S)
# These are the object configuration files in which you define hosts,
# host groups, contacts, contact groups, services, etc.
# You can split your object definitions across several config files
# if you wish (as shown below), or keep them all in a single config file.

# You can specify individual object config files as shown below:
cfg_file=/usr/local/nagios/etc/objects/commands.cfg
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg

# Definitions for monitoring a router/switch
cfg_file=/usr/local/nagios/etc/objects/router.cfg
cfg_file=/usr/local/nagios/etc/objects/Router1.cfg
cfg_file=/usr/local/nagios/etc/objects/Switch2.cfg

##### # Host Template configuration file
xedtemplate_config_file=/usr/local/nagios/etc/objects/hostextinfo.cfg


# ADMINISTRATOR EMAIL/PAGER ADDRESSES
# The email and pager address of a global administrator (likely you).
# Nagios never uses these values itself, but you can access them by
# using the $ADMINEMAIL$ and $ADMINPAGER$ macros in your notification
# commands.

admin_email=nagios@localhost
admin_pager=pagenagios@localhost

To save the file Esc > Shift :wq





Make the configuration changes in cgi.cfg file:

#vi /usr/local/nagios/etc/cgi.cfg

# MAIN CONFIGURATION FILE
# This tells the CGIs where to find your main configuration file.
# The CGIs will read the main and host config files for any other
# data they might need.

main_config_file=/usr/local/nagios/etc/nagios.cfg

use_authentication=1

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

# PING SYNTAX
ping_syntax=/bin/ping -n -U -c 5 $HOSTADDRESS$



# REFRESH RATE
# This option allows you to specify the refresh rate in seconds
# of various CGIs (status, statusmap, extinfo, and outages).

refresh_rate=30

# ESCAPE HTML TAGS
escape_html_tags=1


# SOUND OPTIONS
# Note: All audio files must be placed in the /media subdirectory
# under the HTML path (i.e. /usr/local/nagios/share/media/).

host_unreachable_sound=warning.wav
host_down_sound=warning.wav
service_critical_sound=warning.wav

To save the file Esc > Shift :wq


There are many more fine tuning you can do on this file as per your requirement eg:- MAPS, Layout, etc….
Verify the configuration by issuing the command as given below:
# /usr/local/nagios/bin/nagios -v  /usr/local/nagios/etc/nagios.cfg

Output should be as given below before starting or restarting nagios.
Total Warnings: 0
Total Errors:   0

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


Restart the Nagios if all looks fine
#service nagios restart
Or
#/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
After this the configurations will reflect in the Web GUI Dashboard.

For further documentation please refer the official site.

1 comment:

  1. You also noticed the file "hostextinfo.cfg" --> Where is the file?

    ReplyDelete