NDOutils on CentOS

From Nagios Wiki

Jump to: navigation, search

Contents

[edit] Purpose of HOWTO

To show how to configure Nagios' NDOutils to store all configuration and event data from Nagios into a database, which will help facilidate quicker retrieval and processing event data. Lots of other Nagios-related tools (e.g. NagVis rely on the MySQL backend made available by NDOUtils.

This HOWTO assumes that the MySQL database lives on the Nagios server

[edit] How Nagios Normally Works

[edit] How Nagios Works with NDOUtils

[edit] NDOutils

From the Nagios website:

NDOUtils is an addon allowing you to store Nagios data (current status information, state history, notification history, etc.) in a MySQL database. This addon consists of an event broker module and a daemon. Consider this addon to be experimental for the moment, although it will likely play a central role in the a new Nagios web interface in the future.

[edit] NDOUtils Requirements

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

[edit] 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

[edit] Creating MySQL DB

HOWTO on creating MySQL DBs

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 "nagios";
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> quit

[edit] NDOUtils Install

[edit] Download and untar

cd /tmp
wget http://internap.dl.sourceforge.net/sourceforge/nagios/ndoutils-1.4b6.tar.gz
tar zxfv ndoutils-1.4b6.tar.gz

[edit] Compiling

./configure
make

Look through config.log for problems.

cd /tmp/ndoutils-1.4b6/
less config.log

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

[edit] Copying Binaries

Since we can't "make install" and have the NDOMOD and NDO2DB binaries magically go where they're supposed to, we have to copy them each individually.

[edit] 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

/tmp/ndoutils-1.4b6/src/ndomod-2x.o

Copy the compiled NDOMOD module to your Nagios installation:

cp /tmp/ndoutils-1.4b6/src/ndomod-2x.o /usr/bin/ndomod.o

or

cp /tmp/ndoutils-1.4b6/src/ndomod-2x.o /usr/local/nagios/bin/ndomod.o

If your nagios installation is located here.

[edit] 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 /tmp/ndoutils-1.4b6/src/ndo2db-2x /usr/bin/ndo2db

or

cp /tmp/ndoutils-1.4b6/src/ndo2db-2x /usr/local/nagios/bin/ndo2db

If your nagios installation is located here. I think that NDO binary and module should be integrated with nagios binaries.

[edit] Creating NDO database

It's time now to create the NDO MySql database Run the DB installation script in the /tmp/ndoutils-1.4b6/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 /tmp/ndoutils-1.4b6/db
./installdb -u nagios -p nagios -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.4b6
     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/)


[edit] CFG File Changes for CentOS-MySQL Environment

[edit] ndo2db.cfg

cp /tmp/ndoutils-1.4b6/config/ndo2db.cfg /etc/nagios/

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=nagios

You should knwo check that /var/run/nagios exist. If not, create it

mkdir /var/run/nagios

And make sure that NDO will be allowed to access this directory to create its socket.

chown -R nagios:nagios /var/run/nagios

[edit] ndomod.cfg

Copy the sample NDOMOD config file to your Nagios installation (which we assume to be /etc/nagios). Note: this config is not ready yet; we will need to modify it later to our environment.

cp /tmp/ndoutils-1.4b6/config/ndomod.cfg /etc/nagios/

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=/var/run/nagios/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...


[edit] Start NDO2DB daemon

/usr/bin/ndo2db -c /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.

If not working, will look something like:

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

So, check your ndomod.cfg config file (output parameter)

[edit] Other Resources

Personal tools
Advertisement