cuongk6t's Blog

How they do that – step by step

How to setup NDOutils on CentOS

with 11 comments



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

Written by cuongk6t

07/06/2011 at 5:16 pm

11 Responses

Subscribe to comments with RSS.

  1. if you get error : ndomod: Error writing to data sink! , please change mod 666 for ndo2db.cfg and ndomod.cfg
    /etc/init.d/nagios stop
    /etc/init.d/ndo2db stop
    /etc/init.d/ndo2db start
    /etc/init.d/nagios start
    check again: tail -f /usr/local/nagios/var/nagios.log
    Good luck.
    If you can’t fix, please let me know.

    cuongk6t

    10/06/2011 at 2:52 pm

  2. ok, step by step (tested by me) 6/2011 – centos 5.6
    1. yum install gcc mysql mysql-devel mysql-server gcc-c++ libdbi-dbd-mysql
    2. /etc/init.d/mysqld start
    3. /sbin/chkconfig mysqld on
    4. /usr/bin/mysqladmin -u root password 123456
    123456 is your password
    5. mysql -u root -p123456
    6. mkdir ~/downloads
    7. cd ~/downloads/
    8. wget http://sourceforge.net/projects/nagios/files/ndoutils-1.x/ndoutils-1.4b9/ndoutils-1.4b9.tar.gz/download
    9. tar xvzf ndoutils-1.4b9.tar.gz
    10. cd ndoutils-1.4b9
    11. ./configure –prefix=/usr/local/nagios/ –enable-mysql –disable-pgsql –with-ndo2db-user=nagios -with-ndo2db-group=nagcmd
    12. make
    13. less config.log
    14. cd db/
    15. ./installdb -u nagios -p nagios -h localhost -d nagios
    16. cd ..
    17. cp ./src/ndomod-3x.o /usr/local/nagios/bin/ndomod.o
    18. cp ./src/ndo2db-3x /usr/local/nagios/bin/ndo2db
    19. cp ./config/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg
    20. cp ./config/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg
    21. chmod 774 /usr/local/nagios/bin/ndo*
    22. chown nagios:nagios /usr/local/nagios/bin/ndo*
    23. cp ./daemon-init /etc/init.d/ndo2db
    24. chmod +x /etc/init.d/ndo2db
    25. chkconfig –add ndo2db
    26. vi /usr/local/nagios/etc/nagios.cfg
    27. vi /usr/local/nagios/etc/ndo2db.cfg
    28. vi /usr/local/nagios/etc/ndomod.cfg
    29. /etc/init.d/ndo2db start
    30. /etc/init.d/nagios restart
    31. tail -f /usr/local/nagios/var/nagios.log
    if you get error: Could not open data sink
    —————————
    [1307690851] Nagios 3.2.3 starting… (PID=10660)
    [1307690851] Local time is Fri Jun 10 00:27:31 PDT 2011
    [1307690851] LOG VERSION: 2.0
    [1307690851] ndomod: NDOMOD 1.4b9 (10-27-2009) Copyright (c) 2009 Nagios Core Development Team and Community Contributors
    [1307690851] ndomod: Could not open data sink! I’ll keep trying, but some output may get lost…
    [1307690851] Event broker module ‘/usr/local/nagios/bin/ndomod.o’ initialized successfully.
    [1307690851] Finished daemonizing… (New PID=10661)
    —————————
    Following these steps:
    chmod 666 /usr/local/nagios/etc/ndomod.cfg
    chmod 666 /usr/local/nagios/etc/ndo2db.cfg
    /etc/init.d/ndo2db stop
    /etc/init.d/nagios stop
    /etc/init.d/ndo2db start
    /etc/init.d/nagios start

    Any questions? Post new comment Please

    cuongk6t

    10/06/2011 at 4:10 pm

    • I got a problem at the last step : Start the ndo2db init script and restart the nagios:

      [root@nagios ndoutils-1.5.2]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

      Nagios Core 3.4.1
      Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors
      Copyright (c) 1999-2009 Ethan Galstad
      Last Modified: 05-11-2012
      License: GPL

      Website: http://www.nagios.org
      Reading configuration data…
      Error in configuration file ‘/usr/local/nagios/etc/nagios.cfg’ – Line 246 (UNKNOWN VARIABLE)
      Error processing main config file!

      ***> One or more problems was encountered while processing the config files…

      Check your configuration file(s) to ensure that they contain valid
      directives and data defintions. If you are upgrading from a previous
      version of Nagios, you should be aware that some variables/definitions
      may have been removed or modified in this version. Make sure to read
      the HTML documentation regarding the config files, as well as the
      ‘Whats New’ section to find out what has changed.

      I try to kill the “ndo2db” process, and try to start again but still failed.
      [root@nagios ndoutils-1.5.2]# ps -ef | grep ndo2db
      nagios 5357 1 0 10:24 ? 00:00:00 /usr/local/nagios/bin/ndo2db -c /usr/local/nagios/etc/ndo2db.cfg
      root 5399 17677 0 10:28 pts/0 00:00:00 grep ndo2db
      [root@nagios ndoutils-1.5.2]# kill -9 5357
      [root@nagios ndoutils-1.5.2]#
      [root@nagios ndoutils-1.5.2]#
      [root@nagios ndoutils-1.5.2]# /usr/local/nagios/bin/ndo2db -c /usr/local/nagios/etc/ndo2db.cfg
      Could not bind socket: Address already in use

      Following your suggestion below, try again but still the same.

      [root@nagios ndoutils-1.5.2]# chmod 666 /usr/local/nagios/etc/ndomod.cfg
      [root@nagios ndoutils-1.5.2]# chmod 666 /usr/local/nagios/etc/ndo2db.cfg
      [root@nagios ndoutils-1.5.2]# /etc/init.d/ndo2db stop
      ndo2db was not running… could not stop
      [root@nagios ndoutils-1.5.2]#
      [root@nagios ndoutils-1.5.2]#
      [root@nagios ndoutils-1.5.2]# ps -eaf | grep ndo2
      root 5425 17677 0 10:29 pts/0 00:00:00 grep ndo2
      [root@nagios ndoutils-1.5.2]# /etc/init.d/nagios stop
      Stopping nagios: done.
      [root@nagios ndoutils-1.5.2]#
      [root@nagios ndoutils-1.5.2]#
      [root@nagios ndoutils-1.5.2]# /etc/init.d/ndo2db start
      Starting ndo2db:Could not bind socket: Address already in use
      done.
      [root@nagios ndoutils-1.5.2]#
      [root@nagios ndoutils-1.5.2]# /etc/init.d/nagios start
      Starting nagios:CONFIG ERROR! Start aborted. Check your Nagios configuration.

      Please help me to know what problem I met ?

      I’m looking forward to hearing from you soon.

      chinhvc

      18/09/2012 at 12:49 am

  3. Dear Mr.Chinhvc,
    For a long time, I’m not use nagios again, but if your issue not resolve, I’ll create a new nagios server to check it.
    Please show me some line before and after line 246 in configuration file ‘/usr/local/nagios/etc/nagios.cfg’ . I want to check what’s the variable unknown.

    quyenluc

    18/09/2012 at 7:47 pm

    • This is my /usr/local/nagios/etc/nagios.cfg file which includes these line between 223 – 268.

      223 # EVENT BROKER MODULE(S)
      224 # This directive is used to specify an event broker module that should
      225 # by loaded by Nagios at startup. Use multiple directives if you want
      226 # to load more than one module. Arguments that should be passed to
      227 # the module at startup are seperated from the module path by a space.
      228 #
      229 #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      230 # WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING
      231 #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      232 #
      233 # Do NOT overwrite modules while they are being used by Nagios or Nagios
      234 # will crash in a fiery display of SEGFAULT glory. This is a bug/limitation
      235 # either in dlopen(), the kernel, and/or the filesystem. And maybe Nagios…
      236 #
      237 # The correct/safe way of updating a module is by using one of these methods:
      238 # 1. Shutdown Nagios, replace the module file, restart Nagios
      239 # 2. Delete the original module file, move the new module file into place, restart Nagios
      240 #
      241 # Example:
      242 #
      243 # broker_module= [moduleargs]
      244
      245 broker_module=/usr/local/nagios/bin/ndomod.o
      246 config_file=/usr/local/nagios/etc/ndomod.cfg
      247 #broker_module=/somewhere/module2.o arg1 arg2=3 debug=0
      248
      249
      250
      251 # LOG ROTATION METHOD
      252 # This is the log rotation method that Nagios should use to rotate
      253 # the main log file. Values are as follows..
      254 # n = None – don’t rotate the log
      255 # h = Hourly rotation (top of the hour)
      256 # d = Daily rotation (midnight every day)
      257 # w = Weekly rotation (midnight on Saturday evening)
      258 # m = Monthly rotation (midnight last day of month)
      259
      260 log_rotation_method=d
      261
      262
      263
      264 # LOG ARCHIVE PATH
      265 # This is the directory where archived (rotated) log files should be
      266 # placed (assuming you’ve chosen to do log rotation).
      267
      268 log_archive_path=/usr/local/nagios/var/archives

      I’m not familiar with nagios, but really need it to monitor my system.
      Let me know if I can supply additional information.

      chinhvc

      18/09/2012 at 11:11 pm

  4. I think you also need to know the content of /usr/local/nagios/etc/ndomod.cfg file. So that, this is the configuration in this file, please check it :

    [root@nagios ~]# cat /usr/local/nagios/etc/ndomod.cfg
    #####################################################################
    # NDOMOD CONFIG FILE
    #
    # Last Modified: 09-05-2007
    #####################################################################

    # INSTANCE NAME
    # This option identifies the “name” associated with this particular
    # instance of Nagios and is used to seperate data coming from multiple
    # instances. Defaults to ‘default’ (without quotes).

    instance_name=default

    # OUTPUT TYPE
    # This option determines what type of output sink the NDO NEB module
    # should use for data output. Valid options include:
    # file = standard text file
    # tcpsocket = TCP socket
    # unixsocket = UNIX domain socket (default)

    #output_type=file
    #output_type=tcpsocket
    output_type=unixsocket

    # OUTPUT
    # This option determines the name and path of the file or UNIX domain
    # socket to which output will be sent if the output type option specified
    # above is “file” or “unixsocket”, respectively. If the output type
    # option is “tcpsocket”, this option is used to specify the IP address
    # of fully qualified domain name of the host that the module should
    # connect to for sending output.

    #output=/usr/local/nagios/var/ndo.dat
    #output=127.0.0.1
    output=/usr/local/nagios/var/ndo.sock

    # TCP PORT
    # This option determines what port the module will connect to in
    # order to send output. This option is only valid if the output type
    # option specified above is “tcpsocket”.

    tcp_port=5668

    # ENCRYPTION
    # This option determines if the module will use SSL to encrypt the
    # network traffic between module and ndo2db daemon.
    # Both sides have to enable this feature which depends on SSL Libraries
    # like openssl or kerberos
    # This option is only valid if the output type
    # option specified above is “tcpsocket”.
    #
    # A value of ‘1’ will enable this feature

    use_ssl=0

    # OUTPUT BUFFER
    # This option determines the size of the output buffer, which will help
    # prevent data from getting lost if there is a temporary disconnect from
    # the data sink. The number of items specified here is the number of
    # lines (each of variable size) of output that will be buffered.

    output_buffer_items=5000

    # BUFFER FILE
    # This option is used to specify a file which will be used to store the
    # contents of buffered data which could not be sent to the NDO2DB daemon
    # before Nagios shuts down. Prior to shutting down, the NDO NEB module
    # will write all buffered data to this file for later processing. When
    # Nagios (re)starts, the NDO NEB module will read the contents of this
    # file and send it to the NDO2DB daemon for processing.

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

    # FILE ROTATION INTERVAL
    # This option determines how often (in seconds) the output file is
    # rotated by Nagios. File rotation is handled by Nagios by executing
    # the command defined by the file_rotation_command option. This
    # option has no effect if the output_type option is a socket.

    file_rotation_interval=14400

    # FILE ROTATION COMMAND
    # This option specified the command (as defined in Nagios) that is
    # used to rotate the output file at the interval specified by the
    # file_rotation_interval option. This option has no effect if the
    # output_type option is a socket.
    #
    # See the file ‘misccommands.cfg’ for an example command definition
    # that you can use to rotate the log file.

    #file_rotation_command=rotate_ndo_log

    # FILE ROTATION TIMEOUT
    # This option specified the maximum number of seconds that the file
    # rotation command should be allowed to run before being prematurely
    # terminated.

    file_rotation_timeout=60

    # RECONNECT INTERVAL
    # This option determines how often (in seconds) that the NDO NEB
    # module will attempt to re-connect to the output file or socket if
    # a connection to it is lost.

    reconnect_interval=15

    # RECONNECT WARNING INTERVAL
    # This option determines how often (in seconds) a warning message will
    # be logged to the Nagios log file if a connection to the output file
    # or socket cannot be re-established.

    reconnect_warning_interval=15
    #reconnect_warning_interval=900

    # DATA PROCESSING OPTION
    # This option determines what data the NDO NEB module will process.
    # Do not mess with this option unless you know what you’re doing!!!!
    # Read the source code (include/ndbxtmod.h) to determine what values
    # to use here. Values from source code should be OR’ed to get the
    # value to use here. A value of -1 will cause all data to be processed.
    # Read the source code (include/ndomod.h) and look for “NDOMOD_PROCESS_”
    # to determine what values to use here. Values from source code should
    # be OR’ed to get the value to use here. A value of -1 will cause all
    # data to be processed.

    data_processing_options=-1

    # CONFIG OUTPUT OPTION
    # This option determines what types of configuration data the NDO
    # NEB module will dump from Nagios. Values can be OR’ed together.
    # Values:
    # 0 = Don’t dump any configuration information
    # 1 = Dump only original config (from config files)
    # 2 = Dump config only after retained information has been restored
    # 3 = Dump both original and retained configuration

    config_output_options=2

    chinhvc

    18/09/2012 at 11:12 pm

    • No one else had posted the answer here, but I found it elsewhere; I committed the same error as the OP and resolved it.

      The error (in his file:)

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

      The fix:
      Line 246 is not intended to stand on its own. It is a continuation of the previous line (though the instructions that the OP drew from don’t make this clear.) So line 245 should have read:

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

      HTH

      Tim C

      09/01/2013 at 9:15 pm

      • And, aggravatingly, this site (like others) wrap the lines too aggressively.

        To express the fix another way, there should be no new-line after ndomod.o, only a space, and then immediately followed by the config_file= portion.

        Stupid line wraps.

        Tim C

        09/01/2013 at 9:18 pm

  5. How do you limit the space the mysql db uses? my /var file system is up to 50 GB, and growing fast.

    Howard Coles

    04/09/2013 at 2:29 am

  6. hello, great post, i have an issue happens that everything works fine, my logs flles looks like you said , but in msql the tables are empy , but i dont have any error with nagios and ndoutils… i am really outset about it.. do yuo have some suggestion..?? please help me …

    johnny

    29/07/2014 at 9:32 am

    • hi Johnny,
      I can’t help you now, because this project I make in 2011 and not continue until 2012, now I can’t remember about that and I don’t have any test lab to do it again.

      Cuong

      29/07/2014 at 2:50 pm


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: