Documentation Of: Ministry of Education, Youth and Sport

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 77

Kingdom of Cambodia

National Religion King


YYZZ

Ministry of Education, Youth and Sport


Department of Information and ASEAN Affairs
ICT in Education Office

Documentation of

Topic: Nagios Core 3.3.1 Network Monitoring

YYFMarch 1, 2012GZZ
Ministry of Education, Youth and Sport, #201, Norodom Blvd., Phnom Penh Kingdom of Cambodia
website: www.moeys.gov.kh, Email: info@moeys.gov.kh
Fax: +855 23 210 134

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

Document History

VERSION
V1.0
V1.0

March 1, 2012

DATE
FEBROURY 01, 2012
FEBROURY 02, 2012

DESCRIPTION
NAGIOS CORE AND PLUGINS INSTALATION

By Vannath KANN

Page 2 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

Table of Content
1.

2.

3.

About Nagios Core .......................................................................................................................... 6


1.1.

What is Nagios Core? ...........................................................................................................................................6

1.2.

Downloading the Latest Version .........................................................................................................................6

Quick Start Installation Guide....................................................................................................... 6


2.1.

Introduction ..........................................................................................................................................................6

2.2.

What You Will End Up? ......................................................................................................................................7

2.3.

Prerequisites..........................................................................................................................................................7

2.4.

Step 1: Create Account Information ...................................................................................................................7

2.5.

Step 2: Download Nagios and the Plugins ..........................................................................................................8

2.6.

Step 3: Compile and Install Nagios .....................................................................................................................8

2.7.

Step 4: Customize Configuration ........................................................................................................................9

2.8.

Step 5: Configure the Web Interface ..................................................................................................................9

2.9.

Step 6: Compile and Install the Nagios Plugins ...............................................................................................11

2.10.

Step 7: Start Nagios ............................................................................................................................................11

2.11.

Step 8: Modify SELinux Setting ........................................................................................................................12

2.12.

Step 9: Login to the Web Interface ...................................................................................................................13

2.13.

Step 10: Other Modifications.............................................................................................................................14

2.14.

Step 11:Your Done ............................................................................................................................................15

2.15.

Nagios Virtual Host ............................................................................................................................................15

How to monitor a Linux/Unix machine (NRPE addon) ............................................................ 18


3.1.

Introduction ........................................................................................................................................................18

3.2.

Overview..............................................................................................................................................................19

3.3.

Installation and Setup NRPE on Remote Server .............................................................................................19

3.4.

SetupNagios Monitoring Host Server ...............................................................................................................23

3.5.
Customizing Your Configuration......................................................................................................................31
3.5.1. Remote Host Configuration .............................................................................................................................31
3.5.2. Monitoring Host Configuration .......................................................................................................................32
3.6.

4.

NRPE Option Help .............................................................................................................................................33

How to monitor a Windows machine .......................................................................................... 35


4.1.

Introduction ........................................................................................................................................................35

March 1, 2012

By Vannath KANN

Page 3 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

5.

6.

7.

4.2.

Overview..............................................................................................................................................................35

4.3.

What's Already Done For You ..........................................................................................................................36

4.4.

Prerequisites........................................................................................................................................................36

4.5.

Installing the Windows Agent............................................................................................................................37

4.6.

Configuring Nagios.............................................................................................................................................40

4.7.

Password Protection ...........................................................................................................................................43

4.8.

Restarting Nagios................................................................................................................................................44

How to monitor a router/switch................................................................................................... 45


5.1.

Introduction ........................................................................................................................................................45

5.2.

Overview..............................................................................................................................................................45

5.3.

Steps .....................................................................................................................................................................46

5.4.

What's Already Done For You ..........................................................................................................................46

5.5.

Prerequisites........................................................................................................................................................47

5.6.

Configuring Nagios.............................................................................................................................................47

5.7.

Monitoring Services............................................................................................................................................48

5.8.

Monitoring Packet Loss and RTA.....................................................................................................................48

5.9.

Monitoring SNMP Status Information .............................................................................................................48

5.10.

Monitoring Bandwidth / Traffic Rate ...............................................................................................................49

5.11.

Restarting Nagios................................................................................................................................................50

How to monitor a network printer .............................................................................................. 51


6.1.

Introduction ........................................................................................................................................................51

6.2.

Overview..............................................................................................................................................................51

6.3.

Steps .....................................................................................................................................................................52

6.4.

What's Already Done For You ..........................................................................................................................52

6.5.

Prerequisites........................................................................................................................................................52

6.6.

Configuring Nagios.............................................................................................................................................53

6.7.

Restarting Nagios................................................................................................................................................54

How to monitor a publicly available service (HTTP,FTP,SSH,etc.) ........................................ 55


7.1.

Introduction ........................................................................................................................................................55

7.2.

Plugins For Monitoring Service.........................................................................................................................55

7.3.

Creating A Host Definition ................................................................................................................................56

7.4.

Creating Service Definitions ..............................................................................................................................56

March 1, 2012

By Vannath KANN

Page 4 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

8.

9.

7.5.

Monitoring HTTP...............................................................................................................................................56

7.6.

Monitoring FTP ..................................................................................................................................................62

7.7.

Monitoring SSH ..................................................................................................................................................63

7.8.

Monitoring SMTP...............................................................................................................................................64

7.9.

Monitoring POP3................................................................................................................................................66

7.10.

Monitoring IMAP ...............................................................................................................................................67

7.11.

Restarting Nagios ss............................................................................................................................................69

Parent and Childs Relationship ................................................................................................... 70


8.1.

Introduction ........................................................................................................................................................70

5.2.

Configuration ......................................................................................................................................................70

Icon Images.................................................................................................................................... 72

10. Trouble shooting ........................................................................................................................... 76


10.1.

Verifying Your Configuration ...........................................................................................................................76

11. Reference........................................................................................................................................ 77

March 1, 2012

By Vannath KANN

Page 5 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

1. About Nagios Core


1.1.

What is Nagios Core?


Nagios Core is an Open Source system and network monitoring application. It watches
hosts and services that you specify, alerting you when things go bad and when they get better.
Nagios Core was originally designed to run under Linux, although it should work under most
other unices as well.
Some of the many features of Nagios Core include:

1.2.

Monitoring of network services (SMTP, POP3, HTTP, NNTP, PING, etc.)


Monitoring of host resources (processor load, disk usage, etc.)
Simple plugin design that allows users to easily develop their own service checks
Parallelized service checks
Ability to define network host hierarchy using "parent" hosts, allowing detection of and
distinction between hosts that are down and those that are unreachable
Contact notifications when service or host problems occur and get resolved (via email,
pager, or user-defined method)
Ability to define event handlers to be run during service or host events for proactive
problem resolution
Automatic log file rotation
Support for implementing redundant monitoring hosts
Optional web interface for viewing current network status, notification and problem history,
log file, etc.

Downloading the Latest Version


FYou can check for new versions of Nagios Core at http://www.nagios.org/download.

2. Quick Start Installation Guide


2.1.

Introduction
This guide is intended to provide you with simple instructions on how to install Nagios from
source (code) on Fedora and have it monitoring your local machine inside of 20 minutes. No
advanced installation options are discussed here - just the basics that will work for 95% of users
who want to get started.
These instructions were written based on a standard CentOS 6.0 version Linux distribution.

March 1, 2012

By Vannath KANN

Page 6 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

2.2.

What You Will End Up?


If you follow these instructions, here's what you'll end up with:
Nagios and the plugins will be installed underneath /usr/local/nagios
Nagios will be configured to monitor a few aspects of your local system (CPU load, disk
usage, etc.)
The Nagios web interface will be accessible at http://localhost/nagios/

2.3.

Prerequisites
During portions of the installation you'll need to have root access to your machine.
You also need to give it a static IP address.
Make sure you've installed the following packages on your Fedora installation before
continuing.
Apache
PHP
GCC compiler
GD development libraries
You can use yum to install these packages by running the following commands (as root):

[root@cent60 ~]# yum install httpdphp


[root@cent60 ~]# yum install gccglibcglibc-common
[root@cent60 ~]# yum install gdgd-devel

2.4.

Step 1: Create Account Information


Become the root user.

[vannath@cent60 ~]$ su -l
Password:
[root@cent60 ~]#

Create a new nagios user account and give it a password.


[root@cent60 ~]# useradd -m nagios
[root@cent60 ~]# passwdnagios
Changing password for user nagios.
New password:
BAD PASSWORD: it is too simplistic/systematic
BAD PASSWORD: is too simple
Retype new password:
March 1, 2012

By Vannath KANN

Page 7 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

passwd: all authentication tokens updated successfully.


[root@cent60 ~]#

Create a new nagcmd group for allowing external commands to be submitted through the web
interface. Add both the nagios user and the apache user to the group.
[root@cent60
[root@cent60
[root@cent60
[root@cent60

2.5.

~]# groupaddnagcmd
~]# usermod -a -G nagcmdnagios
~]# usermod -a -G nagcmd apache
~]#

Step 2: Download Nagios and the Plugins


Create a directory for storing the Nagios Core from downloads.

[root@cent60
[root@cent60
[root@cent60
[root@cent60

~]#
~]# mkdir -p /opt/NagiosCore3.3
~]# cd /opt/NagiosCore3.3/
NagiosCore3.3]#

Download the source code tarballs of both Nagios and the Nagios plugins (visit
http://www.nagios.org/download/ for links to the latest versions). These directions were tested
with Nagios 3.3.1 and Nagios Plugins 1.4.15.
Make that you Server can access to internet.
[root@cent60 NagiosCore3.3]# wgethttp://prdownloads.sourceforge.net/
sourceforge/nagios/ nagios-3.3.1.tar.gz
[root@cent60 NagiosCore3.3]# wgethttp://prdownloads.sourceforge.net/
sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz

2.6.

Step 3: Compile and Install Nagios


Extract the Nagios source code tarball.

[root@cent60 NagiosCore3.3]# ll
total 3724
-rw-r--r--. 1 root root 1714630 Dec 14 14:56 nagios-3.3.1.tar.gz
-rw-r--r--. 1 root root 2095419 Dec 14 14:57 nagios-plugins-1.4.15.tar.gz
[root@cent60 NagiosCore3.3]# tar xvf nagios-3.3.1.tar.gz
[root@cent60 NagiosCore3.3]# ll
total 3728
drwxr-xr-x. 16 nagiosnagios
4096 Jul 26 2011nagios
March 1, 2012

By Vannath KANN

Page 8 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

-rw-r--r--.
-rw-r--r--.
[root@cent60
[root@cent60

1 root
root
1714630 Dec 14 14:56 nagios-3.3.1.tar.gz
1 root
root
2095419 Dec 14 14:57 nagios-plugins-1.4.15.tar.gz
NagiosCore3.3]# cdnagios
nagios]#

Run the Nagios configure script, passing the name of the group you created earlier like so:
[root@cent60 nagios]# ./configure --with-command-group=nagcmd

Compile the Nagios source code.


[root@cent60 nagios]# make all

Install binaries, init script, sample config files and set permissions on the external command
directory.
[root@cent60
[root@cent60
[root@cent60
[root@cent60

nagios]#
nagios]#
nagios]#
nagios]#

make
make
make
make

install
install-init
install-config
install-commandmode

Don't start Nagios yet - there's still more that needs to be done......

2.7.

Step 4: Customize Configuration


Sample configuration files have now been installed in the /usr/local/nagios/etc directory. These
sample files should work fine for getting started with Nagios. You'll need to make just one
change before you proceed.....
Edit the /usr/local/nagios/etc/objects/contacts.cfgconfig file with your favorite editor and
change the email address associated with the nagiosadmin contact definition to the address
you'd like to use for receiving alerts.

[root@cent60 nagios]# vim /usr/local/nagios/etc/objects/contacts.cfg


#
emailnagios@localhost
ADDRESS ******
email
TO YOUR EMAIL ADDRESS ******

2.8.

; <<***** CHANGE THIS TO YOUR EMAIL


vannathkann@gmail.com

; <<***** CHANGE THIS

Step 5: Configure the Web Interface


Install the Nagios web config file in the Apache conf.d directory.

March 1, 2012

By Vannath KANN

Page 9 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

[root@cent60 nagios]# make install-webconf


[root@cent60 nagios]#

Create a nagiosadmin account for logging into the Nagios web interface. Remember the
password you assign to this account - you'll need it later.
[root@cent60 nagios]# htpasswd -c /usr/local/nagios/htpasswd.usersnagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin
[root@cent60 nagios]#

Restart Apache to make the new settings take effect.


[root@cent60 nagios]# servicehttpd restart
Stopping httpd:
[ OK ]
Starting httpd: httpd: apr_sockaddr_info_get() failed for cent60
httpd: Could not reliably determine the server's fully qualified domain name,
using 127.0.0.1 for ServerName
[ OK ]
[root@cent60 nagios]# servicehttpd status
httpd (pid 1610) is running...
[root@cent60 nagios]#

You will experience with above httpd error message so fix is issue we have go and edit file
/etc/httpd/conf/httpd.conf
[root@cent60 conf]# pwd
/etc/httpd/conf
[root@cent60 conf]# vimhttpd.conf

# redirections work in a sensible way.


#
#ServerName www.example.com:80
ServerName*:80
#
# UseCanonicalName: Determines how Apache constructs self-referencing
[root@cent60 nagios]# servicehttpd restart
Stopping httpd:
Starting httpd:

March 1, 2012

By Vannath KANN

[
[

OK
OK

]
]

Page 10 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

[root@cent60 nagios]#

2.9.

Step 6: Compile and Install the Nagios Plugins


Extract the Nagios plugins source code tarball.

[root@cent60 NagiosCore3.3]# tar xvf nagios-plugins-1.4.15.tar.gz


[root@cent60 NagiosCore3.3]# ll
total 3732
drwxr-xr-x. 16 nagiosnagios
4096 Feb 1 23:08 nagios
-rw-r--r--. 1 root
root
1714630 Dec 14 14:56 nagios-3.3.1.tar.gz
drwxrwxrwx. 16 nagios root
4096 Jul 28 2010nagios-plugins-1.4.15
-rw-r--r--. 1 root
root
2095419 Dec 14 14:57 nagios-plugins-1.4.15.tar.gz
[root@cent60 NagiosCore3.3]#cd nagios-plugins-1.4.15

Compile and install the plugins.


[root@cent60 nagios-plugins-1.4.15]# ./configure --with-nagios-user=nagios -with-nagios-group=nagios
[root@cent60 nagios-plugins-1.4.15]# make
[root@cent60 nagios-plugins-1.4.15]# make install

2.10. Step 7: Start Nagios


Add Nagios to the list of system services and have it automatically start when the system boots.
[root@cent60 nagios-plugins-1.4.15]# chkconfig --add nagios
[root@cent60 nagios-plugins-1.4.15]# chkconfignagios on
[root@cent60 nagios-plugins-1.4.15]#

Verify the sample Nagios configuration files.

[root@cent60 nagios-plugins-1.4.15]# /usr/local/nagios/bin/nagios -v


/usr/local/nagios/etc/nagios.cfg
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...
Total Warnings: 0
Total Errors:
0

March 1, 2012

By Vannath KANN

Page 11 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

Things look okay - No serious problems were detected during the pre-flight
check
[root@cent60 nagios-plugins-1.4.15]#

If there are no errors, start Nagios.


[root@cent60 nagios-plugins-1.4.15]#
[root@cent60 nagios-plugins-1.4.15]# servicenagios start
Starting nagios: done.
[root@cent60 nagios-plugins-1.4.15]# servicenagios restart
Running configuration check...done.
Stopping nagios: done.
Starting nagios: done.
[root@cent60 nagios-plugins-1.4.15]#

2.11. Step 8: Modify SELinux Setting


Fedora ships with SELinux (Security Enhanced Linux) installed and in Enforcing mode by
default. This can result in "Internal Server Error" messages when you attempt to access the
Nagios CGIs.
See if SELinux is in Enforcing mode.
[root@cent60 nagios-plugins-1.4.15]# getenforce
Enforcing
[root@cent60 nagios-plugins-1.4.15]#

Put SELinux into Permissive mode.


[root@cent60 nagios-plugins-1.4.15]# getenforce 0
Enforcing
[root@cent60 nagios-plugins-1.4.15]#

To make this change permanent, you'll have to modify the settings in /etc/selinux/config and
reboot.
[root@cent60 nagios-plugins-1.4.15]# vim /etc/selinux/config
#
disabled - No SELinux policy is loaded.
#SELINUX=enforcing
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
[root@cent60 nagios-plugins-1.4.15]# reboot

March 1, 2012

By Vannath KANN

Page 12 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

Instead of disabling SELinux or setting it to permissive mode, you can use the following
command to run the CGIs under SELinux enforcing/targeted mode:
[root@cent60 nagios-plugins-1.4.15]# chcon -R -t httpd_sys_content_t
/usr/local/nagios/sbin
[root@cent60 nagios-plugins-1.4.15]# chcon -R -t httpd_sys_content_t
/usr/local/nagios/share/
[root@cent60 nagios-plugins-1.4.15]#

For information on running the Nagios CGIs under Enforcing mode with a targeted policy, visit
the Nagios Support Portal or Nagios Community Wiki.

2.12. Step 9: Login to the Web Interface


You should now be able to access the Nagios web interface at the URL below. You'll be
prompted for the username (nagiosadmin) and password you specified earlier.
Open web browser enter http://192.168.10.1/nagios
If you still cannot access no Nagios Server check your firewall and disable it.
[root@cent60 ~]#
[root@cent60 ~]# system-config-firewall-tui

March 1, 2012

By Vannath KANN

Page 13 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

Click on the "Service Detail" navbar link to see details of what's being monitored on your local
machine. It will take a few minutes for Nagios to check all the services associated with your
machine, as the checks are spread out over time.

2.13. Step 10: Other Modifications


Make sure your machine's firewall rules are configured to allow access to the web server if you
want to access the Nagios interface remotely.
Configuring email notifications is out of the scope of this documentation. While Nagios is
currently configured to send you email notifications, your system may not yet have a mail
program properly installed or configured. Refer to your system documentation, search the web,
or look to the Nagios Support Portal or Nagios Community Wiki for specific instructions on
configuring your system to send email messages to external addresses. More information on
notifications can be found here.

March 1, 2012

By Vannath KANN

Page 14 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

2.14. Step 11:Your Done


Congratulations! You sucessfully installed Nagios. Your journey into monitoring is just
beginning. You'll no doubt want to monitor more than just your local machine.

2.15. Nagios Virtual Host


We dont want to access to Nagios with 192.168.10.1/nagiso we want to use domain name
instead like nagios.vannath.lab
The Virtual Host configuration file will create during installing Nagios in
/etc/httpd/conf.d/nagios.conf
[root@cent60 conf.d]# pwd
/etc/httpd/conf.d
[root@cent60 conf.d]# vimnagios.conf
# SAMPLE CONFIG SNIPPETS FOR APACHE WEB SERVER
# Last Modified: 11-26-2005
#
# This file contains examples of entries that need
# to be incorporated into your Apache web server
# configuration file. Customize the paths, etc. as
# needed to fit your system.
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
<Directory "/usr/local/nagios/sbin">
# SSLRequireSSL
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
# Orderdeny,allow
# Deny from all
# Allow from 127.0.0.1
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>
Alias /nagios "/usr/local/nagios/share"
<Directory "/usr/local/nagios/share">
March 1, 2012

By Vannath KANN

Page 15 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

SSLRequireSSL
Options None
AllowOverride None
Order allow,deny
Allow from all
# Orderdeny,allow
# Deny from all
# Allow from 127.0.0.1
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>

And then edit this file as the following:


# SAMPLE CONFIG SNIPPETS FOR APACHE WEB SERVER
# Last Modified: 11-26-2005
#
# This file contains examples of entries that need
# to be incorporated into your Apache web server
# configuration file. Customize the paths, etc. as
# needed to fit your system.
<VirtualHost nagios.vannath.lab:80>
ServerAdmin webmaster@vannath.lab
DocumentRoot /usr/local/nagios/share
ServerNamenagios.vannath.lab
ErrorLog logs/dummy-host.example.com-error_log
CustomLog logs/dummy-host.example.com-access_log common

ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"


<Directory "/usr/local/nagios/sbin">
# SSLRequireSSL
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
# Orderdeny,allow
# Deny from all
# Allow from 127.0.0.1
AuthName "Nagios Access"
March 1, 2012

By Vannath KANN

Page 16 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>
Alias /nagios "/usr/local/nagios/share"
<Directory "/usr/local/nagios/share">
# SSLRequireSSL
Options None
AllowOverride None
Order allow,deny
Allow from all
# Orderdeny,allow
# Deny from all
# Allow from 127.0.0.1
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>
</VirtualHost>

The next thing to do is add CNAME record on your DNS Server


[root@cent60 conf.d]# vim /var/named/vannath.lab.zone
$TTL 1D
@
IN SOA
cent60.vannath.lab. root.vannath.lab. (
0
; serial
1D
; refresh
1H
; retry
1W
; expire
3H )
; minimum
NS
cent60.vannath.lab.
cent60 A
192.168.10.1
nagios CNAME
cent60.vannath.lab.

OK now let try access to nagios using domain name nagios.vannath.lab

March 1, 2012

By Vannath KANN

Page 17 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

Alright, now we can access Nagios with domain name

3. How to monitor a Linux/Unix machine (NRPE addon)


3.1.

Introduction
This document describes how you can monitor "private" services and attributes of Linux/UNIX
servers, such as:
CPU load
Memory usage

March 1, 2012

By Vannath KANN

Page 18 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

Disk usage
Logged in users
Running processes
etc.
Publicly available services that are provided by Linux servers (HTTP, FTP, SSH, SMTP, etc.)
can be monitored easily by following the documentation on monitoring publicly available
services.

3.2.

Overview
There are several different ways to monitor attributes or remote Linux/Unix servers. One is by
using shared SSH keys and the check_by_ssh plugin to execute plugins on remote servers. This
method will not be covered here, but can result in high load on your monitoring server if you
are monitoring hundreds or thousands of services. The overhead of setting up/destroying SSH
connections is the cause of this.
Another common method of monitoring remote Linux/Unix hosts is to use the NRPE addon.
NRPE allows you to execute plugins on remote Linux/Unix hosts. This is useful if you need to
monitor local resources/attributes like disk usage, CPU load, memory usage, etc. on a remote
host.
Use th NRPE daemon to execute Nagios plugins on the remote server and report back to the
monitoring host server.

3.3.

Installation and Setup NRPE on Remote Server

1. Create Nagios user account on remote server to monitored


[root@cent61 ~]# useraddnagios
[root@cent61 ~]# passwdnagios
Changing password for user nagios.
New password:
BAD PASSWORD: it is too simplistic/systematic
BAD PASSWORD: is too simple
March 1, 2012

By Vannath KANN

Page 19 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

Retype new password:


passwd: all authentication tokens updated successfully.
[root@cent61 ~]#

2. Download and Install Nagios Plugins


from http://www.nagios.org/download/download.php
[root@cent61 ~]# mkdir -p /opt/Nagios
[root@cent61 ~]# cd /opt/Nagios/
[root@cent61 Nagios]#

Save file to directory /opt/Nagios. As of this writing Nagios 3.3.1 (Stable) and Nagios Plugins
1.4.15 (Stable)

Extract Files:
[root@cent61 Nagios]# tarxvf nagios-plugins-1.4.15.tar.gz
[root@cent61 Nagios]# ll
total 2456
drwxrwxrwx. 16 501 root
4096 Jul 28 2010 nagios-plugins-1.4.15
-rw-r--r--. 1 root root 2095419 Dec 14 14:57 nagios-plugins-1.4.15.tar.gz
-rw-r--r--. 1 root root 411768 Jan 29 14:02 nrpe-2.13.tar.gz
[root@cent61 Nagios]# cd nagios-plugins-1.4.15
[root@cent61 nagios-plugins-1.4.15]#

3. Compile and Configure Nagios Plugins


You need the openssl-devel,GCC compiler and GD development libraries package installed to
compile plugins with ssl support.
March 1, 2012

By Vannath KANN

Page 20 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

[root@cent61 nagios-plugins-1.4.15]# yum install openssl-devel


[root@cent61 nagios-plugins-1.4.15]# yum install gccglibcglibc-common
[root@cent61 nagios-plugins-1.4.15]# yum install gdgd-devel

Install Plugin:
[root@cent61 nagios-plugins-1.4.15]# ./configure --with-nagios-user=nagios -with-nagios-group=nagios
[root@cent61 nagios-plugins-1.4.15]# make
[root@cent61 nagios-plugins-1.4.15]# make install

The permissions on the plugin directory and the plugins will need to be changed to nagios user
[root@cent61 nagios-plugins-1.4.15]# chownnagios.nagios /usr/local/nagios/
[root@cent61 nagios-plugins-1.4.15]# chown -R nagios.nagios
/usr/local/nagios/libexec/
[root@cent61 nagios-plugins-1.4.15]#

Package xinted is needed


[root@cent61 nagios-plugins-1.4.15]# yum install xinetd

4. Download and Install NRPE Daemon


As of this writing NRPE 2.13 (Stable)
Extract the Files:
[root@cent61 Nagios]# tar xvf nrpe-2.13.tar.gz
[root@cent61 Nagios]# ll
total 2460
drwxrwxrwx. 16
501 root
4096 Feb 2 19:32 nagios-plugins-1.4.15
-rw-r--r--. 1 root
root
2095419 Dec 14 14:57 nagios-plugins-1.4.15.tar.gz
drwxr-xr-x. 8 nagiosnagios
4096 Nov 12 01:50 nrpe-2.13
-rw-r--r--. 1 root
root
411768 Jan 29 14:02 nrpe-2.13.tar.gz
[root@cent61 Nagios]# cd nrpe-2.13

5. Compile and configure NRPE


[root@cent61 nrpe-2.13]# ./configure
*** Configuration summary for nrpe 2.13 11-11-2011 ***:
General Options:
------------------------NRPE port:
5666
NRPE user:
nagios
NRPE group:
nagios
Nagios user: nagios
Nagios group: nagios

March 1, 2012

By Vannath KANN

Page 21 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

Review the options above for accuracy. If they look okay,


type 'make all' to compile the NRPE daemon and client.
[root@cent61
[root@cent61
[root@cent61
[root@cent61
[root@cent61
[root@cent61

nrpe-2.13]#
nrpe-2.13]#
nrpe-2.13]#
nrpe-2.13]#
nrpe-2.13]#
nrpe-2.13]#

make
make
make
make
make

all
install-plugin
install-daemon
install-daemon-config
install-xinetd

6. Post NRPE Configuration


Edit Xinetd NRPE entry:
Add Nagios Monitoring server to the only_from directive
[root@cent61 nrpe-2.13]# vim /etc/xinetd.d/nrpe
# default: on
# description: NRPE (Nagios Remote Plugin Executor)
servicenrpe
{
flags
= REUSE
socket_type
= stream
port
= 5666
wait
= no
user
= nagios
group
= nagios
server
= /usr/local/nagios/bin/nrpe
server_args
= -c /usr/local/nagios/etc/nrpe.cfg --inetd
log_on_failure += USERID
disable
= no
only_from
= 127.0.0.1 192.168.10.1
}

Edit services file entry ,Add entry for nrpe daemon


[root@cent61 nrpe-2.13]# vim /etc/services
sfmsso
5635/tcp
# SFM Authentication Subsystem
sfm-db-server
5636/tcp
# SFMdb - SFM DB server
nrpe5666/tcp# NRPE
amqps
5671/tcp
# amqp protocol over TLS/SSL

Restart Xinetd and Set to start at boot:

March 1, 2012

By Vannath KANN

Page 22 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

[root@cent61 nrpe-2.13]# chkconfigxinetd on


[root@cent61 nrpe-2.13]# servicexinetd restart
Stopping xinetd:
Starting xinetd:
[root@cent61 nrpe-2.13]#

[
[

OK
OK

]
]

7. Test NRPE Daemon Install


Check NRPE daemon is running and listening on port 5666: Output should be: as here
[root@cent61 nrpe-2.13]# netstat -at | grepnrpe
tcp
0
0 *:nrpe
*:*
[root@cent61 nrpe-2.13]#

LISTEN

Check NRPE daemon is functioning: Output should be NRPE version:


[root@cent61 nrpe-2.13]# /usr/local/nagios/libexec/check_nrpe -H localhost
NRPE v2.13
[root@cent61 nrpe-2.13]#

8. Open Port 5666 on Firewall


Make sure to open port 5666 on the firewall of the remote server so that the Nagios monitoring
server can access the NRPE daemon.

3.4.

SetupNagios Monitoring Host Server

1. Downlad and Install NRPE Plugin


From http://www.nagios.org/download/download.php
As of this writing NRPE 2.13 (Stable)
Save file to directory /opt/NagiosCore3.3
[root@cent60 NagiosCore3.3]# ll
total 4136
drwxr-xr-x. 16 nagiosnagios
4096 Feb
-rw-r--r--. 1 root
root
1714630 Dec
drwxrwxrwx. 16 nagios root
4096 Feb
-rw-r--r--. 1 root
root
2095419 Dec
-rw-r--r--. 1 root
root
411768 Jan
[root@cent60 NagiosCore3.3]#

1 23:08 nagios
14 14:56 nagios-3.3.1.tar.gz
2 00:09 nagios-plugins-1.4.15
14 14:57 nagios-plugins-1.4.15.tar.gz
29 14:02 nrpe-2.13.tar.gz

Extract the Files:


[root@cent60 NagiosCore3.3]# tar xvf nrpe-2.13.tar.gz
[root@cent60 NagiosCore3.3]# cd nrpe-2.13

2. Compile and Configure NRPE


March 1, 2012

By Vannath KANN

Page 23 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

You need the openssl-devel package installed to compile NRPE with ssl support.
[root@cent60 nrpe-2.13]# yum install openssl-devel
[root@cent60 nrpe-2.13]# ./configure
*** Configuration summary for nrpe 2.13 11-11-2011 ***:
General Options:
------------------------NRPE port:
5666
NRPE user:
nagios
NRPE group:
nagios
Nagios user: nagios
Nagios group: nagios

Review the options above for accuracy. If they look okay,


type 'make all' to compile the NRPE daemon and client.
[root@cent60 nrpe-2.13]# make all
[root@cent60 nrpe-2.13]# make install-plugin

3. Test Connection to NRPE daemon on Remote Server

Lets now make sure that the NRPE on our Nagios server can talk to the NRPE daemon on the
remote server we want to monitor. Replace <IP of Remote Server> with the remote servers IP
address.
[root@cent60 nrpe-2.13]# /usr/local/nagios/libexec/check_nrpe -H 192.168.10.2
NRPE v2.13
[root@cent60 nrpe-2.13]#

If you encounter a problem check firewall on the remote Server.


[root@cent60 nrpe-2.13]# /usr/local/nagios/libexec/check_nrpe -H 192.168.10.2
Connection refused or timed out
[root@cent60 nrpe-2.13]#

Make sure that the firewall is disable on the remote linux Server
[root@cent61 nrpe-2.13]# system-config-firewall-tui
Firewall Configuration

A firewall protects against unauthorized

March 1, 2012

By Vannath KANN

Page 24 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

network intrusions. Enabling a firewall blocks


all incoming connections. Disabling a firewall
allows all connections and is not recommended.

Firewall: [ ] Enabled

OK
Customize
Cancel

4. Create NRPE Command Definition

A command definition needs to be created in order for the check_nrpe plugin to be used by
nagios. Add the following:
[root@cent60 nrpe-2.13]# vim /usr/local/nagios/etc/objects/commands.cfg
##################################################################################
#
NRPE CHECK COMMAND
#
#
Command to use NRPE to check remote host systems
##################################################################################
define command{
command_namecheck_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}

D
5. Create Linux Object template

In order to be able to add the remote linux machine to Nagios we need to create an object
template file adn add some object definitions.
Create new linux-box-remote object template file:
[root@cent60 nrpe-2.13]# vim /usr/local/nagios/etc/objects/linux-box-remote.cfg

Add the following and replace the values host_name alias address with the values that
match your setup:
The host_name you set for the define_host section must match the host_name in the
define_service section
March 1, 2012

By Vannath KANN

Page 25 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

define host{
namelinux-box-remote
; Name of this template
use
generic-host
; Inherit default values
check_period
24x7
check_interval
5
retry_interval
1
max_check_attempts
10
check_command
check-host-alive
notification_period
24x7
notification_interval 30
notification_optionsd,r
contact_groups
admins
register
0
; DONT REGISTER THIS - ITS A TEMPLATE
}
define host{
uselinux-box-remote
; Inherit default values from a template
host_name Cent61
; The name we're giving to this server
alias
Cent61 ; A longer name for the server
address
192.168.10.2
; IP address of the server
}
define service{
use
generic-service
host_name
Cent61
service_description CPU Load
check_commandcheck_nrpe!check_load
}
define service{
use
generic-service
host_name
Cent61
service_description Current Users
check_commandcheck_nrpe!check_users
}
define service{
use
generic-service
host_name
Cent61
service_description /dev/hda1 Free Space
check_command
check_nrpe!check_hda1
}
March 1, 2012

By Vannath KANN

Page 26 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

define service{
use
generic-service
host_name
Cent61
service_description Total Processes
check_commandcheck_nrpe!check_total_procs
}
define service{
use
generic-service
host_name
Cent61
service_description Zombie Processes
check_commandcheck_nrpe!check_zombie_procs

Activate the linux-box-remote.cfg template:


[root@cent60 ~]# vim /usr/local/nagios/etc/nagios.cfg
####### Definitions for monitoring remote Linux machine #########
cfg_file=/usr/local/nagios/etc/objects/linux-box-remote.cfg
################

Verify Nagios Configuration Files


[root@cent60 ~]# /usr/local/nagios/bin/nagios -v
/usr/local/nagios/etc/nagios.cfg
Checking obsessive compulsive processor commands...
Checking misc settings...
Total Warnings: 0
Total Errors:
0
Things look okay - No serious problems were detected during the pre-flight
check
[root@cent60 ~]#

Restart Nagios:
[root@cent60 ~]# servicenagios restart
Running configuration check...done.
Stopping nagios: done.
Starting nagios: done.
[root@cent60 ~]#
March 1, 2012

By Vannath KANN

Page 27 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

Check Nagios Monitoring server that the remote linux box was added and is being monitored !

6. Trouble Shooting
On Status Information you will encounter error message DISK CRITICAL - /dev/hda1 is not
accessible: No such file or directory

March 1, 2012

By Vannath KANN

Page 28 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

Solution you need you check you systems hard disk architecture on the remote server
[root@cent61 ~]# df -h
FilesystemSize Used Avail Use% Mounted on
/dev/sda2
9.9G 382M 9.0G
4%
tmpfs
504M
0 504M
0%
/dev/sda1
97M
24M
69M 26%
/dev/sda5
3.9G 973M 2.7G 27%
/dev/sr0
4.4G 4.4G
0 100%
[root@cent61 ~]#

/
/dev/shm
/boot
/usr
/mnt/iso/dvd

As you can the systems hard disk architecture is sda not hda so change it to fix this.
[root@cent61 ~]# vim /usr/local/nagios/etc/nrpe.cfg
#command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p
/dev/hda1
command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% p/dev/sda2

OK now the problem is fixed

March 1, 2012

By Vannath KANN

Page 29 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

You see on Service manu it display /dev/hda1 it is not really on exactly systems Change
command to the right one. This is done on the remote server
[root@cent61 ~]# vim /usr/local/nagios/etc/nrpe.cfg
#command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p
/dev/hda1
command[check_disk_root]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p
/dev/sda2

And thenon Nagios Server change as the following


[root@cent60 objects]# pwd
/usr/local/nagios/etc/objects
[root@cent60 objects]# vimlinux-box-remote.cfg
define service{
use
generic-service
host_name
Cent61
#
service_description /dev/hda1 Free Space
#
check_command
check_nrpe!check_hda1
service_description Root Partition
check_commandcheck_nrpe!check_disk_root
}

Then restart nagios service


[root@cent60 objects]# servicenagios restart
Running configuration check...done.

March 1, 2012

By Vannath KANN

Page 30 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

Stopping nagios: done.


Starting nagios: done.
[root@cent60 objects]#

Atfter that is should look as the following

3.5.

Customizing Your Configuration


You'll might want to monitor more services on the remote Linux/Unix box than those that are
described in thisdocumentation. This is easy to accomplish
Anytime you want to monitor a new service on a remote host using the NRPE addon, you have
to do two things:
Add a new command definition to the nrpe.cfg file on the remote host
Add a new service definition to your Nagios configuration on the monitoring
host
Let's say you want to monitor the swap usage on the remote Linux/Unix host. Here are the steps
you'd need tofollow...

3.5.1. Remote Host Configuration

You can use the check_swap plugin to monitor swap usage on the machine. Assuming you
followed theinstallation instructions in this document, the check_swap plugin should already be
installed in/usr/local/nagios/libexec
March 1, 2012

By Vannath KANN

Page 31 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

Login as the nagios user on the remote host.


Run the check_swap plugin manually and tweak the command line options to specify the
desired warning andcritical free swap space thresholds. Make sure the full command line
returns the expected output you want fromthe plugin. For this example, let's say you want a
critical alert if swap free space is less than 10% and a warning iffree space is less than 20%.
Here's the command line that would accomplish that:
[root@cent61 etc]# /usr/local/nagios/libexec/check_swap -w 20% -c 10%
SWAP OK - 100% free (1023 MB out of 1023 MB) |swap=1023MB;204;102;0;1023
[root@cent61 etc]#

Now that you know the command line that should be execute, open the NRPE configuration
file.
[root@cent61 etc]# pwd
/usr/local/nagios/etc
[root@cent61 etc]# vimnrpe.cfg

Add a new check_swap command definition that uses the command line from above and save
the file.
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c
200
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%
# The following examples allow user-supplied arguments and can

If you're running the NRPE daemon as a standalone daemon you'll need to restart it. If you're
running it under theinetd/xinetdsuperserver you don't need to do anything more.
3.5.2. Monitoring Host Configuration

On the monitoring host, you need to define a new service for monitoring the swap usage on the
remote host. Addthe following entry to one of your object configuration files
define service{
use
generic-service
host_name
Cent62
service_description Swap Partition
check_commandcheck_nrpe!check_swap
}.

Notice that the check commands is passing check_swap to check_nrpe command definition.
This will cause the NRPE daemon to run the check_swap command that was definded in the
nrpe.cfg file on the remote host in the previous step.
March 1, 2012

By Vannath KANN

Page 32 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

Next, verify your Nagios configuration files and restart Nagios.


[root@cent60 etc]# /usr/local/nagios/bin/nagios -v
/usr/local/nagios/etc/nagios.cfg
Checking misc settings...
Total Warnings: 0
Total Errors:
0
Things look okay - No serious problems were detected during the pre-flight
check
[root@cent60 etc]#
[root@cent60 etc]# servicenagios restart
Running configuration check...done.
Stopping nagios: done.
Starting nagios: done.
[root@cent60 etc]#

Thats it! You are now monitoring a new service on the remote host using the NRPE addon

3.6.

NRPE Option Help


For more option about NRPE you can use -h when executed NRPE script

[root@cent61 libexec]# cd /usr/local/nagios/libexec/


[root@cent61 libexec]# ls

March 1, 2012

By Vannath KANN

Page 33 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

check_aptcheck_flexlmcheck_mailqcheck_oraclecheck_ssmtp
check_breezecheck_ftpcheck_mrtgcheck_overcrcheck_swap
check_by_sshcheck_httpcheck_mrtgtrafcheck_pingcheck_tcp
check_clamdcheck_icmpcheck_nagioscheck_popcheck_time
check_clustercheck_ide_smartcheck_nntpcheck_procscheck_udp
check_dhcpcheck_ifoperstatuscheck_nntpscheck_realcheck_ups
check_digcheck_ifstatuscheck_nrpecheck_rpccheck_users
check_diskcheck_imapcheck_ntcheck_sensorscheck_wave
check_disk_smbcheck_ircdcheck_ntpcheck_simap
negate
check_dnscheck_jabbercheck_ntp_peercheck_smtpurlize
check_dummycheck_loadcheck_ntp_timecheck_spop
utils.pm
check_file_agecheck_logcheck_nwstatcheck_ssh
utils.sh
[root@cent61 libexec]#
[root@cent61 libexec]# ./check_dhcp -h
check_dhcp v1.4.15 (nagios-plugins 1.4.15)
Copyright (c) 2001-2004 Ethan Galstad (nagios@nagios.org)
Copyright (c) 2001-2007 Nagios Plugin Development Team
<nagiosplug-devel@lists.sourceforge.net>
This plugin tests the availability of DHCP servers on a network.

Usage:
check_dhcp [-v] [-u] [-s serverip] [-r requestedip] [-t timeout]
[-i interface] [-m mac]
Options:
-h, --help
Print detailed help screen
-V, --version
Print version information
-v, --verbose
Show details for command-line debugging (Nagios may truncate output)
-s, --serverip=IPADDRESS
IP address of DHCP server that we must hear from
-r, --requestedip=IPADDRESS
IP address that should be offered by at least one DHCP server
-t, --timeout=INTEGER
Seconds to wait for DHCPOFFER before timeout occurs
-i, --interface=STRING
Interface to to use for listening (i.e. eth0)
-m, --mac=STRING
March 1, 2012

By Vannath KANN

Page 34 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

MAC address to use in the DHCP request


-u, --unicast
Unicast testing: mimic a DHCP relay, requires -s
Send email to nagios-users@lists.sourceforge.net if you have questions
regarding use of this software. To submit patches or suggest improvements,
send email to nagiosplug-devel@lists.sourceforge.net
[root@cent61 libexec]#

4. How to monitor a Windows machine


4.1.

Introduction
This document describes how you can monitor "private" services and attributes of Windows
machines, such as:

Memory usage
CPU load
Disk usage
Service states
Running processes
etc.

Publicly available services that are provided by Windows machines (HTTP, FTP, POP3, etc.)
can be monitored easily by following the documentation on monitoring publicly available
services.

4.2.

Overview
Monitoring private services or attributes of a Windows machine requires that you install an
agent on it. This agent acts as a proxy between the Nagios plugin that does the monitoring and
the actual service or attribute of the Windows machine. Without installing an agent on the
Windows box, Nagios would be unable to monitor private services or attributes of the Windows
box.
For this example, we will be installing the NSClient++ (http://sourceforge.net/projects/nscplus/)
addon on the Windows machine and using the check_nt plugin to communicate with the
NSClient++ addon. The check_nt plugin should already be installed on the Nagios server if you
followed the quickstart guide.

March 1, 2012

By Vannath KANN

Page 35 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

The NSClient++ agent must be installed on the target Windows machine and configured before
Nagios can monitor system metrics, services, processes, or performance data on the target
machine

4.3.

What's Already Done For You


To make your life a bit easier, a few configuration tasks have already been done for you:
A check_nt command definition has been added to the commands.cfg file. This allows you
to use the check_nt plugin to monitor Window services.
A Windows server host template (called windows-server) has already been created in the
templates.cfg file. This allows you to add new Windows host definitions in a simple
manner.
The above-mentioned config files can be found in the /usr/local/nagios/etc/objects/ directory.
You can modify the definitions in these and other definitions to suit your needs better if you'd
like. However, I'd recommend waiting until you're more familiar with configuring Nagios
before doing so. For the time being, just follow the directions outlined below and you'll be
monitoring your Windows boxes in no time.

4.4.

Prerequisites
The first time you configure Nagios to monitor a Windows machine, you'll need to do a bit of
extra work. Remember, you only need to do this for the *first* Windows machine you monitor.
Edit the main Nagios config file.

[root@cent60 ~]# vim /usr/local/nagios/etc/nagios.cfg

Remove the leading pound (#) sign from the following line in the main configuration file:
# Definitions for monitoring a Windows machine
cfg_file=/usr/local/nagios/etc/objects/windows.cfg

Save the file and exit.


March 1, 2012

By Vannath KANN

Page 36 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

What did you just do? You told Nagios to look to the /usr/local/nagios/etc/objects/windows.cfg
to find additional object definitions. That's where you'll be adding Windows host and service
definitions. That configuration file already contains some sample host, hostgroup, and service
definitions. For the *first* Windows machine you monitor, you can simply modify the sample
host and service definitions in that file, rather than creating new ones.

4.5.

Installing the Windows Agent


Before you can begin monitoring private services and attributes of Windows machines, you'll
need to install an agent on those machines. I recommend using the NSClient++ addon, which
can be found at http://sourceforge.net/projects/nscplus. These instructions will take you through
a basic installation of the NSClient++ addon, as well as the configuration of Nagios for
monitoring the Windows machine.
Download the NSClient++ installer package to the target machine you wish to install it on.
Run the NSClient++ MSI installer package to initiate the installation. The welcome screen will
appear. Click Next to continue to the next step

Read through the End User License Agreement. Once you have agreed to its terms, check the
acceptance box and click Next to continue.

March 1, 2012

By Vannath KANN

Page 37 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

You may customize the installation options on the next screen if you wish. No changes are
required for an working installation of the agent. Click Next to continue.

If an existing NSClient++ installation exists on the target machine, you will have the option of
using the old configuration file. This option is not enable if this is the first time you are
installing the client. Click Next to continue

March 1, 2012

By Vannath KANN

Page 38 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

In the next step you will need to configure the NSClient++ agent. These steps are important!
Make sure you:
Enter the IP address of the Nagios Core server in the Allowed hosts box.
Enter a password in the NSClient password box that will be required for
communication between the Nagios server and the Windows machine.
Check the following boxes in the Modules to load section:
Enable common check plugins
Enable nsclient server (check_nt)
Click Next to continue.

Click the Install button on the next screen to begin the installation.
March 1, 2012

By Vannath KANN

Page 39 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

When the installation completes, make sure to check the Start service option and click Finish
to complete the setup.
The NSClient++ agent will now be running as a service, which means the Windows machine is
ready to be monitored with Nagios.

4.6.

Configuring Nagios
Now it's time to define some object definitions in your Nagios configuration files in order to
monitor the new Windows machine.

March 1, 2012

By Vannath KANN

Page 40 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

Open the windows.cfg file for editing.


[root@cent60 ~]# vim /usr/local/nagios/etc/objects/windows.cfg

Add a new host definition for the Windows machine that you're going to monitor. If this is the
*first* Windows machine you're monitoring, you can simply modify the sample host definition
in windows.cfg. Change the host_name, alias, and address fields to appropriate values for the
Windows box.
# Change the host_name, alias, and address to fit your situation
define host{
use
template
host_name
alias
host
address
}

windows-server

; Inherit default values from a

w2k81
; The name we're giving to this host
Windows Server 2008; A longer name associated with the
192.168.10.3

; IP address of the host

Good. Now you can add some service definitions (to the same configuration file) in order to tell
Nagios to monitor different aspects of the Windows machine. If this is the *first* Windows
machine you're monitoring, you can simply modify the sample service definitions in
windows.cfg.
Note: Replace "w2k81" in the example definitions below with the name you specified in the
host_name directive of the host definition you just added.
Add the following service definition to monitor the version of the NSClient++ addon that is
running on the Windows server. This is useful when it comes time to upgrade your Windows
servers to a newer version of the addon, as you'll be able to tell which Windows machines still
need to be upgraded to the latest version of NSClient++.
define service{
use
#
host_name
host_name
service_description
check_command
}

generic-service
winserver
w2k81
NSClient++ Version
check_nt!CLIENTVERSION

Add the following service definition to monitor the uptime of the Windows server.

March 1, 2012

By Vannath KANN

Page 41 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

define service{
use
#
host_name
host_name
service_description
check_command
}

generic-service
winserver
w2k81
Uptime
check_nt!UPTIME

Add the following service definition to monitor the CPU utilization on the Windows server and
generate a CRITICAL alert if the 5-minute CPU load is 90% or more or a WARNING alert if
the 5-minute load is 80% or greater.
define service{
use
#
host_name
host_name
service_description
check_command
}

generic-service
winserver
w2k81
CPU Load
check_nt!CPULOAD!-l 5,80,90

Add the following service definition to monitor memory usage on the Windows server and
generate a CRITICAL alert if memory usage is 90% or more or a WARNING alert if memory
usage is 80% or greater.
define service{
use
#
host_name
host_name
service_description
check_command
}

generic-service
winserver
w2k81
Memory Usage
check_nt!MEMUSE!-w 80 -c 90

Add the following service definition to monitor usage of the C:\ drive and D:\drive on the
Windows server and generate a CRITICAL alert if disk usage is 90% or more or a WARNING
alert if disk usage is 80% or greater.
define service{
use
#
host_name
host_name
service_description
check_command
}

March 1, 2012

generic-service
winserver
w2k81
C:\ Drive Space
check_nt!USEDDISKSPACE!-l c -w 80 -c 90

By Vannath KANN

Page 42 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

define service{
use
#
host_name
host_name
service_description
check_command
}

generic-service
winserver
w2k81
D:\ Drive Space
check_nt!USEDDISKSPACE!-l d -w 80 -c 90

Add the following service definition to monitor the W3SVC service state on the Windows
machine and generate a CRITICAL alert if the service is stopped.
define service{
use
#
host_name
host_name
service_description
check_command
}

generic-service
winserver
w2k81
W3SVC
check_nt!SERVICESTATE!-d SHOWALL -l W3SVC

Add the following service definition to monitor the Explorer.exe process on the Windows
machine and generate a CRITICAL alert if the process is not running.
define service{
use
#
host_name
host_name
service_description
check_command
}

generic-service
winserver
w2k81
Explorer
check_nt!PROCSTATE!-d SHOWALL -l Explorer.exe

That's it for now. You've added some basic services that should be monitored on the Windows
box. Save the configuration file.

4.7.

Password Protection
If you specified a password in the NSClient++ configuration file on the Windows machine,
you'll need to modify the check_nt command definition to include the password. Open the
commands.cfg file for editing.

[root@cent60 ~]# vim /usr/local/nagios/etc/objects/commands.cfg


[root@cent60 ~]#

Change the definition of the check_nt command to include the "-s <PASSWORD>" argument
(where PASSWORD is the password you specified on the Windows machine) like this:
March 1, 2012

By Vannath KANN

Page 43 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

# 'check_nt' command definition


define command{
command_name
check_nt
command_line
$USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -s 1234567 v $ARG1$ $ARG2$
}

Save the file.

4.8.

Restarting Nagios

You're done with modifying the Nagios configuration, so you'll need to verify your
configuration files and restart Nagios.
If the verification process produces any errors messages, fix your configuration file before
continuing. Make sure that you don't (re)start Nagios until the verification process completes
without any errors!
[root@cent60 ~]# /usr/local/nagios/bin/nagios -v
/usr/local/nagios/etc/nagios.cfg
Checking misc settings...
Total Warnings: 0
Total Errors:
0
Things look okay - No serious problems were detected during the pre-flight
check
[root@cent60 ~]#
[root@cent60 ~]# service nagios restart
Running configuration check...done.
Stopping nagios: done.
Starting nagios: done.
[root@cent60 ~]#

Ok now we monitor it !

March 1, 2012

By Vannath KANN

Page 44 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

5. How to monitor a router/switch


5.1.

Introduction
This document describes how you can monitor the status of network switches and routers. Some
cheaper "unmanaged" switches and hubs don't have IP addresses and are essentially invisible on
your network, so there's not any way to monitor them. More expensive switches and routers
have addresses assigned to them and can be monitored by pinging them or using SNMP to
query status information.
I'll describe how you can monitor the following things on managed
switches, hubs, and routers:
Packet loss, round trip average
SNMP status information
Bandwidth / traffic rate

5.2.

Overview
Monitoring switches and routers can either be easy or more involved - depending on what
equipment you have and what you want to monitor. As they are critical infrastructure
components, you'll no doubt want to monitor them in at least some basic manner.
Switches and routers can be monitored easily by "pinging" them to determine packet loss, RTA,
etc. If your switch supports SNMP, you can monitor port status, etc. with the check_snmp
plugin and bandwidth (if you're using MRTG) with the check_mrtgtraf plugin.

March 1, 2012

By Vannath KANN

Page 45 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

The check_snmp plugin will only get compiled and installed if you have the net-snmp and netsnmp-utils packages installed on your system. Make sure the plugin exists in
/usr/local/nagios/libexec before you continue. If it doesn't, install net-snmp and net-snmp-utils
and recompile/reinstall the Nagios plugins.

5.3.

Steps
There are several steps you'll need to follow in order to monitor a new router or switch. They
are:
Perform first-time prerequisites
Create new host and service definitions for monitoring the device
Restart the Nagios daemon

5.4.

What's Already Done For You


To make your life a bit easier, a few configuration tasks have already been done for you:
Two command definitions (check_snmp and check_local_mrtgtraf) have been added to
the commands.cfg file. These allows you to use the check_snmp and check_mrtgtraf
plugins to monitor network routers.
A switch host template (called generic-switch) has already been created in the
templates.cfg file. This allows you to add new router/switch host definitions in a simple
manner.
The above-mentioned config files can be found in the /usr/local/nagios/etc/objects/ directory.
You can modify the definitions in these and other definitions to suit your needs better if you'd
like. However, I'd recommend waiting until you're more familiar with configuring Nagios

March 1, 2012

By Vannath KANN

Page 46 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

before doing so. For the time being, just follow the directions outlined below and you'll be
monitoring your network routers/switches in no time.

5.5.

Prerequisites
The first time you configure Nagios to monitor a network switch, you'll need to do a bit of extra
work. Remember, you only need to do this for the *first* switch you monitor.
Edit the main Nagios config file.

[root@cent60 etc]# vim /usr/local/nagios/etc/nagios.cfg


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

Save the file and exit.


What did you just do? You told Nagios to look to the /usr/local/nagios/etc/objects/switch.cfg to
find additional object definitions. That's where you'll be adding host and service definitions for
routers and switches. That configuration file already contains some sample host, hostgroup, and
service definitions. For the *first* router/switch you monitor, you can simply modify the
sample host and service definitions in that file, rather than creating new ones.

5.6.

Configuring Nagios
You'll need to create some object definitions in order to monitor a new router/switch.
Open the switch.cfg file for editing.

[root@cent60 etc]# vim /usr/local/nagios/etc/objects/switch.cfg

Add a new host definition for the switch that you're going to monitor. If this is the *first* switch
you're monitoring, you can simply modify the sample host definition in switch.cfg. Change the
host_name, alias, and address fields to appropriate values for the switch.
# Define the switch that we'll be monitoring
define host{
use
generic-switch ; Inherit default values from a template
#
host_name
linksys-srw224p ; The name we're giving to this switch
host_name
icteo-sw01
; The name we're giving to this switch
alias
ICTEO Switch 01 ; A longer name associated with the
switch
address
192.168.10.10 ; IP address of the switch
hostgroups
switches
; Host groups this switch is associated with
}
March 1, 2012

By Vannath KANN

Page 47 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

5.7.

Monitoring Services
Now you can add some service definitions (to the same configuration file) to monitor different
aspects of the switch. If this is the *first* switch you're monitoring, you can simply modify the
sample service definition in switch.cfg.
Note: Replace "linksys-srw224p" in the example definitions below with the name you specified
in the host_name directive of the host definition you just added.

5.8.

Monitoring Packet Loss and RTA


Add the following service definition in order to monitor packet loss and round trip average
between the Nagios host and the switch every 5 minutes under normal conditions.

# Create a service to PING to switch


define service{
use
generic-service ; Inherit values from a template
#
host_name
linksys-srw224p ; The name of the host the
service is associated with
host_name
icteo-sw01
; The name we're giving to this switch
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
}

This service will be:


CRITICAL if the round trip average (RTA) is greater than 600 milliseconds or the
packet loss is 60% or more
WARNING if the RTA is greater than 200 ms or the packet loss is 20% or more
OK if the RTA is less than 200 ms and the packet loss is less than 20%

5.9.

Monitoring SNMP Status Information


If your switch or router supports SNMP, you can monitor a lot of information by using the
check_snmp plugin. If it doesn't, skip this section.
Add the following service definition to monitor the uptime of the switch.

March 1, 2012

By Vannath KANN

Page 48 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

# Monitor uptime via SNMP


define service{
use
generic-service ; Inherit values from a template
#
host_name
linksys-srw224p
host_name
icteo-sw01
; The name we're giving to this switch
service_description
Uptime
check_command
check_snmp!-C public -o sysUpTime.0
}

In the check_command directive of the service definition above, the "-C public" tells the plugin
that the SNMP community name to be used is "public" and the "-o sysUpTime.0" indicates
which OID should be checked.
f you want to ensure that a specific port/interface on the switch is in an up state, you could add a
service definition like this:
if you want to ensure that a specific port/interface on the switch is in an up state, you could add
a service definition like this:
# Monitor Port 1 status via SNMP
define service{
use
generic-service ; Inherit values from a template
#
host_name
linksys-srw224p
host_name
icteo-sw01
; The name we're giving to this switch
service_description
Port 1 Link Status
check_command
check_snmp!-C public -o ifOperStatus.1 -r 1 -m
RFC1213-MIB
}

In the example above, the "-o ifOperStatus.1" refers to the OID for the operational status of port
1 on the switch. The "-r 1" option tells the check_snmp plugin to return an OK state if "1" is
found in the SNMP result (1 indicates an "up" state on the port) and CRITICAL if it isn't found.
The "-m RFC1213-MIB" is optional and tells the check_snmp plugin to only load the
"RFC1213-MIB" instead of every single MIB that's installed on your system, which can help
speed things up.
That's it for the SNMP monitoring example. There are a million things that can be monitored
via SNMP, so its up to you to decide what you need and want to monitor. Good luck!
Tip: You can usually find the OIDs that can be monitored on a switch by running the following
command (replace 192.168.10.10 with the IP address of the switch): snmpwalk -v1 -c public
192.168.1.253 -m ALL .1

5.10. Monitoring Bandwidth / Traffic Rate

March 1, 2012

By Vannath KANN

Page 49 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

If you're monitoring bandwidth usage on your switches or routers using MRTG, you can have
Nagios alert you when traffic rates exceed thresholds you specify. The check_mrtgtraf plugin
(which is included in the Nagios plugins distribution) allows you to do this.
You'll need to let the check_mrtgtraf plugin know what log file the MRTG data is being stored
in, along with thresholds, etc. In my example, I'm monitoring one of the ports on a Linksys
switch. The MRTG log file is stored in /var/lib/mrtg/192.168.1.253_1.log. Here's the service
definition I use to monitor the bandwidth data that's stored in the log file...
# Monitor bandwidth via MRTG logs
define service{
use
generic-service ; Inherit values from a template
#
host_name
linksys-srw224p
host_name
icteo-sw01
; The name we're giving to this switch
service_description
Port 1 Bandwidth Usage
check_command
check_local_mrtgtraf!/var/lib/mrtg/192.168.10.10_1.log!AVG!1000000,1000000!5000000
,5000000!10
}

In the example above, the "/var/lib/mrtg/192.168.10.10_1.log" option that gets passed to the
check_local_mrtgtraf command tells the plugin which MRTG log file to read from. The "AVG"
option tells it that it should use average bandwidth statistics. The "1000000,2000000" options
are the warning thresholds (in bytes) for incoming traffic rates. The "5000000,5000000" are
critical thresholds (in bytes) for outgoing traffic rates. The "10" option causes the plugin to
return a CRITICAL state if the MRTG log file is older than 10 minutes (it should be updated
every 5 minutes).
Save the file.

5.11. Restarting Nagios


Once you've added the new host and service definitions to the switch.cfg file, you're ready to
start monitoring the router/switch. To do this, you'll need to verify your configuration and
restart Nagios.
If the verification process produces any errors messages, fix your configuration file before
continuing. Make sure that you don't (re)start Nagios until the verification process completes
without any errors!
[root@cent60 etc]# /usr/local/nagios/bin/nagios -v
/usr/local/nagios/etc/nagios.cfg
Checking misc settings...

March 1, 2012

By Vannath KANN

Page 50 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

Total Warnings: 0
Total Errors:
0
Things look okay - No serious problems were detected during the pre-flight
check
[root@cent60 etc]#

6. How to monitor a network printer


6.1.

Introduction
This document describes how you can monitor the status of networked printers. Specifically,
HP printers that have internal/external JetDirect cards/devices, or other print servers (like the
Troy PocketPro 100S or the Netgear PS101) that support the JetDirect protocol.
The check_hpjd plugin (which is part of the standard Nagios plugins distribution) allows you to
monitor the status of JetDirect-capable printers which have SNMP enabled. The plugin is
capable of detecting the following printer states:

6.2.

Paper Jam
Out of Paper
Printer Offline
Intervention Required
Toner Low
Insufficient Memory
Open Door
Output Tray is Full
and more...

Overview
Monitoring the status of a networked printer is pretty simple. JetDirect-enabled printers usually
have SNMP enabled, which allows Nagios to monitor their status using the check_hpjd plugin
The check_hpjd plugin will only get compiled and installed if you have the net-snmp and netsnmp-utils packages installed on your system. Make sure the plugin exists in
/usr/local/nagios/libexec before you continue. If it doesn't, install net-snmp and net-snmp-utils
and recompile/reinstall the Nagios plugins.

March 1, 2012

By Vannath KANN

Page 51 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

6.3.

Steps
There are several steps you'll need to follow in order to monitor a new network printer. They
are:
Perform first-time prerequisites
Create new host and service definitions for monitoring the printer
Restart the Nagios daemon

6.4.

What's Already Done For You


To make your life a bit easier, a few configuration tasks have already been done for you:
A check_hpjd command definition has been added to the commands.cfg file. This
allows you to use the check_hpjd plugin to monitor network printers.
A printer host template (called generic-printer) has already been created in the
templates.cfg file. This allows you to add new printer host definitions in a simple
manner.
The above-mentioned config files can be found in the /usr/local/nagios/etc/objects/ directory.
You can modify the definitions in these and other definitions to suit your needs better if you'd
like. However, I'd recommend waiting until you're more familiar with configuring Nagios
before doing so. For the time being, just follow the directions outlined below and you'll be
monitoring your network printers in no time

6.5.

Prerequisites
The first time you configure Nagios to monitor a network printer, you'll need to do a bit of extra
work. Remember, you only need to do this for the *first* printer you monitor.
Edit the main Nagios config file.

[root@cent60 objects]# vim /usr/local/nagios/etc/nagios.cfg

Remove the leading pound (#) sign from the following line in the main configuration file:
March 1, 2012

By Vannath KANN

Page 52 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

# Definitions for monitoring a network printer


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

Save the file and exit.


What did you just do? You told Nagios to look to the /usr/local/nagios/etc/objects/printer.cfg to
find additional object definitions. That's where you'll be adding host and service definitions for
the printer. That configuration file already contains some sample host, hostgroup, and service
definitions. For the *first* printer you monitor, you can simply modify the sample host and
service definitions in that file, rather than creating new ones.

6.6.

Configuring Nagios
You'll need to create some object definitions in order to monitor a new printer.
Open the printer.cfg file for editing.

[root@cent60 objects]# vim /usr/local/nagios/etc/objects/printer.cfg

Add a new host definition for the networked printer that you're going to monitor. If this is the
*first* printer you're monitoring, you can simply modify the sample host definition in
printer.cfg. Change the host_name, alias, and address fields to appropriate values for the printer
define host{
use
#
host_name
host_name
alias
address
hostgroups
associated with
}

generic-printer ; Inherit default values from a template


hplj2605dn
; The name we're giving to this printer
icteo-pr01
The name we're giving to this printer
ICTEO Printer 01 ;A longer name associated with the printer
192.168.10.20
; IP address of the printer
network-printers
; Host groups this printer is

Now you can add some service definitions (to the same configuration file) to monitor different
aspects of the printer. If this is the *first* printer you're monitoring, you can simply modify the
sample service definition in printer.cfg.
Note: Replace "icteo-pr01" in the example definitions below with the name you specified in the
host_name directive of the host definition you just added.
Add the following service definition to check the status of the printer. The service uses the
check_hpjd plugin to check the status of the printer every 10 minutes by default. The SNMP
community string used to query the printer is "public" in this example.
define service{
use
#
host_name
with
March 1, 2012

generic-service
; Inherit values from a template
hplj2605dn ;The name of the host the service is associated

By Vannath KANN

Page 53 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

host_name
icteo-pr01
service_description
rinter Status
; The service description
check_command
heck_hpjd!-C public ; The command used to monitor the
service
normal_check_interval
10
under normal conditions
retry_check_interval
1
until its final/hard state is determined
}

; Check the service every 10 minutes


; Re-check the service every minute

Add the following service definition to ping the printer every 10 minutes by default. This is
useful for monitoring RTA, packet loss, and general network connectivity.
#Create a service for "pinging" the printer occassionally.
monitoring RTA, packet loss, etc.

Useful for

define service{
use
generic-service
#
host_name
hplj2605dn
host_name
icteo-pr01
service_description
PING
check_command
check_ping!3000.0,80%!5000.0,100%
normal_check_interval
10
retry_check_interval
1
}

Save the file

6.7.

Restarting Nagios
Once you've added the new host and service definitions to the printer.cfg file, you're ready to
start monitoring the printer. To do this, you'll need to verify your configuration and restart
Nagios.
If the verification process produces any errors messages, fix your configuration file before
continuing. Make sure that you don't (re)start Nagios until the verification process completes
without any errors!

[root@cent60 objects]# /usr/local/nagios/bin/nagios -v


/usr/local/nagios/etc/nagios.cfg
Checking misc settings...
Total Warnings: 0
Total Errors:
0
March 1, 2012

By Vannath KANN

Page 54 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

Things look okay - No serious problems were detected during the pre-flight
check
[root@cent60 objects]#
[root@cent60 objects]# service nagios restart
Running configuration check...done.
Stopping nagios: done.
Starting nagios: done.
[root@cent60 objects]#

7. How to monitor a publicly available service (HTTP,FTP,SSH,etc.)


7.1.

Introduction
This document describes how you can monitor publicly available services, applications and
protocols. By "public" I mean services that are accessible across the network - either the local
network or the greater Internet. Examples of public services include HTTP, POP3, IMAP, FTP,
and SSH. There are many more public services that you probably use on a daily basis. These
services and applications, as well as their underlying protocols, can usually be monitored by
Nagios without any special access requirements.
Private services, in contrast, cannot be monitored with Nagios without an intermediary agent of
some kind. Examples of private services associated with hosts are things like CPU load,
memory usage, disk usage, current user count, process information, etc. These private services
or attributes of hosts are not usually exposed to external clients. This situation requires that an
intermediary monitoring agent be installed on any host that you need to monitor such
information on.
D
d

7.2.

Plugins For Monitoring Service


When you find yourself needing to monitor a particular application, service, or protocol,
chances are good that a plugin exists to monitor it. The official Nagios plugins distribution
comes with plugins that can be used to monitor a variety of services and protocols. There are
also a large number of contributed plugins that can be found in the contrib/ subdirectory of the
plugin distribution. The NagiosExchange.org website hosts a number of additional plugins that
have been written by users, so check it out when you have a chance.

March 1, 2012

By Vannath KANN

Page 55 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

If you don't happen to find an appropriate plugin for monitoring what you need, you can always
write your own. Plugins are easy to write, so don't let this thought scare you off. Read the
documentation on developing plugins for more information.
I'll walk you through monitoring some basic services that you'll probably use sooner or later.
Each of these services can be monitored using one of the plugins that gets installed as part of
the Nagios plugins distribution. Let's get started...

7.3.

Creating A Host Definition


Before you can monitor a service, you first need to define a host that is associated with the
service. You can place host definitions in any object configuration file specified by a cfg_file
directive or placed in a directory specified by a cfg_dir directive. If you have already created a
host definition, you can skip this step.
For this example, lets say you want to monitor a variety of services on a remote host. Let's call
that host linux-box-remotet. The host definition can be placed in its own file or added to an
already exiting object configuration file. Here's what the host definition for linux-box-remote
might look like:

define host{
use
template
host_name
alias
address
}

linux-box-remote

; Inherit default values from a

Cent61
; The name we're giving to this server
Cent61 ; A longer name for the server
192.168.10.2
; IP address of the server

Now that a definition has been added for the host that will be monitored, we can start defining
services that should be monitored. As with host definitions, service definitions can be placed in
any object configuration file.

7.4.

Creating Service Definitions


For each service you want to monitor, you need to define a service in Nagios that is associated
with the host definition you just created. You can place service definitions in any object
configuration file specified by a cfg_file directive or placed in a directory specified by a cfg_dir
directive.
Some example service definitions for monitoring common public service (HTTP, FTP, etc.) are
given below.

7.5.

Monitoring HTTP

March 1, 2012

By Vannath KANN

Page 56 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

Chances are you're going to want to monitor web servers at some point - either yours or
someone else's. The check_http plugin is designed to do just that. It understands the HTTP
protocol and can monitor response time, error codes, strings in the returned HTML, server
certificates, and much more.
The commands.cfg file contains a command definition for using the check_http plugin. It looks
like this:
[root@cent60 objects]# pwd
/usr/local/nagios/etc/objects
[root@cent60 objects]# vim commands.cfg
# 'check_http' command definition
define command{
command_name
check_http
command_line
$USER1$/check_http -I $HOSTADDRESS$ $ARG1$
}

A simple service definition for monitoring the HTTP service on the remotehost machine might
look like this:
[root@cent60 objects]# pwd
/usr/local/nagios/etc/objects
[root@cent60 objects]# vim linux-box-remote.cfg
define service{
use
host_name
service_description
check_command
}

generic-service
Cent61
HTTP
check_http

You will experience with HTTP deamon with warning HTTP/1.1 403 Forbidden.

March 1, 2012

By Vannath KANN

Page 57 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

Nagios is checking in the apache or HTTP Root directory , is looking for index pages .
the solution is to create index there :
[root@cent61
[root@cent61
total 0
[root@cent61
[root@cent61

~]# cd /var/www/html/
html]# ll
html]# touch index.html
html]#

Restart httpd :
[root@cent61 html]# service httpd restart
Stopping httpd:
Starting httpd
[root@cent61 html]#

[ OK ]
[ OK ]

Restart nagios :
[root@cent60 objects]# service nagios restart
Running configuration check...done.
Stopping nagios: done.
Starting nagios: done.
[root@cent60 objects]#

after 2 minutes maximum you get :

March 1, 2012

By Vannath KANN

Page 58 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

This simple service definition will monitor the HTTP service running on remotehost. It will
produce alerts if the web server doesn't respond within 10 seconds or if it returns HTTP errors
codes (403, 404, etc.). That's all you need for basic monitoring
Tip: For more advanced monitoring, run the check_http plugin manually with --help as a
command-line argument to see all the options you can give the plugin. This --help syntax works
with all of the plugins I'll cover in this document.
[root@cent60 libexec]# pwd
/usr/local/nagios/libexec
[root@cent60 libexec]#
[root@cent60 libexec]# ./check_http -h
check_http v1.4.15 (nagios-plugins 1.4.15)
Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>
Copyright (c) 1999-2008 Nagios Plugin Development Team
<nagiosplug-devel@lists.sourceforge.net>
This plugin tests the HTTP service on the specified host. It can test
normal (http) and secure (https) servers, follow redirects, search for
strings and regular expressions, check connection times, and report on
certificate expiration times.

Usage:
check_http -H <vhost> | -I <IP-address> [-u <uri>] [-p <port>]
[-w <warn time>] [-c <critical time>] [-t <timeout>] [-L] [-a auth]
[-b proxy_auth] [-f <ok|warning|critcal|follow|sticky|stickyport>]
[-e <expect>] [-s string] [-l] [-r <regex> | -R <case-insensitive
regex>]
March 1, 2012

By Vannath KANN

Page 59 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

[-P string] [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>]


[-A string] [-k string] [-S] [--sni] [-C <age>] [-T <content-type>]
[-j method]
NOTE: One or both of -H and -I must be specified
Options:
-h, --help
Print detailed help screen
-V, --version
Print version information
-H, --hostname=ADDRESS
Host name argument for servers using host headers (virtual host)
Append a port to include it in the header (eg: example.com:5000)
-I, --IP-address=ADDRESS
IP address or name (use numeric address if possible to bypass DNS lookup).
-p, --port=INTEGER
Port number (default: 80)
-4, --use-ipv4
Use IPv4 connection
-6, --use-ipv6
Use IPv6 connection
-e, --expect=STRING
Comma-delimited list of strings, at least one of them is expected in
the first (status) line of the server response (default: HTTP/1.)
If specified skips all other status line logic (ex: 3xx, 4xx, 5xx
processing
)
-s, --string=STRING
String to expect in the content
-u, --url=PATH
URL to GET or POST (default: /)
-P, --post=STRING
URL encoded http POST data
-j, --method=STRING (for example: HEAD, OPTIONS, TRACE, PUT, DELETE)
Set HTTP method.
-N, --no-body
Don't wait for document body: stop reading after headers.
(Note that this still does an HTTP GET or POST, not a HEAD.)
-M, --max-age=SECONDS
Warn if document is more than SECONDS old. the number can also be of
the form "10m" for minutes, "10h" for hours, or "10d" for days.
-T, --content-type=STRING
March 1, 2012

By Vannath KANN

Page 60 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

specify Content-Type header media type when POSTing


-l, --linespan
Allow regex to span newlines (must precede -r or -R)
-r, --regex, --ereg=STRING
Search page for regex STRING
-R, --eregi=STRING
Search page for case-insensitive regex STRING
--invert-regex
Return CRITICAL if found, OK if not
-a, --authorization=AUTH_PAIR
Username:password on sites with basic authentication
-b, --proxy-authorization=AUTH_PAIR
Username:password on proxy-servers with basic authentication
-A, --useragent=STRING
String to be sent in http header as "User Agent"
-k, --header=STRING
Any other tags to be sent in http header. Use multiple times for
additional
headers
-L, --link
Wrap output in HTML link (obsoleted by urlize)
-f, --onredirect=<ok|warning|critical|follow|sticky|stickyport>
How to handle redirected pages. sticky is like follow but stick to the
specified IP address. stickyport also ensure post stays the same.
-m, --pagesize=INTEGER<:INTEGER>
Minimum page size required (bytes) : Maximum page size required (bytes)
-w, --warning=DOUBLE
Response time to result in warning status (seconds)
-c, --critical=DOUBLE
Response time to result in critical status (seconds)
-t, --timeout=INTEGER
Seconds before connection times out (default: 10)
-v, --verbose
Show details for command-line debugging (Nagios may truncate output)
Notes:
This plugin will attempt to open an HTTP connection with the host.
Successful connects return STATE_OK, refusals and timeouts return
STATE_CRITICA
L
March 1, 2012

By Vannath KANN

Page 61 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

other errors return STATE_UNKNOWN. Successful connects, but incorrect reponse


messages from the host result in STATE_WARNING return values. If you are
checking a virtual server that uses 'host headers' you must supply the FQDN
(fully qualified domain name) as the [host_name] argument.
Send email to nagios-users@lists.sourceforge.net if you have questions
regarding use of this software. To submit patches or suggest improvements,
send email to nagiosplug-devel@lists.sourceforge.net
[root@cent60 libexec]#

7.6.

Monitoring FTP
When you need to monitor FTP servers, you can use the check_ftp plugin. The commands.cfg
file contains a command definition for using the check_ftp plugin, which looks like this:

[root@cent60 objects]# pwd


/usr/local/nagios/etc/objects
[root@cent60 objects]# vim commands.cfg
# 'check_ftp' command definition
define command{
command_name
check_ftp
command_line
$USER1$/check_ftp -H $HOSTADDRESS$ $ARG1$
}

A simple service definition for monitoring the FTP server on remotehost would look like this:
[root@cent60 objects]# pwd
/usr/local/nagios/etc/objects
[root@cent60 objects]# vim linux-box-remote.cfg
define service{
use
generic-service
host_name
Cent61
service_description FTP
check_command
check_ftp
}

Then you will see as the following on you Nagios Server

March 1, 2012

By Vannath KANN

Page 62 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

This service definition will monitor the FTP service and generate alerts if the FTP server doesn't
respond within 10 seconds.
A more advanced service definition is shown below. This service will check the FTP server
running on port 1023 on remotehost. It will generate an alert if the server doesn't respond within
5 seconds or if the server response doesn't contain the string "Pure-FTPd [TLS]".
[root@cent60 objects]# pwd
/usr/local/nagios/etc/objects
[root@cent60 objects]# vim commands.cfg
define service{
use
generic-service
host_name
Cent61
service_description Special FTP
check_command
check_ftp !-p 1023 -t 5 -e "Pure-FTPd [TLS]"
}

7.7.

Monitoring SSH
When you need to monitor SSH servers, you can use the check_ssh plugin. The commands.cfg
file contains a command definition for using the check_ssh plugin, which looks like this:

# 'check_ssh' command definition


define command{
command_name
check_ssh
command_line
$USER1$/check_ssh $ARG1$ $HOSTADDRESS$
}

A simple service definition for monitoring the SSH server on remotehost would look like this:
March 1, 2012

By Vannath KANN

Page 63 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

[root@cent60 objects]# pwd


/usr/local/nagios/etc/objects
[root@cent60 objects]# vim linux-box-remote.cfg
define service{
use
generic-service
host_name
Cent61
service_description SSH
check_command
check_ssh
}

This service definition will monitor the SSH service and generate alerts if the SSH server
doesn't respond within 10 seconds.
A more advanced service definition is shown below. This service will check the SSH server and
generate an alert if the server doesn't respond within 5 seconds or if the server version string
string doesn't match "OpenSSH_4.2".
define service{
use
host_name
service_description
check_command
}

7.8.

generic-service
Cent61
SSH Version Check
check_ssh !-t 5 -r "OpenSSH_4.2"

Monitoring SMTP
The check_smtp plugin can be using for monitoring your email servers. The commands.cfg file
contains a command definition for using the check_smtp plugin, which looks like this:

[root@cent60 objects]# pwd


/usr/local/nagios/etc/objects
[root@cent60 objects]# vim commands.cfg
# 'check_smtp' command definition
define command{
command_name
check_smtp
command_line
$USER1$/check_smtp -H $HOSTADDRESS$ $ARG1$
}

A simple service definition for monitoring the SMTP server on remotehost would look like this:
[root@cent60 objects]# pwd
/usr/local/nagios/etc/objects
[root@cent60 objects]# vim linux-box-remote.cfg

March 1, 2012

By Vannath KANN

Page 64 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

define service{
use
host_name
service_description
check_command
}

generic-service
Cent61
SMTP
check_smtp

Testing to see whether SMPT Service on Cent61 is run or not from Nagios Server
[root@cent60 objects]# telnet 192.168.10.2 25
Trying 192.168.10.2...
Connected to 192.168.10.2.
Escape character is '^]'.
220 cent61.localdomain ESMTP Postfix
quit
221 2.0.0 Bye
Connection closed by foreign host.
[root@cent60 objects]#

Then we will see as the following

This service definition will monitor the SMTP service and generate alerts if the SMTP server
doesn't respond within 10 seconds.
A more advanced service definition is shown below. This service will check the SMTP server
and generate an alert if the server doesn't respond within 5 seconds or if the response from the
server doesn't contain "mygreatmailserver.com".
define service{
use
host_name
service_description
check_command
March 1, 2012

generic-service
Cent61
SMTP Response Check
check_smtp! t 5 e mygreatmailserver.com

By Vannath KANN

Page 65 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

7.9.

Monitoring POP3
The check_pop plugin can be using for monitoring the POP3 service on your email servers. The
commands.cfg file contains a command definition for using the check_pop plugin, which looks
like this:

[root@cent60 objects]# pwd


/usr/local/nagios/etc/objects
[root@cent60 objects]# vim commands.cfg
# 'check_pop' command definition
define command{
command_name
check_pop
command_line
$USER1$/check_pop -H $HOSTADDRESS$ $ARG1$
}

A simple service definition for monitoring the POP3 service on remotehost would look like
this:
[root@cent60 objects]# pwd
/usr/local/nagios/etc/objects
[root@cent60 objects]# vim linux-box-remote.cfg
define service{
use
host_name
service_description
check_command
}

generic-service
Cent61
POP3
check_pop

This service definition will monitor the POP3 service and generate alerts if the POP3 server
doesn't respond within 10 seconds.
Then you will see as below:

March 1, 2012

By Vannath KANN

Page 66 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

A more advanced service definition is shown below. This service will check the POP3 service
and generate an alert if the server doesn't respond within 5 seconds or if the response from the
server doesn't contain "mygreatmailserver.com".
define service{
use
host_name
service_description
check_command
}

generic-service
Cent61
POP3
check_pop !-t 5 -e "mygreatmailserver.com"

7.10. Monitoring IMAP


The check_imap plugin can be using for monitoring IMAP4 service on your email servers. The
commands.cfg file contains a command definition for using the check_imap plugin, which looks
like this:
[root@cent60 objects]# pwd
/usr/local/nagios/etc/objects
[root@cent60 objects]# vim commands.cfg
# 'check_imap' command definition
define command{
command_name
check_imap
command_line
$USER1$/check_imap -H $HOSTADDRESS$ $ARG1$
}

March 1, 2012

By Vannath KANN

Page 67 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

A simple service definition for monitoring the IMAP4 service on remotehost would look like
this:
[root@cent60 objects]# pwd
/usr/local/nagios/etc/objects
[root@cent60 objects]# vim linux-box-remote.cfg
define service{
use
host_name
service_description
check_command
}

generic-service
Cent61
IMAP
check_imap

This service definition will monitor the IMAP4 service and generate alerts if the IMAP server
doesn't respond within 10 seconds.

A more advanced service definition is shown below. This service will check the IMAP4 service
and generate an alert if the server doesn't respond within 5 seconds or if the response from the
server doesn't contain "mygreatmailserver.com".
define service{
use
host_name
service_description
check_command
}

March 1, 2012

generic-service
Cent61
IMAP
check_imap !-t 5 -e "mygreatmailserver.com"

By Vannath KANN

Page 68 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

7.11. Restarting Nagios


Once you've added the new host and service definitions to your object configuration file(s),
you're ready to start monitoring them. To do this, you'll need to verify your configuration and
restart Nagios.
[root@cent60 objects]# /usr/local/nagios/bin/nagios -v
/usr/local/nagios/etc/nagios.cfg
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...
Total Warnings: 0
Total Errors:
0
Things look okay - No serious problems were detected during the pre-flight
check
[root@cent60 objects]#
[root@cent60 objects]# service nagios restart
Running configuration check...done.
Stopping nagios: done.
Starting nagios: done.
[root@cent60 objects]#

If the verification process produces any errors messages, fix your configuration file before
continuing. Make sure that you don't (re)start Nagios until the verification process completes
without any errors!

March 1, 2012

By Vannath KANN

Page 69 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

8. Parent and Childs Relationship


8.1.

Introduction
An important feature of Nagios is the ability to create parent child relationships. Each switch,
router, server, and hosts the packet encounters or passes through is considered a hop and will
require that you define a parent/child host relationship in Nagios. Then you want to add the
parent host to all the children using the following host definition option: parent <parent host>.

5.2.

Configuration

Configuration on host name Cent62


define host{
use
host_name
alias
#
address
address
parents
}

linux-box-remote02 ; Inherit default values from a template


Cent62
; The name we're giving to this server
Cent62 ; A longer name for the server
192.168.10.4
; IP address of the server
127.0.0.3
; IP address of the server
icteo-sw01

Configuration on Switch name icteo-sw02

March 1, 2012

By Vannath KANN

Page 70 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

define host{
use
host_name
alias
switch
address
hostgroups
parents
}

generic-switch ; Inherit default values from a template


icteo-sw02 ; The name we're giving to this switch
ICTEO Switch 02 ; A longer name associated with the
127.0.0.1 ; IP address of the switch
switches ; Host groups this switch is associated with
Cent62

Configuration on host name w2k81


define host{
use
template
#
host_name
#
alias
the host
host_name
alias
the host
#
address
address
parents
}

windows-server

; Inherit default values from a

winserver
; The name we're giving to this host
My Windows Server
; A longer name associated with
w2k81
; The name we're giving to this host
Windows Server 2008
; A longer name associated with
192.168.10.3
127.0.0.3
icteo-sw01

; IP address of the host


; IP address of the host

Configuration on host name icteo-pr01


define host{
use
template
#
host_name
printer
host_name
printer
alias
the printer
#
address
address
hostgroups
associated with
parents
}

March 1, 2012

generic-printer

; Inherit default values from a

hplj2605dn

; The name we're giving to this

icteo-pr01

; The name we're giving to this

ICTEO Printer 01

; A longer name associated with

192.168.10.20
127.0.0.6
network-printers

; IP address of the printer


; IP address of the printer
; Host groups this printer is

icteo-sw02

By Vannath KANN

Page 71 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

And other host configuration are the same just user option: parent and then we will see the
result as the following:

9. Icon Images
The icons has to be put with your favorite SSH explorer in /usr/local/nagios/share/images

March 1, 2012

By Vannath KANN

Page 72 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

Here the sample configuration for Nagios host


define host{
use
to use

linux-server

; Name of host template


; This host definition

will inherit all variables that are defined


; in (or inherited by)
the linux-server host template definition.
host_name
Nagios
alias
Nagios Server
address
127.0.0.1
icon_image linux_nagios.png
vrml_image linux_nagios.png
statusmap_image linux_nagios.png
March 1, 2012

By Vannath KANN

Page 73 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

Here the sample configuration for Cent61 host


define host{
use
linux-box-remote
; Inherit default values from a
template
host_name Cent61
; The name we're giving to this server
alias
Cent61 ; A longer name for the server
address
192.168.10.2
; IP address of the server
parents
icteo-sw01
icon_image linux_centos.png
vrml_image linux_centos.png
statusmap_image linux_centos.png
}

Here the sample configuration for w2k81 host


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
host_name
w2k81
; The name we're giving to this host
alias
Windows Server 2008
; A longer name associated with
the host
#
address
192.168.10.3
; IP address of the host
address
127.0.0.3
; IP address of the host
parents
icteo-sw01
icon_image win2k8.png
vrml_image win2k8.png
statusmap_image win2k8.png
}

Here the sample configuration for icteo-sw01 host


define host{
use
template
#
host_name
switch
host_name
switch

March 1, 2012

generic-switch

; Inherit default values from a

linksys-srw224p

; The name we're giving to this

icteo-sw01

; The name we're giving to this

By Vannath KANN

Page 74 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

alias

ICTEO Switch 01 ; A longer name associated with the

switch
address
127.0.0.1
hostgroups
switches
associated with
#
parents
Cent62
icon_image switch40.png
vrml_image switch40.png
statusmap_image switch40.png
}

; IP address of the switch


; Host groups this switch is

And here is the result

You can find more image with the following link


http://exchange.nagios.org/directory/Graphics-and-Logos/Images-and-Logos
March 1, 2012

By Vannath KANN

Page 75 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

10.Trouble shooting

10.1. Verifying Your Configuration


Every time you modify your configuration files, you should run a sanity check on them. It is
important to do this before you (re)start Nagios, as Nagios will shut down if your configuration
contains errors.
In order to verify your configuration, run Nagios with the -v command line option like so:
[root@cent60 objects]# /usr/local/nagios/bin/nagios -v
/usr/local/nagios/etc/nagios.cfg

If you've forgotten to enter some critical data or misconfigured things, Nagios will spit out a
warning or error message that should point you to the location of the problem. Error messages
generally print out the line in the configuration file that seems to be the source of the problem.
On errors, Nagios will often exit the pre-flight check and return to the command prompt after
printing only the first error that it has encountered. This is done so that one error does not
cascade into multiple errors as the remainder of the configuration data is verified. If you get any
error messages you'll need to go and edit your configuration files to remedy the problem.
Warning messages can generally be safely ignored, since they are only recommendations and
not requirements.
Processing object config file '/usr/local/nagios/etc/objects/printer02.cfg'...
Warning: Duplicate definition found for hostgroup 'network-printers' (config
file '/usr/local/nagios/etc/objects/printer02.cfg', starting on line 47)
Error: Could not add object property in file
'/usr/local/nagios/etc/objects/printer02.cfg' on line 48.
Error processing object config files!
***> One or more problems was encountered while processing the config files...
Check your configuration file(s) to ensure that they contain valid
directives and data defintions. If you are upgrading from a previous
version of Nagios, you should be aware that some variables/definitions
may have been removed or modified in this version. Make sure to read
the HTML documentation regarding the config files, as well as the
'Whats New' section to find out what has changed.
[root@cent60 etc]#
March 1, 2012

By Vannath KANN

Page 76 of 77

Ministry of Education, Youth and Sports.#201, Norodom Blvd.,


Phnom Penh, Kingdom of Cambodia
Website: www.moeys.gov.kh
Fax: +855 23 210 134
CentOS6_Nagios_Core_3.3.x_V0.0.docx

Once you've verified your configuration files and fixed any errors you can go ahead and
(re)start Nagios.

11.Reference
http://nagios.sourceforge.net/docs/nagioscore/3/en/toc.html
http://www.kernelhardware.org/nagios-nrpe-to-monitor-remote-linux-server/
http://ideasnet.wordpress.com/2011/11/19/ides-server-x-how-to-set-the-parent-childrelationships-between-router-switchserver-and-hosts-with-nagios-and-how-they-are-connectedto-each-other/
http://exchange.nagios.org/directory/Graphics-and-Logos/Images-and-Logos

The End, Thank!


 
FiG

March 1, 2012

By Vannath KANN

Page 77 of 77

You might also like