Wednesday, December 29, 2010

NDOUtils installation on CentOS for Nagios

NDOUtils installation on CentOS

NDOUtils Requirements

  • GCC-C++
  • MySQL
  • MySQL-Devel
  • MySQL-Server

Installing MySQL

# yum -y install mysql mysql-devel mysql-server gcc-c++

# /etc/init.d/mysqld start

# chkconfig --add mysqld


-> make sure it's running

# ps -ef | grep mysql


-> Creating MySQL DB

mysql -u root

(no password

#Now, inside MySQL shell

mysql>create database nagios;

Query OK, 1 row affected (0.00 sec)

mysql>show databases;

+----------+

| Database |

+----------+

| database |

| mysql |

| nagios |

| test |

+----------+

4 rows in set (0.01 sec)

mysql>

Create a username/password that has at least the following privileges for the database: SELECT, INSERT, UPDATE, DELETE"

mysql> GRANT ALL ON nagios.* TO nagios@localhost IDENTIFIED BY "example";

Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;

Query OK, 0 rows affected (0.00 sec)

mysql> quit


-> NDOUtils Install

Download and untar

# cd /usr/local/nagios/var/

# wget http://internap.dl.sourceforge.net/sourceforge/nagios/ndoutils-1.4b9.tar.gz

# tar zxfv ndoutils-1.4b9.tar.gz


-> Compiling

# cd ndoutils-1.4b9

# ./configure

# make


Look through config.log for problems.

# less config.log

(If problems, run "make clean" to blow away bad binaries)


-> Copying Binaries

ndomod

There are two different versions of the NDOMOD module that get compiled, so make sure you use the module that matches the version of Nagios you are running, and adjust the directions given below to fit the name of the module version you're using.

ndomod-2x.o = NDOMOD module for Nagios 2.x ndomod-3x.o = NDOMOD module for Nagios 3.x (unstable)

In our CentOS example, we use the stable 2.x version

# /usr/local/nagios/var/ndoutils-1.4b9/src/ndomod-2x.o

Copy the compiled NDOMOD module to your Nagios installation:

# cp /usr/local/nagios/var/ndoutils-1.4b9/src/ndomod-3x.o /usr/local/nagios/bin/ndomod.o

ndo2db

There are two different versions of the NDO2DB daemon that get compiled, so make sure you use the daemon that matches the version of Nagios you are running, and adjust the directions given below to fit the name of the daemon you're using.

ndo2db-2x.o = NDO2DB daemon for Nagios 2.x ndo2db-3x.o = NDO2DB daemon for Nagios 3.x (unstable)

Copy the compiled NDO2DB daemon to your Nagios installation:

# cp /usr/local/nagios/var/ndoutils-1.4b9/src/ndo2db-2x /usr/local/nagios/bin/ndo2db

-> Creating NDO database

It's time now to create the NDO MySql database Run the DB installation script in the /tmp/ndoutils-1.4b9/db/ subdirectory of the NDO distribution to create the necessary tables in the database.

(-u = user; -p = password; -h = name of computer; -d = MySQL DB)

# cd /usr/local/nagios/var/ndoutils-1.4b9/db

# ./installdb -u nagios -p password -h localhost -d nagios

DBD::mysql::db do failed: Table 'nagios.nagios_dbversion' doesn't exist at ./installdb line 51.

** Creating tables for version 1.4b9

Using mysql.sql for installation...

** Updating table nagios_dbversion

Done!

We'll need to later make sure that the database name, prefix, and username/password we created and setup match the variable specified in our NDO2DB config file (which will ultimately live in /etc/nagios/)

CFG File Changes for CentOS-MySQL Environment

ndo2db.cfg

# cp //usr/local/nagios/var/ndoutils-1.4b9/config/ndo2db.cfg /usr/local/nagios/etc/


->in ndo2db.cfg

# SOCKET TYPE

# This option determines what type of socket the daemon will create

# an accept connections from.

# Value:

# unix = Unix domain socket (default)

# tcp = TCP socket

socket_type=unix

#socket_type=tcp

. . .

# SOCKET NAME

# This option determines the name and path of the UNIX domain

# socket that the daemon will create and accept connections from.

# This option is only valid if the socket type specified above

# is "unix".

socket_name=/usr/local/nagios/var/ndo.sock

#socket_name=/var/run/nagios/ndo.sock

. . .

# DATABASE USERNAME/PASSWORD

# This is the username/password that will be used to authenticate to the DB.

# The user needs at least SELECT, INSERT, UPDATE, and DELETE privileges on

# the database.

#db_user=ndouser

#db_pass=ndopassword

db_user=nagios

db_pass=password

ndomod.cfg

Copy the sample NDOMOD config file to your Nagios installation

Note: this config is not ready yet; we will need to modify it later to our environment.

# cp //usr/local/nagios/var/ndoutils-1.4b9/config/ndomod.cfg /usr/local/nagios/etc/

Add a line similiar to the following to the *main* Nagios config file (usually /usr/local/nagios/etc/nagios.cfg):

nagios.cfg file (all one one line, this cfg_file!=confg_file variable)

broker_module=/usr/local/nagios/bin/ndomod.o config_file=/usr/local/nagios/etc/ndomod.cfg


The config directive above will cause Nagios to load the NDOMOD event broker the next time it starts. Of course, this requres that you compiled Nagios with support for the event broker in the first place, which is not a problem if we installed via package (via RPMforge repository).

Make sure you have a line similar to the following in the *main* Nagios config file (usually /usr/local/nagios/etc/nagios.cfg):

event_broker_options=-1

That directive will cause the Nagios daemon to send data to the NDOMOD module. Without that option, NDOMOD won't get any information. Finaly make sure that output parameter in ndomod.cfg is set up to

output=//usr/local/nagios/var/ndo.sock

It's very important that output parameter has exactly the same value as socket_name parameter in ndo2db.cfg file. If not, you will get this message when starting nagios daemon.

[1192222122] ndomod: Error writing to data sink! Some output may get lost...

Start NDO2DB daemon

# /usr/local/nagios/bin/ndo2db -c /usr/local/Nagios/etc/nagios/ndo2db.cfg

[root@localhost nagios]# ps -ef | grep ndo2db

nagios 26516 1 0 19:36 ? 00:00:00 ndo2db -c /etc/nagios/ndo2db.cfg

root 26536 26460 0 19:40 pts/0 00:00:00 grep ndo

[root@localhost nagios]#

restart Nagios

# /etc/init.d/nagios restart

Proof it's working:

# tail /var/log/nagios/nagios.log

[1192222138] ndomod: Successfully reconnected to data sink! 0 items lost, 68 queued items to flush.

[1192222138] ndomod: Successfully flushed 68 queued items to data sink.

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

Wednesday, December 15, 2010

Installing Nagios on CentOS

1. First we make sure these prerequisites are installed and up to date
Run these commands from a command line:
-> yum install httpd
-> yum install gcc
-> yum install glibc glibc-common
-> yum install gd gd-devel

2. Elevate to root
From command line:
-> su -

3. Create a new nagios user account and give it a password
From command line:
-> /usr/sbin/useradd -m nagios
-> passwd nagios
Type the new password twice.

4.Create a new nagcmd group for external commands
From Command line:
-> /usr/sbin/groupadd nagcmd
-> /usr/sbin/usermod -a -G nagcmd nagios
-> /usr/sbin/usermod -a -G nagcmd apache

5. Create a directory to install Nagios
From command line:
-> mkdir downloads
-> cd dowloads/

6. Download source code from http://www.nagios.org/download/
These commands will download version 3.2.0 of the Core Nagios files and version 1.4.13 of the Nagios plugins.
From command line:
-> wget http://downloads.sourceforge.net/project/nagios/nagios-3.x/nagios-3.2.0/nagios-3.2.0.tar.gz?use_mirror=softlayer
-> wget http://downloads.sourceforge.net/project/nagiosplug/nagiosplug/1.4.13/nagios-plugins-1.4.13.tar.gz?use_mirror=softlayer

7. Extract and compile nagios-3.0.6.tar.gz
From Command line:
-> tar -xzvf nagios-3.0.6.tar.gz
-> cd nagios-3.0.6
-> ./configure --with-command-group=nagcmd
-> make all
-> make install
-> make install-init
-> make install-config
-> make install-commandmode

8. Edit the /usr/local/nagios/etc/objects/contacts.cfg config file. Change the email address associated with the nagiosadmin contact to the address you'd like to use for receiving alerts.
From command line:
-> vi /usr/local/nagios/etc/objects/contacts.cfg

9. Install the Nagios web config file in the Apache conf.d directory
From command line:
-> make install-webconf

10. Create a nagiosadmin account for logging into the Nagios web interface
From command line:
-> htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

11. Restart Apache
From command line:
-> service httpd restart

12. Compile and Install the Nagios Plugins
From command line:
-> cd downloads/
-> tar xzf nagios-plugins-1.4.11.tar.gz
-> cd nagios-plugins-1.4.11
-> ./configure --with-nagios-user=nagios --with-nagios-group=nagios
-> make
-> make install

13. Add Nagios to the list of system services
From command line:
-> chkconfig --add nagios
-> chkconfig nagios on

14. Check for config errors
From command line:
-> /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

15. Start Nagios
From command line:
-> service nagios start

16. Login to the Web Interface using username (nagiosadmin) and password you specified earlier
From your internet browser navigate to the following URL:
http:///nagios