Menu Principal

segunda-feira, 22 de agosto de 2011

Nagios - NRPE

Fonte: http://techmajha.com/2011/05/03/monitoring-remote-linux-box-using-nagios-nrpe-nagios-remote-plugin-executer/



NRPE is an addon that allows you to execute plugins on remote Linux/Unix hosts. This is useful if you need to monitor resources like disk usage, CPU load, memory usage, etc. on a remote host.
Nagios Server IP : 192.168.19.26
Linux Box IP : 192.168.19.25 IP of Linux Box to be Monitored

Installation and Configuration of NRPE on Remote Linux server (a.k.a. Linux box to be monitored)


[root@ora11gr2 ~]# useradd nagios
[root@ora11gr2 ~]# passwd nagios
[root@ora11gr2 ~]# cd /
[root@ora11gr2 /]# mkdir downloads
[root@ora11gr2 /]# cd downloads/

You will need to download and install following two files on remote host:
[root@ora11gr2 downloads]# wget
http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz
[root@ora11gr2 downloads]# wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz
[root@ora11gr2 downloads]# ls
nagios-plugins-1.4.15.tar.gz nrpe-2.12.tar.gz
Installation of Nagios-Plugin

[root@ora11gr2 downloads]# tar xvzf nagios-plugins-1.4.15.tar.gz
[root@ora11gr2 downloads]# cd nagios-plugins-1.4.15
[root@ora11gr2 nagios-plugins-1.4.15]./configure --with-nagios-user=nagios --with-nagios-group=nagios
[root@ora11gr2 nagios-plugins-1.4.15]# make
[root@ora11gr2 nagios-plugins-1.4.15]# make install
[root@ora11gr2 nagios-plugins-1.4.15]# chown nagios:nagios /usr/local/nagios
[root@ora11gr2 nagios-plugins-1.4.15]# chown -R nagios:nagios /usr/local/nagios/libexec
[root@ora11gr2 nagios-plugins-1.4.15]# yum install xinetd

Installation of NRPE

[root@ora11gr2 nagios-plugins-1.4.15]# cd ..
[root@ora11gr2 nrpe-2.12]# yum -y install openssl-devel
[root@ora11gr2 downloads]# tar xvzf nrpe-2.12.tar.gz
[root@ora11gr2 downloads]# cd nrpe-2.12
[root@ora11gr2 nrpe-2.12]# ./configure

*** Configuration summary for nrpe 2.12 03-10-2008 ***:
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@ora11gr2 nrpe-2.12]# make all
[root@ora11gr2 nrpe-2.12]# make install-plugin
[root@ora11gr2 nrpe-2.12]# make install-daemon
[root@ora11gr2 nrpe-2.12]# make install-daemon-config
[root@ora11gr2 nrpe-2.12]# make install-xinetd

Configuration of NRPE
Edit nrpe and Add the IP Address of nagios server:

[root@ora11gr2 nrpe-2.12]# vi /etc/xinetd.d/nrpe
# default: on
# description: NRPE (Nagios Remote Plugin Executor)
service nrpe
{
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.19.26
}
~


Configure NRPE as Daemon
Edit service file and Add NRPE Daemon at the end of file:

[root@ora11gr2 nrpe-2.12]# vi /etc/services
nrpe 5666/tcp # NRPE

[root@ora11gr2 nrpe-2.12]# chkconfig xinetd on
[root@ora11gr2 nrpe-2.12]# service xinetd restart
Stopping xinetd: [ OK ]
Starting xinetd: [ OK ]
Test NRPE Daemon installation

[root@ora11gr2 nrpe-2.12]# netstat -at | grep nrpe
tcp 0 0 *:nrpe *:* LISTEN

Verify to check NRPE is working properly:

[root@ora11gr2 nrpe-2.12]# /usr/local/nagios/libexec/check_nrpe -H localhost
NRPE v2.12

Open Port 5666 on Firewall
You can completely stop firewall as follows, there are other methods to open ports

[root@ora11gr2 nrpe-2.12]# iptables -L
[root@ora11gr2 nrpe-2.12]# iptables -F
[root@ora11gr2 nrpe-2.12]# iptables-save
[root@ora11gr2 nrpe-2.12]# service iptables restart
[root@ora11gr2 nrpe-2.12]# service iptables stop
[root@ora11gr2 nrpe-2.12]# service iptables status

Modify nrpe.cfg file:
nrpe.cfg file contains the commands needed to monitor services of remote host.

[root@ora11gr2 nrpe-2.12]# vi /usr/local/nagios/etc/nrpe.cfg
# The following examples use hardcoded command arguments...

command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda1
#command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_total_procs -w 150 -c 200

I have changed the disk type, because I have sata disk installed in my remote linux box.

[root@ora11gr2 nrpe-2.12]# fdisk -l

Disk /dev/sda: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 19457 156183930 8e Linux LVM

Now, Move to your Nagios server and install NRPE on it.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Installation of NRPE on Nagios SERVER:


