Introduction
As part of the network monitoring server, Nagios is used for monitoring servers and their services.
Installation
Download and expand the source:
cd /usr/src
wget http://superb-east.dl.sourceforge.net/sourceforge/nagios/nagios-2.4.tar.gz
tar -zxvf nagios-2.4.tar.gz
Add users and groups:
adduser nagios
mkdir /usr/local/nagios
chown nagios.nagios /usr/local/nagios
groupadd nagioscmd
usermod -G nagioscmd www-data
usermod -G nagioscmd nagios
Obtain libs, compile, and install:
apt-get install libgd-dev
apt-get install mcrypt
apt-get install libmcrypt-dev
cd nagios-2.4
./configure \
--prefix=/usr/local/nagios \
--with-cgiurl=/cgi-bin/nagios \
--with-htmurl=/nagios \
--with-nagios-user=nagios \
--with-nagios-group=nagios \
--with-command-group=nagioscmd \
--localstatedir=/var/local/nagios
make all
make install
make install-init
make install-commandmode
make install-config
Add the following lines to /etc/apache2/sites-available/default.
They need to go before the default cgi-bin configuration files.
<Location "/nagios/">
SetHandler default-handler
</Location>
ScriptAlias /cgi-bin/nagios/ /usr/local/nagios/sbin/
<Directory "/usr/local/nagios/sbin">
# AllowOverride AuthConfig
AllowOverride None
Options ExecCGI -MultiViews
Order allow,deny
Allow from all
AddHandler cgi-script .cgi
</Directory>
Alias /nagios/ "/usr/local/nagios/share/"
<Directory "/usr/local/nagios/share">
DefaultType text/html
Options None
# AllowOverride AuthConfig
AllowOverride None
Order allow,deny
Allow from all
</Directory>
Restart Apache:
/etc/init.d/apache2 restart
Modify configuration files:
cd /usr/local/nagios
mkdir samples
cp * samples/
mv cgi.cfg-sample cgi.cfg
mv checkcommands.cfg-sample checkcommands.cfg
mv misccommands.cfg-sample misccommands.cfg
mv nagios.cfg-sample nagios.cfg
mv resource.cfg-sample resource.cfg
rm bigger.cfg-sample
rm minimal.cfg-sample
Install plug-ins:
cd /usr/src
>wget http://superb-east.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.3.tar.gz
tar -zxvf nagios-plugins-1.4.3.tar.gz
cd nagios-plugins-1.4.3
./configure \
--prefix=/usr/local/nagios \
--with-nagios-user=nagios \
--with-nagios-group=nagios \
--with-cgiurl=/cgi-bin/nagios
make
make install
Make Nagios run automatically:
update-rc.d nagios defaults 25
To test configurations before committing them to execution:
cd /usr/local/nagios
bin/nagios -v etc/nagios.cfg
Customizations
In /usr/local/nagios/etc/checkcommands.cfg, insert the following lines (this will be used by an Windows event
logging program):
# 'check_dummy' command definition
define command{
command_name check_dummy
command_line $USER1$/check_dummy $ARG1$ $ARG2$
}
Create a directory for site specific configurations:
mkdir /usr/local/nagios/etc/examplecom
Make the following changes to /usr/local/nagios/etc/nagios.cfg:
#cfg_file=/usr/local/nagios/etc/minimal.cfg
cfg_dir=/usr/local/nagios/etc/examplecom
check_external_commands=1
use_syslog=0
log_notifications=0
date_format=iso8601
admin_email=root
Apply the following changes to /usr/local/nagios/etc/cgi.cfg:
46c46
< show_context_help=0
---
> show_context_help=1
65c65
< #nagios_check_command=/usr/local/nagios/libexec/check_nagios /var/local/nagios/status.dat 5
'/usr/local/nagios/bin/nagios'
---
> nagios_check_command=/usr/local/nagios/libexec/check_nagios /var/local/nagios/status.dat 5
'/usr/local/nagios/bin/nagios'
116c116
< #authorized_for_system_information=nagiosadmin,theboss,jdoe
---
> authorized_for_system_information=nagiosadmin,admin
128c128
< #authorized_for_configuration_information=nagiosadmin,jdoe
---
> authorized_for_configuration_information=nagiosadmin,admin
141c141
< #authorized_for_system_commands=nagiosadmin
---
> authorized_for_system_commands=nagiosadmin,admin
154,155c154,155
< #authorized_for_all_services=nagiosadmin,guest
< #authorized_for_all_hosts=nagiosadmin,guest
---
> authorized_for_all_services=nagiosadmin,admin
> authorized_for_all_hosts=nagiosadmin,admin
168,169c168,169
< #authorized_for_all_service_commands=nagiosadmin
< #authorized_for_all_host_commands=nagiosadmin
---
> authorized_for_all_service_commands=nagiosadmin,admin
> authorized_for_all_host_commands=nagiosadmin,admin
Create a file /usr/local/nagios/etc/services.cfg with the following content:
################################################################################
# Configuration File: Services
#
# Last Modified: 2006/06/08
# By: Ray Burkholder
#
################################################################################
################################################################################
# Service Templates
################################################################################
# Generic service definition template
define service{
name generic-service ; Generic Service Template
active_checks_enabled 1 ; Active service checks are enabled
passive_checks_enabled 1 ; Passive service checks are enabled/accepted
parallelize_check 1 ; Active service checks should be parallelized
obsess_over_service 1 ; We should obsess over this service (if necessary)
check_freshness 0 ; Default is to NOT check service 'freshness'
notifications_enabled 1 ; Service notifications are enabled
event_handler_enabled 1 ; Service event handler is enabled
flap_detection_enabled 1 ; Flap detection is enabled
process_perf_data 1 ; Process performance data
retain_status_information 1 ; Retain status information across program restarts
retain_nonstatus_information 1 ; Retain non-status information across program restarts
register 0 ; DONT REGISTER THIS DEFINITION
is_volatile 0
check_period 24x7
max_check_attempts 3
normal_check_interval 3
retry_check_interval 1
contact_groups general-admins
notification_interval 120
notification_period 24x7
notification_options w,u,c,r
}
Create a file /usr/local/nagios/etc/hosts.cfg with the following content:
###############################################################################
# Configuration File: Hosts
# Last Modified: 2006/06/08
#
# By: Ray Burkholder
#
################################################################################
# HOST Template
################################################################################
# Generic host definition template
define host{
name generic-host-skeleton ; The name of this host template
notifications_enabled 1 ; Host notifications are enabled
event_handler_enabled 0 ; Host event handler is enabled
flap_detection_enabled 1 ; Flap detection is enabled
process_perf_data 1 ; Process performance data
retain_status_information 1 ; Retain status information across program restarts
retain_nonstatus_information 1 ; Retain non-status information across program restarts
active_checks_enabled 1
passive_checks_enabled 0
max_check_attempts 5
contact_groups general-admins
register 0 ; DONT REGISTER THIS DEFINITION
}
# 'generic-host' server host definition
define host{
name generic-host
use generic-host-skeleton
check_command check-host-alive
notification_interval 120
notification_period 24x7
notification_options d,u,r
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST
}
# 'generic-host-nocheck' server host definition
define host{
name generic-host-nocheck
use generic-host-skeleton
notification_interval 120
notification_period 24x7
notification_options d,u,r
register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOst
}
Add the following lines to /usr/local/nagios/etc/nagios.cfg:
cfg_file=/usr/local/nagios/etc/services.cfg
cfg_file=/usr/local/nagios/etc/hosts.cfg
cfg_dir=/usr/local/nagios/etc/examplecom
examplecom files
Create file /usr/local/nagios/etc/examplecom/timeperiod.cfg:
################################################################################
# Configuration File: Time Period
#
# Last Modified: 2005/07/19
#
# By: Ray Burkholder
#
################################################################################
###############################################################################
# TIMEPERIOD DEFINITIONS
################################################################################
# '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 09:00-17:00
tuesday 09:00-17:00
wednesday 09:00-17:00
thursday 09:00-17:00
friday 09: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 a file called /usr/local/nagios/etc/examplecom/contacts.cfg with the following contact. Add additional
contacts and rearrange groups as needed.
################################################################################
# Configuration File: Contacts and Contact Groups
#
# Last Modified: 2006/06/08
#
# By: Ray Burkholder
#
################################################################################
# relevant documentation
# http://nagios.sourceforge.net/docs/1_0/xodtemplate.html#contact<
################################################################################
# CONTACT DEFINITIONS
################################################################################
# 'nagios' contact definition
define contact{
contact_name nagios
alias Nagios Admin
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,u,r
service_notification_commands notify-by-email,notify-by-epager
host_notification_commands host-notify-by-email,host-notify-by-epager
email nagios-admin@localhost.localdomain
pager pagenagios-admin@localhost.localdomain
}
# Network Generic Alerts
define contact {
contact_name networkalerts
alias Network Alerts
service_notification_period 24x7
host_notification_period 24x7
service_notification_options c,w
host_notification_options d,r
service_notification_commands notify-by-email
host_notification_commands host-notify-by-email
email networkalerts@example.com
}
################################################################################
# CONTACT GROUP DEFINITIONS
################################################################################
# 'general-admins' contact group definition
define contactgroup{
contactgroup_name general-admins
alias General Administrators
members networkalerts
}
# 'windows-server-admins' contact group definition
define contactgroup{
contactgroup_name windows-server-admins
alias Windows Server Administrators
members networkalerts
}
# 'windows-desktop-admins' contact group definition
define contactgroup{
contactgroup_name windows-desktop-admins
alias Windows Desktop Support
members networkalerts
}
# 'linux-server-admins' contact group definition
define contactgroup{
contactgroup_name linux-server-admins
alias Linux Administrators
members networkalerts
}
# 'switch-admins' contact group definition
define contactgroup{
contactgroup_name switch-admins
alias Etherswitch Administrators
members networkalerts
}
# 'router-admins' contact group definition
define contactgroup{
contactgroup_name router-admins
alias Router Technicians
members networkalerts
}
# 'firewall-admins' contact group definition
define contactgroup{
contactgroup_name firewall-admins
alias Firewall Technicians
members networkalerts
}
# 'printer-admins' contact group definition
define contactgroup{
contactgroup_name printer-admins
alias Printer Administrators
members networkalerts
}
# 'sensor-admins' contact group definition
define contactgroup{
contactgroup_name sensor-admins
alias Sensor Administrators
members networkalerts
}
Create a file called /usr/local/nagios/etc/examplecom/groups.cfg with the following template:
################################################################################
# Configuration File: Groups
#
# Last Modified: 2006/06/08
# By: Ray Burkholder
#
################################################################################
# Group DEFINITIONS
################################################################################
#define hostgroup {
# hostgroup_name groupname
# alias Member Devices
# members x,y
# }