Nagios Procedure on CentOS (Linux)


Topic 1: Install Nagios

 

To install Nagios we need to know the requirement for install Nagios

  • We need CentOS 5.5
  • Apache Php Gcc

To install we need to install CentOS and then we install Dependency package

By

 


# yum install httpd gcc glibc glibc-common gd gd-devel php

 

After we install dependency package we need to install nagios

We can download nagios from http://nagios.org and we install

 

#useradd -m nagios

 

Create nagcmd group for allowing external commands to be submitted through the web interface. Add both the nagios user and the apache user

 

#groupadd nagcmd

#usermod -a -G nagcmd nagios

#usermod -a -G nagcmd apache

 

Create one folder for installation

 

#Mkdir /tmp/nagios

 

Copy Nagios package that just download to that folder and extract it by command

 

#
tar -xvf nagios-3.2.1.tar.gz

 

After we extract we install to compile

 

#./configure –with-command-group=nagcmd

#make all ;Compile binaries, init script, sample config files:

#make install

#make install-init

#make install-config

#make install-commandmode

 

After we install we need to install web interface by command

 

#make install-webconf

 

Nagios Web Interface installed to /usr/local/nagios/share ( http conf file added to /etc/httpd/conf.d/nagios.conf )

Create Web Interface Login User:

 

#htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

#put password

#re put password

 

And we need to start services Apache

 

#service httpd restart

 

Topic 2: Install plugin

 

To install plugin we need to download plugin from http://nagios.org and then copy to /tmp/nagios and extract it by command

 

#
tar xzf nagios-plugins-1.4.13.tar.gz

#cd nagios-plugins1.4.13

 

Compile and Configure Nagios Plugins

 

#./configure –with-nagios-user=nagios –with-nagios-group=nagios

#make

#make install

 

After we install plugin we need to verify nagios with command

 

#/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

 

Total Warnings: 0

Total Errors: 0

 

Topic 3: Start Nagios

 

Enable Nagios to start at system startup / boot

 

#chkconfig –add nagios

#chkconfig nagios on

#chkconfig httpd on

 

Start Nagios

 

#service nagios start

 

To login we interface we need to

 

#http://ip-address/nagios

#chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin/

#chcon -R -t httpd_sys_content_t /usr/local/nagios/share/

 

Topic 4: Add host

To monitor we need to create host that we want to monitor. To create host need to know the type of host

Nagios we can monitor Linux, Windows server, Windows Client, Switch, Router, UPS, with and services.

 

Topic5: Monitor Localhost

The first I need to monitor localhost CentOS with services

  • Current Load
  • Current Users
  • PING
  • Root partition
  • SSH
  • Swap Usage
  • Total Processes

To configure local host we need to allow on main configuration nagios file

 

#/usr/local/nagios/etc/nagios.cfp bye delete sign (#) before this line

#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg

 

And then we need to configure on file localhost.cfg

 

define host{

use linux-server

host_name localhost

alias localhost

address 127.0.0.1

icon_image linux1.png

statusmap_image linux1.png

contact_groups admins

}

 

With host group

 

define hostgroup{


hostgroup_name linux-servers ; The name of the hostgroup

alias Linux Servers ; Long name of the group

members localhost; Comma separated list of hosts that belong to this group

}

define service{

use local-service ; Name of service template to use

host_name localhost

service_description PING

check_command check_ping!100.0,20%!500.0,60%

}

 

 

# Define a service to check the disk space of the root partition

# on the local machine. Warning if < 20% free, critical if

# < 10% free space on partition.

 

define service{

use local-service ; Name of service template to use

host_name localhost

service_description Root Partition

check_command check_local_disk!20%!10%!/

}

 

 

 

# Define a service to check the number of currently logged in

# users on the local machine. Warning if > 20 users, critical

# if > 50 users.

 

define service{

use local-service ; Name of service template to use

host_name localhost

service_description Current Users

check_command check_local_users!20!50

}

 

 

# Define a service to check the number of currently running procs

# on the local machine. Warning if > 250 processes, critical if

# > 400 users.

 

define service{

use local-service ; Name of service template to use

host_name localhost

service_description Total Processes

check_command check_local_procs!250!400!RSZDT

}

 

define service{

use local-service ; Name of service template to use

host_name localhost

service_description Current Load

check_command check_local_load!5.0,4.0,3.0!10.0,6.0,4.0

}

 

 

 

# Define a service to check the swap usage the local machine.

# Critical if less than 10% of swap is free, warning if less than 20% is free

 

define service{

use local-service ; Name of service template to use

host_name localhost

service_description Swap Usage

check_command check_local_swap!20!10

}

 

 

 

# Define a service to check SSH on the local machine.

# Disable notifications for this service by default, as not all users may have SSH enabled.

 

define service{

use local-service ; Name of service template to use

host_name localhost

service_description SSH

check_command check_ssh

notifications_enabled 1

}

 

 

 

Topic 6: Monitor Windows

 

To monitor window need to install nsclient++.exe on window client now I install nsclient++.exe on my computer with ip address 192.168.1.244

And we need to allow on

 

#vim /usr/local/nagios/etc/nagios.cfg by delete sign # before line

cfg_file=/usr/local/nagios/etc/objects/windows.cfg

 

And we need to configure on file

 

#vim /usr/local/nagios/etc/objects/windows.cfg

define host{

use windows-server ; Inherit default values from a template

host_name winserver ; The name we’re giving to this host

alias My Windows Server ; A longer name associated with the host

address 192.168.1.244; IP address of the host

icon_image windows.png

icon_image_alt windows.png

statusmap_image windows.png

contact_groups admins

}

define hostgroup{

hostgroup_name windows-servers ; The name of the hostgroup

alias Windows Servers ; Long name of the group

}

 

 

# Create a service for monitoring the version of NSCLient++ that is installed

# Change the host_name to match the name of the host you defined above

 

define service{

use generic-service

host_name winserver

service_description NSClient++ Version

check_command check_nt!CLIENTVERSION

}

 

# Create a service for monitoring the uptime of the server

# Change the host_name to match the name of the host you defined above

 

define service{

use generic-service

host_name winserver

service_description Uptime

check_command check_nt!UPTIME

}

 

# Create a service for monitoring CPU load

# Change the host_name to match the name of the host you defined above

 

define service{

use generic-service

host_name winserver

service_description CPU Load

check_command check_nt!CPULOAD!-l 5,80,90

}

 

# Create a service for monitoring memory usage

# Change the host_name to match the name of the host you defined above

 

define service{

use generic-service

host_name winserver

service_description Memory Usage

check_command check_nt!MEMUSE!-w 80 -c 90

}

 

 

# Create a service for monitoring C:\ disk usage

# Change the host_name to match the name of the host you defined above

 

define service{

use generic-service

host_name winserver

service_description C:\ Drive Space

check_command check_nt!USEDDISKSPACE!-l c -w 80 -c 90

}

 

define service{

use generic-service

host_name winserver

service_description D:\ Drive Space

check_command check_nt!USEDDISKSPACE!-l d -w 80 -c 90

}

 

# Create a service for monitoring the Explorer.exe process

# Change the host_name to match the name of the host you defined above

 

define service{

use generic-service

host_name winserver

service_description Explorer

check_command check_nt!PROCSTATE!-d SHOWALL -l Explorer.exe

}

 

Topic 7: Monitor Switch or router

To monitor switch or router we need to allow on file nagios.cfg the same localhost and windows

 

cfg_file=/usr/local/nagios/etc/objects/switch.cfg

 

And then we need to configure on file

 

#vim /
usr/local/nagios/etc/objects/switch.cfg

define host{

use generic-switch ; Inherit default values from a template

host_name s-02-pnh-hqcore ; The name we’re giving to this switch

alias s-02-pnh-hqcore ; A longer name associated with the switch

address 111.67.111.248 ; IP address of the switch

hostgroups switches ; Host groups this switch is associated with

}

 

define hostgroup{

hostgroup_name switches ; The name of the hostgroup

alias Network Switches ; Long name of the group

}

 

# Create a service to PING to switch

 

define service{

use generic-service ; Inherit values from a template

host_name s-02-pnh-hqcore ; 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 5 ; Check the service every 5 minutes under normal conditions

retry_check_interval 1 ; Re-check the service every minute until its final/hard state is determined

}

 

 

# Monitor uptime via SNMP

 

define service{

use generic-service ; Inherit values from a template

host_name s-02-pnh-hqcore

service_description Uptime

check_command check_snmp!-C public -o sysUpTime.0

}

 

Topic 8: Command

 

All the command that we use we need to write on file

 

#vim /usr/local/nagios/etc/command.cfg

# ‘check_local_disk’ command definition

define command{

command_name check_local_disk

command_line $USER1$/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$

}

 

# ‘check_local_load’ command definition

define command{

command_name check_local_load

command_line $USER1$/check_load -w $ARG1$ -c $ARG2$

}

 

 

# ‘check_local_procs’ command definition

define command{

command_name check_local_procs

command_line $USER1$/check_procs -w $ARG1$ -c $ARG2$ -s $ARG3$

}

 

 

# ‘check_local_users’ command definition

define command{

command_name check_local_users

command_line $USER1$/check_users -w $ARG1$ -c $ARG2$

}

 

# ‘check_local_swap’ command definition

define command{

command_name check_local_swap

command_line $USER1$/check_swap -w $ARG1$ -c $ARG2$

}

 

# ‘check_local_mrtgtraf’ command definition

define command{

command_name check_local_mrtgtraf

command_line $USER1$/check_mrtgtraf -F $ARG1$ -a $ARG2$ -w $ARG3$ -c $ARG4$ -e $ARG5$

}

 

define command{

command_name check_ftp

command_line $USER1$/check_ftp -H $HOSTADDRESS$ $ARG1$

}

 

# ‘check_hpjd’ command definition

define command{

command_name check_hpjd

command_line $USER1$/check_hpjd -H $HOSTADDRESS$ $ARG1$

}

 

# ‘check_snmp’ command definition

define command{

command_name check_snmp

command_line $USER1$/check_snmp -H $HOSTADDRESS$ $ARG1$

}

 

# ‘check_http’ command definition

define command{

command_name check_http

command_line $USER1$/check_http -I $HOSTADDRESS$ $ARG1$

}

 

define command{

command_name check_dns

command_line $USER1$/check_dns $ARG1$

}

 

# ‘check_ssh’ command definition

define command{

command_name check_ssh

command_line $USER1$/check_ssh $ARG1$ $HOSTADDRESS$

}

 

# ‘check_dhcp’ command definition

define command{

command_name check_dhcp

command_line $USER1$/check_dhcp $ARG1$

}

 

# ‘check_ping’ command definition

define command{

command_name check_ping

command_line $USER1$/check_ping -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ -p 5

}

 

# ‘check_pop’ command definition

define command{

command_name check_pop

command_line $USER1$/check_pop -H $HOSTADDRESS$ $ARG1$

}

 

# ‘check_imap’ command definition

define command{

command_name check_imap

command_line $USER1$/check_imap -H $HOSTADDRESS$ $ARG1$

}

 

 

# ‘check_smtp’ command definition

define command{

command_name check_smtp

command_line $USER1$/check_smtp -H $HOSTADDRESS$ $ARG1$

}

 

# ‘check_tcp’ command definition

define command{

command_name check_tcp_sql

command_line $USER1$/check_tcp -H 192.168.1.217 -p 3306

}

 

define command{

command_name check_amavis

command_line $USER1$/check_tcp -H 192.168.1.217 -p 10024

}

define command{

command_name check_tcp

command_line $USER1$/check_tcp -H $HOSTADDRESS$ -p $ARG1$ $ARG2$

}

 

 

# ‘check_udp’ command definition

define command{

command_name check_udp

command_line $USER1$/check_udp -H $HOSTADDRESS$ -p $ARG1$ $ARG2$

}

 

 

# ‘check_nt’ command definition

define command{

command_name check_nt

command_line $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -v $ARG1$ $ARG2$

}

  • Note for snmp we need to install

    yum install net-snmp
    yum install net-snmp-utils

Topic 9: Create Contact

 

After we add host we need to create contact for nagios to sent mail sent it have problem

To create contact we need to

#vim /usr/local/nagios/etc/contact.cfg

define contact{

contact_name nagiosadmin ; Short name of user

use generic-contact ; Inherit default values from generic-contact template

alias Nagios Admin ; Full name of user

email nagios@svc.lan

}

 

# We only have one contact in this simple configuration file, so there is

# no need to create more than one contact group.

 

define contactgroup{

contactgroup_name admins

alias Nagios Administrators

members nagiosadmin

}

 

And we need to add contact to host like above.

 

 

Topic 10: Monitor Linux server their services

To monitor Linux server we need to

Vim need to enable on nagios.cfg

cfg_dir=/usr/local/nagios/etc/servers

 

And we need to create file with extension cfg on folder server

 

define host{

use linux-servers

host_name master.svc.lan

alias master.svc.lan

address 192.168.1.217

contact_groups admins

icon_image linux.png

statusmap_image linux.png

}

 

define hostgroup{

hostgroup_name linux-servers

alias Linux Servers

members master.svc.lan

}

 

define service{

use generic-service ; Name of service template to use

host_name master.svc.lan

service_description SSH

check_command check_ssh

# notifications_enabled 1

}

 

define service{

use generic-service ; Name of service template to use

host_name master.svc.lan

service_description HTTP

check_command check_http

notifications_enabled 1

contact_groups admins

 

}

 

define service {

use generic-service

host_name master.svc.lan

service_description SMTP

check_command check_smtp! -t 2 -e “svc.lan”

}

 

define service {

use generic-service

host_name master.svc.lan

service_description POP3

check_command check_pop

}

define service {

use generic-service

host_name master.svc.lan

service_description IMAP

check_command check_imap

}

define service {

use generic-service

host_name master.svc.lan

service_description Mysql

check_command check_tcp_sql

}

 

define service {

use generic-service

host_name master.svc.lan

service_description DNS

check_command check_dns!master.svc.lan

}

define service{

use generic-service ; Name of service template to use

host_name master.svc.lan

service_description PING

check_command check_ping!100.0,20%!500.0,60%

}

 

Finish!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s