[root@zxweb ~]# useradd nagios
[root@zxweb ~]# tar zxvf nagios-plugins-2.2.1.tar.gz
[root@zxweb ~]# cd nagios-plugins-2.2.1
[root@zxweb nagios-plugins-2.2.1]# ./configure --prefix=/usr/local/nagios \
--with-cgiurl=/nagios/cgi-bin \
--with-nagios-user=nagios \
--with-nagios-group=nagios
[root@zxweb nagios-plugins-2.2.1]# make
[root@zxweb nagios-plugins-2.2.1]# make install
[root@zxweb ~]# yum install -y xinetd
[root@zxweb ~]# tar zxvf nrpe-3.2.1.tar.gz
[root@zxweb ~]# cd nrpe-3.2.1
[root@zxweb nrpe-3.2.1]# ./configure --prefix=/usr/local/nagios --enable-ssl
[root@zxweb nrpe-3.2.1]# make all
[root@zxweb nrpe-3.2.1]# make install
[root@zxweb nrpe-3.2.1]# make install-plugin
[root@zxweb nrpe-3.2.1]# make install-daemon
[root@zxweb nrpe-3.2.1]# make install-config
[root@zxweb nrpe-3.2.1]# make install-inetd
[root@zxweb ~]# vi /etc/xinetd.d/nrpe
# default: off
# description: NRPE (Nagios Remote Plugin Executor)
service nrpe
{
disable = no
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
only_from = 192.168.1.200
log_on_success =
}
[root@zxweb ~]# vi /etc/services
nrpe 5666/tcp # nagios
[root@zxweb ~]# yum -y install perl-Time-HiRes
[root@zxweb ~]# rpm -ivh perl-UNIVERSAL-require-0.13-1.el6.rf.noarch.rpm
[root@zxweb ~]# tar zxvf Sys-Statistics-Linux-0.66.tar.gz
[root@zxweb ~]# cd Sys-Statistics-Linux-0.66
[root@zxweb Sys-Statistics-Linux-0.66]# perl Makefile.PL
[root@zxweb Sys-Statistics-Linux-0.66]# make
[root@zxweb Sys-Statistics-Linux-0.66]# make install
[root@zxweb ~]# vi /usr/local/nagios/etc/nrpe.cfg
allowed_hosts=192.168.1.200
command[check_cpu]=/usr/local/nagios/libexec/check_linux_stats.pl -C -w 50 -c 80 -s 5
command[check_memory]=/usr/local/nagios/libexec/check_memory.py -w 20 -c 10
command[check_disk]=/usr/local/nagios/libexec/check_disk.pl -w 20 -c 10
command[check_network]=/usr/local/nagios/libexec/check_linux_stats.pl -N -w 1048576 -c 2097152 -p eth0
command[check_uptime]=/usr/local/nagios/libexec/check_linux_stats.pl -U -w 5
[root@zxweb ~]# cd /usr/local/nagios/libexec
[root@zxweb libexec]# chmod a+x check_linux_stats.pl
[root@zxweb libexec]# chmod a+x check_memory.py
[root@zxweb libexec]# chmod a+x check_disk.pl
[root@zxweb libexec]# ./check_linux_stats.pl -C -w 50 -c 80 -s 5
CPU OK : idle 97.79% |idle=97.79%;50;80 user=0.00% system=0.00% iowait=2.21% steal=0.00%
[root@zxweb ~]# /etc/init.d/xinetd start
Starting xinetd: [ OK ]
[root@zxweb ~]# netstat -tunlp | grep 5666
tcp 0 0 :::5666 :::* LISTEN 2409/xinetd
[root@zxweb ~]# cd /usr/local/tomcat/conf
[root@zxweb conf]# vi tomcat-users.xml
[root@zxweb ~]# cd /usr/local/icinga/libexec
[root@zxweb libexec]# ./check_tomcat.py -h
usage: check_tomcat.py [-h] [-V] [-v] -H HOST -p PORT [-u USER] [-a PASS]
[-U URL] [-C CONNECTOR] [-t TIMEOUT] [-e EXPIRE_TIME]
[-n NAMEAPP] [-w WARNING] [-c CRITICAL] -m
{status,mem,thread,app}
Nagios plugin for check an apache tomcat server
optional arguments:
-h, --help show this help message and exit
-V, --version Show plugin version
-v, --verbosity increase output verbosity:
-v Single line, additional information (eg list processes that fail)
-vv Multi line, configuration debug output (eg ps command used)
-vvv Lots of detail for plugin problem diagnosis
Connection parameters:
parameters for Tomcat connection
-H HOST, --host HOST Name or Ip of tomcat host
-p PORT, --port PORT Tomcat port (Example:8080)
-u USER, --user USER Tomcat user
-a PASS, --authentication PASS
Tomcat authentication password
-U URL, --URL URL Tomcat manager app url "/manager" by default
-C CONNECTOR, --connector CONNECTOR
Connector name, used in thread mode
-t TIMEOUT, --timeout TIMEOUT
Timeout for connection (5 seconds by default)
-e EXPIRE_TIME, --expire_time EXPIRE_TIME
Expire time for sessions created in tomcat manager app
value in minutes (0 minutes by default)
Check parameters:
Parameters for tomcat check
-n NAMEAPP, --nameapp NAMEAPP
Name of the java application you want to check, only for app mode
-w WARNING, --warning WARNING
Warning value
-c CRITICAL, --critical CRITICAL
Critical value
-m {status,mem,thread,app}, --mode {status,mem,thread,app}
Tomcat monitorizacion mode:
status: The status of tomcat server
mem: Tomcat server used percentage memory status, warning and critical
values. Requiered in percentage.
thread: Tomcat connectors Threads used, warning and critical values requiered.
The parameter connector is optional, if not exists, all connector were shown.
app: Application status in tomcat server, the name of the application
must be defined with the parameter -n or --nameapp.
This option check the status of java application running on tomcat server[root@nagios ~]# cd /usr/local/icinga/etc/objects/
[root@nagios objects]# vi commands.cfg
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
define command{
command_name check_tomcat
command_line $USER1$/check_tomcat.py -H $HOSTADDRESS$ -p $ARG1$ -u $ARG2$ -a $ARG3$ -w $ARG4$ -c $ARG5$ -m $ARG6$
}
define command{
command_name check_http
command_line $USER1$/check_http -H $HOSTADDRESS$ -p $ARG1$ -e 200
}
[root@nagios objects]# vi tomcat.cfg
# define a host
define host{
use linux-server
host_name zxweb
alias zxweb
icon_image redhat.gif
statusmap_image redhat.gd2
address 192.168.1.201
}
# define an hostgroup
define hostgroup{
hostgroup_name sale-tomcat
alias webapp
members zxweb
}
# define an servicegroup
define servicegroup {
servicegroup_name ping
alias alive
}
define servicegroup {
servicegroup_name os
alias linux
}
# define an servicegroup
define servicegroup {
servicegroup_name webapp
alias tomcat
}
# Define a service
define service{
hostgroup_name sale-tomcat
use generic-service
service_description alive
servicegroups ping
check_command check_ping!100.0,20%!500.0,60%
}
define service{
hostgroup_name sale-tomcat
use generic-service
service_description os cpu usage
servicegroups os
check_command check_nrpe!check_cpu
}
define service{
hostgroup_name sale-tomcat
use generic-service
service_description os memory usage
servicegroups os
check_command check_nrpe!check_memory
}
define service{
hostgroup_name sale-tomcat
use generic-service
service_description os disk usage
servicegroups os
check_command check_nrpe!check_disk
}
define service{
hostgroup_name sale-tomcat
use generic-service
service_description os network usage
servicegroups os
check_command check_nrpe!check_network
}
define service{
hostgroup_name sale-tomcat
use generic-service
service_description os uptime
servicegroups os
check_command check_nrpe!check_uptime
}
define service{
hostgroup_name zxweb
use generic-service
service_description zxweb status
servicegroups webapp
check_command check_http!8080
}
define service{
hostgroup_name zxweb
use generic-service
service_description tomcat status
servicegroups webapp
check_command check_tomcat!8080!admin!abcd.1234!80!90!status
}
define service{
hostgroup_name zxweb
use generic-service
service_description tomcat memory
servicegroups webapp
check_command check_tomcat!8080!admin!abcd.1234!80!90!mem
}
define service{
hostgroup_name zxweb
use generic-service
service_description tomcat thread
servicegroups webapp
check_command check_tomcat!8080!admin!abcd.1234!80!90!thread
}
[root@nagios ~]# cd /usr/local/icinga/etc
[root@nagios etc]# vi icinga.cfg
cfg_file=/usr/local/icinga/etc/objects/tomcat.cfg
[root@nagios ~]# service icinga restart
Running configuration check...OK
Stopping Icinga: Waiting for icinga to exit ..Stopping icinga done.
Starting icinga: Starting icinga done.