Wednesday, December 29, 2010

Nagios and nrpe setup CentOs

Nagios and nrpe setup CentOs 5.3 :

Nagios/nrpe how to :

For this session, I am demonstrating a basic Nagios set up of nrpe.

There are two hosts involved.
1. The nagios host. (the master node; where the nagios web ui is)
2. The remote host (the node you want to monitor remotely from the master node)

Software Versions involved:
both hosts: CentOS release 5.3 (Final) (64 bit)

master node:
Nagios® Core™ Version 3.2.0
nagios.x86_64 3.2.0-1.el5.rf (yum install)

remote host:
nagios-nrpe.x86_64 2.12-1.el5.rf (yum install)

(I assume you have a basic nagios set up already - this is just to enable nrpe)

nagios host: (master)

$ sudo yum install nagios-plugins-nrpe nrpe

$ sudo chown nagios.nagios /etc/nagios/nrpe.cfg

$ sudo vi /etc/nagios/objects/commands.cfg

# add

define command{

command_name check_nrpe

command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$

}

$ sudo vi /etc/nagios/objects/myremote_host.cfg

# add

define service{

use remote-service

host_name example.com

service_description Check Remote Users

check_command check_nrpe!check_users

}

# nrpe (remote checks) syntax is check_nrpe(as defined above) ! 'command to

run' (as defined on remote host, see below)

remote host: (node to be remotely monitored)
(NOTE: nagios itself should not be installed on this host)

$ sudo yum install nagios-nrpe

$ cd /etc/nagios

$ sudo chown nagios.nagios *.cfg

$ sudo vim /etc/xinetd.d/nrpe

# add

service nrpe

{

flags = REUSE

type = UNLISTED

port = 5666

socket_type = stream

wait = no

user = nagios

group = nagios

server = /usr/sbin/nrpe

server_args = -c /etc/nagios/nrpe.cfg --inetd

log_on_failure += USERID

disable = no # was yes

only_from = NAGIOS_MASTER_IP (master nagios host you want to

connect from) # was localhost

}

$ sudo vim cat /etc/hosts.allow

# add same ip from xinetd above

NAGIOS_MASTER_IP

$ sudo vim /etc/nagios/nrpe.cfg

#allowed_hosts=127.0.0.1 #

# add same ip from xinetd above

allowed_hosts=NAGIOS_MASTER_IP

$ sudo vim /etc/services

# append this line to the file

# Local services

nrpe 5666/tcp # nrpe (nagios)

$ sudo /sbin/service nrpe start

Starting Nagios NRPE daemon (nrpe): [ OK ]

$ sudo /etc/init.d/xinetd reload

$ sudo /sbin/chkconfig --list |grep nrpe

nrpe 0:off 1:off 2:off 3:off 4:off 5:off 6:off

nrpe: off

$ sudo /sbin/chkconfig --levels 35 nrpe on

$ sudo /sbin/chkconfig --list |grep nrpe

nrpe 0:off 1:off 2:off 3:on 4:off 5:on 6:off

nrpe: off

$ netstat -an | grep 5666

tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN

ok, good, it's running

now from nagios (master) server:
(can we see it's running too?)
telnet REMOTE_HOST_WE_JUST_CONFIGURED_IP 5666

$ /usr/lib64/nagios/plugins/check_nrpe -H REMOTE_HOST_WE_JUST_CONFIGURED_IP -p5666 -c check_disk1

to add new commands to be run via nrpe, we must add those to the remote host, nrpe.cfg file:

added new test on remote host:
$ sudo vim /etc/nagios/nrpe.cfg
command[check_mapper]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/sda5

test from master node:
$ /usr/lib64/nagios/plugins/check_nrpe -H REMOTE_HOST_WE_JUST_CONFIGURED_IP -p5666 -c check_mapper
DISK OK - free space: / 41180 MB (50% inode=99%);| /=40614MB;68993;77617;0;86242

helpful master node commands:
server config test:
$ sudo /usr/bin/nagios -v /etc/nagios/nagios.cfg
#start/stop/restart:
$ sudo /sbin/service nagios restart
#command line check commands against remote host:
$ /usr/lib64/nagios/plugins/check_nrpe -H REMOTE_SERVER_IP -p5666 -c check_disk1

No comments: