How to setup NDOutils on CentOS

May 26, 2011 by techmajha
Filed under: server services
 

NDOutils is as addon allowing you to store Nagios data (current status information, state history, notification history, etc.) in a MySQL database.

Install NDOUtils Prerequisite:


# yum install gcc mysql mysql-devel mysql-server gcc-c++ libdbi-dbd-mysql

Make sure mysql is running.


# ps -ef | grep mysql

Create MySQL DB for NDOutils


# mysql -u root -p

Create database nagios once login into mysql shell:


mysql> create database nagios;
Query OK, 1 row affected (0.03 sec)

mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| asterisk |
| asteriskcdrdb |
| mysql |
| nagios |
| openaudit |
| otrs |
| test |
| wikidb |
+--------------------+
9 rows in set (0.10 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.04 sec)

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

NDOUtils Install

Download, untar and compile


# cd /downloads/
# wget http://downloads.sourceforge.net/project/nagios/ndoutils-1.x/ndoutils-1.4b9/ndoutils-1.4b9.tar.gz
# tar xvzf ndoutils-1.4b9.tar.gz
# cd ndoutils-1.4b9
# ./configure
# make

In case of problems look through config.log:


# cd /downloads/ndoutils-1.4b9/
# less config.log

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

Copying Binaries

As per NagiosWiki, Since we can’t “make install” and have the NDOMOD and NDO2DB binaries automatiically go where they’re supposed to, we have to copy them individually.

First copy ndomod:


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

Next copy ndo2db:


# cp /downloads/ndoutils-1.4b9/src/ndo2db-3x /usr/local/nagios/bin/ndo2db
# chmod 755 /usr/local/nagios/bin/ndo2db

Creating NDO database:


# cd /downloads/ndoutils-1.4b9/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.4b9
Using mysql.sql for installation...
** Updating table nagios_dbversion
Done!

Copy configuration and Set permission for NDOMOD and NDO2DB:


# cp /downloads/ndoutils-1.4b9/config/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg
# cp /downloads/ndoutils-1.4b9/config/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg
# chmod 775 /usr/local/nagios/etc/ndo*
# chown nagios:nagios /usr/local/nagios/etc/ndo*

CFG File Changes for CentOS-MySQL:

Before making changes to ndo2db.cfg and ndomod.cfg file.
Add following two lines to the *main* Nagios config file (usually /usr/local/nagios/etc/nagios.cfg):
Note : broker_module=/usr/local/nagios/bin/ndomod.o config_file=/usr/local/nagios/etc/ndomod.cfg is a single line.


# vi /usr/local/nagios/etc/nagios.cfg

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

First Modify /usr/local/nagios/etc/ndo2db.cfg file as required in your environment (My customized ndo2db.cfg file) :


# vi /usr/local/nagios/etc/ndo2db.cfg

socket_type=unix
#socket_type=tcp

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

# db_user=ndouser
# db_pass=ndopassword

db_user=nagios
db_pass=nagios

Now Modify /usr/local/nagios/etc/ndomod.cfg :


# vi /usr/local/nagios/etc/ndomod.cfg

In fact you may not require to make any changes to ndomod.cfg file, but check for any of these values if you are thrown with error :

instance_name=default

#output_type=tcpsocket
output_type=unixsocket

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

tcp_port=5668

use_ssl=0

output_buffer_items=5000

buffer_file=/usr/local/nagios/var/ndomod.tmp

file_rotation_interval=14400

file_rotation_timeout=60

reconnect_interval=15

reconnect_warning_interval=15

data_processing_options=-1

config_output_options=2

Start the ndo2db init script and restart the nagios:

Start ndo2db:


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

# ps -ef | grep ndo2db
nagios 19557 1 0 16:43 ? 00:00:00 /usr/local/nagios/bin/ndo2db -c /usr/local/nagios/etc/ndo2db.cfg
root 19603 24897 0 16:44 pts/2 00:00:00 grep ndo2db

Restart Nagios:


# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
# /etc/init.d/nagios restart

# tail -f /usr/local/nagios/var/nagios.log
[1306405816] Auto-save of retention data completed successfully.
[1306408994] Caught SIGTERM, shutting down...
[1306408994] Successfully shutdown... (PID=24204)
[1306408995] Nagios 3.2.3 starting... (PID=20009)
[1306408995] Local time is Thu May 26 16:53:15 IST 2011
[1306408995] LOG VERSION: 2.0
[1306408995] ndomod: NDOMOD 1.4b9 (10-27-2009) Copyright (c) 2009 Nagios Core Development Team and Community Contributors
[1306408995] ndomod: Successfully connected to data sink. 0 queued items to flush.
[1306408995] Event broker module '/usr/local/nagios/bin/ndomod.o' initialized successfully.
[1306408995] Finished daemonizing... (New PID=20012)

Troubleshooting:
If not working, will look something like:

[1306408995] ndomod: Error writing to data sink! Some output may get lost…
So, check your ndomod.cfg config file

 

6/2011 – cuongk6t

Advertisements