[root@puli downloads]# cd ..
[root@puli downloads]# wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.12.tar.gz
[root@puli downloads]# tar xvzf nrpe-2.12.tar.gz
[root@puli downloads]# cd nrpe-2.12
[root@puli nrpe-2.12]# ./configure

*** Configuration summary for nrpe 2.12 03-10-2008 ***:
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@puli nrpe-2.12]# make all
[root@puli nrpe-2.12]# make install-plugin
Verify whether nagios monitoring server can talk to the remotehost.

[root@puli nrpe-2.12]# /usr/local/nagios/libexec/check_nrpe -H
NRPE v2.12


Create NRPE Command Definition
A command definition needs to be created in order for the check_nrpe plugin to be used by nagios.
Edit commands.cfg file on nagios server and Add following:

[root@puli nrpe-2.12]# vi /usr/local/nagios/etc/objects/commands.cfg

###############################################################################
# NRPE CHECK COMMAND
#
# Command to use NRPE to check remote host systems
###############################################################################
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}

Create Nagios Object template for Remote Linux Box
In order to be able to add the remote linux machine to Nagios we need to create an object template
file and add the object definitions we want to monitor.
Create new configuration file linux.cfg @ /usr/local/nagios/etc/objects/:

[root@puli nrpe-2.12]# vi /usr/local/nagios/etc/objects/linux.cfg

###############################################################################
###############################################################################
#
# HOST DEFINITION
#
###############################################################################
###############################################################################
# Define a host for the local machine
define host{
use linux-server ; Name of host template to use
; This host definition will inherit all
variables that are defined
; in (or inherited by) the linux-server host
template definition.
host_name linuxhost
alias linuxhost
address 192.168.19.25 ; IP of Linux Box to be Monitored
}
###############################################################################
###############################################################################
#
# HOST GROUP DEFINITION
#
###############################################################################
###############################################################################
# Define an optional hostgroup for Linux machines
define hostgroup{
hostgroup_name linux-box ; The name of the hostgroup
alias Linux Boxes ; Long name of the group
members linuxhost ; Comma separated list of hosts that belong to this group
}
###############################################################################
###############################################################################
#
# SERVICE DEFINITIONS
#
###############################################################################
###############################################################################
# Define a service to "ping" the local machine
define service{
use generic-service ; Name of service template to use
host_name linuxhost
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
# Define a service to check the disk space of the root partition
# on the local machine. Warning if < 20% free, critical if
# < 10% free space on partition.
define service{
use generic-service ; Name of service template to use
host_name linuxhost
service_description Root Partition
check_command check_nrpe!check_disk!20%!10%!/
}
# Define a service to check the number of currently logged in
# users on the local machine. Warning if > 20 users, critical
# if > 50 users.
define service{
use generic-service ; Name of service template to use
host_name linuxhost
service_description Current Users
check_command check_nrpe!check_users!5!10
}
# Define a service to check the number of currently running procs
# on the local machine. Warning if > 250 processes, critical if
# > 400 users.
define service{
use generic-service ; Name of service template to use
host_name linuxhost
service_description Total Processes
check_command check_nrpe!check_total_procs!250!400!RSZDT
}
# Define a service to check the load on the local machine.
define service{
use generic-service ; Name of service template to use
host_name linuxhost
service_description Current Load
check_command check_nrpe!check_load!5.0,4.0,3.0!10.0,6.0,4.0
# Define a service to check the swap usage the local machine.
# Critical if less than 10% of swap is free, warning if less than 20% is free
#define service{
# use generic-service ; Name of service template to use
# host_name linuxhost
# service_description Swap Usage
# check_command check_nrpe!check_swap!20!10
# }
# Define a service to check SSH on the local machine.
# Disable notifications for this service by default, as not all users may have SSH enabled.
define service{
use generic-service ; Name of service template to use
host_name linuxhost
service_description SSH
check_command check_ssh
notifications_enabled 0
}
# Define a service to check HTTP on the local machine.
# Disable notifications for this service by default, as not all users may have HTTP enabled.
define service{
use generic-service ; Name of service template to use
host_name linuxhost
service_description HTTP
check_command check_http
notifications_enabled 0
}

Once the services you need to monitor are entered into /usr/local/nagios/etc/objects/linux.cfg file, you have to inform nagios about this template, so edit /usr/local/nagios/etc/nagios.cfg and following line into it just below windows.cfg line.

[root@puli nrpe-2.12]# vi /usr/local/nagios/etc/nagios.cfg

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

Verify Nagios Configuration:

[root@puli nrpe-2.12]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Restart Nagios :

[root@puli nrpe-2.12]# service nagios restart
[root@puli nrpe-2.12]# chown -R nagios:nagcmd /usr/local/nagios/var/rw/nagios.cmd
[root@puli nrpe-2.12]# chown -R nagios:nagcmd /usr/local/nagios/var/rw/live

2 comentários: