×


Install NDOUtils in Ubuntu - Do it now

Are you trying to Install NDOUtils in Ubuntu?

This guide will help you.


NDOUtils allows you to export current and historical data from one or more Nagios instances to a MySQL database. Basically, the NDOUtils (Nagios Data Output Utilities) addon allows you to move status and event information from Nagios to a MySQL Database for later retrieval and processing.

Sometimes, our customers report that their Nagios core is not starting. This can be due to an outdated version of NDOUtils.

Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to perform NDOUtils installation on their servers.

In this context, we shall look into steps to install NDOUtils.


How to install NDOUtils in Ubuntu ?

Follow the steps given below to install NDOUtils in Ubuntu:

1. Installing MySQL

This can be done using the following commands:

$ sudo apt-get update
$ sudo apt-get install -y mysql-server libmysqlclient-dev libdbd-mysql-perl

Provide the root password if it prompts to while installing..

To check if MySQL is running we can use the following:

$ ps ax | grep mysql | grep -v grep

We will see an output similar to the one given below:

8142 ? Ssl 0:01 /usr/sbin/mysqld

2. Creating Database

NDOUtils requires creating a database known as Nagios.

Also, we will create a user account called ndoutils with the password ndoutils_password.

The storage location of the database will be the default location that MySQL uses.

i. The following command will connect to the local MySQL database engine interface.

$ mysql -u root -p'mypassword'

ii. After that execute the following four commands one by one:

CREATE DATABASE nagios DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE USER 'ndoutils'@'localhost' IDENTIFIED BY 'ndoutils_password';
GRANT USAGE ON *.* TO 'ndoutils'@'localhost' IDENTIFIED BY 'ndoutils_password' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;
GRANT ALL PRIVILEGES ON nagios.* TO 'ndoutils'@'localhost' WITH GRANT OPTION ;

iii. Then exit the local MySQL database engine interface.


iv. Run the following command to ensure that the database has been created:

$ echo 'show databases;' | mysql -u ndoutils -p'ndoutils_password' -h localhost

We can see the following output:

Database
information_schema
nagios
test

3. Modifying Linux Kernel Settings

NDOUtils uses the kernel message queue for transferring the data from Nagios to NDOUtils.

Here we will increase the default values the Kernel boots with to ensure it operates optimally.

i. Firstly, we will create a backup of  /etc/sysctl.conf file:

$ sudo cp /etc/sysctl.conf /etc/sysctl.conf_backup

ii. After that we need to execute the following commands:

$ sudo sed -i '/msgmnb/d' /etc/sysctl.conf
$ sudo sed -i '/msgmax/d' /etc/sysctl.conf
$ sudo sed -i '/shmmax/d' /etc/sysctl.conf
$ sudo sed -i '/shmall/d' /etc/sysctl.conf
$ sudo sh -c 'printf "\n\nkernel.msgmnb = 131072000\n" >> /etc/sysctl.conf'
$ sudo sh -c 'printf "kernel.msgmax = 131072000\n" >> /etc/sysctl.conf'
$ sudo sh -c 'printf "kernel.shmmax = 4294967295\n" >> /etc/sysctl.conf'
$ sudo sh -c 'printf "kernel.shmall = 268435456\n" >> /etc/sysctl.conf'
$ sudo sysctl -e -p /etc/sysctl.conf

iii. We do not have to reboot the system as the last command ensures that the new settings are active in the kernel.


4. Downloading NDOUtils Source

We can use the following commands for downloading NDOUtils:

$ cd /tmp
$ wget -O ndoutils.tar.gz https://github.com/NagiosEnterprises/ndoutils/archive/ndoutils-2.1.3.tar.gz
$ tar xzf ndoutils.tar.gz

5. Compiling NDOUtils

For compiling we can use the following commands:

$ cd /tmp/ndoutils-ndoutils-2.1.3/
$ sudo ./configure
$ sudo make all

6.  Installing Binaries

To install the binary files, we can run the following command:

$ sudo make install

7. Initializing Database

This prepares the database for NDOUtils:

$ cd db/
$ sudo ./installdb -u 'ndoutils' -p 'ndoutils_password' -h 'localhost' -d nagios
$ cd ..

The command will produce output similar to the following:

DBD::mysql::db do failed: Table 'nagios.nagios_dbversion' doesn't exist at ./installdb line 52.
** Creating tables for version 2.0.1
Using mysql.sql for installation...
** Updating table nagios_dbversion
Done!

We can ignore the first line of output that says failed: Table 'nagios.nagios_dbversion' .


8. Installing Configuration Files

The two config files are:

i. /usr/local/nagios/etc/ndo2db.cfg

The following lines are defined in this file:

db_user=ndoutils
db_pass=ndoutils_password

We should make sure the username and password are correct.


ii.  /usr/local/nagios/etc/ndomod.cfg

No changes are required in this file.

Using the default username and password, the following commands will install the configuration files

$ sudo make install-config
$ sudo mv /usr/local/nagios/etc/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg
$ sudo sh -c 'sed -i 's/^db_user=.*/db_user=ndoutils/g' /usr/local/nagios/etc/ndo2db.cfg'
$ sudo sh -c 'sed -i 's/^db_pass=.*/db_pass=ndoutils_password/g' /usr/local/nagios/etc/ndo2db.cfg'
$ sudo mv /usr/local/nagios/etc/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg

9. Install Service/Daemon

For Ubuntu 13.x/14.x

$ sudo make install-init

For Ubuntu 15.x/16.x/17.x

$ sudo make install-init
$ sudo systemctl enable ndo2db.service

10. Start Service/Daemon

Different Linux distributions have different methods of starting the ndo2db service.

For Ubuntu 13.x/14.x

$ sudo service ndo2db start

For Ubuntu 15.x/16.x/17.x

$ sudo systemctl start ndo2db.service

11. Updating Nagios To Use NDO Broker Module

Now we need to tell Nagios to use the NDO broker module.

We can add the following line to the nagios.cfg file:

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

The following commands will add that line as well as an extra line that explains what the module is for.

$ sudo sh -c 'printf "\n\n# NDOUtils Broker Module\n" >> /usr/local/nagios/etc/nagios.cfg'
$ sudo sh -c 'printf "broker_module=/usr/local/nagios/bin/ndomod.o config_file=/usr/local/nagios/etc/ndomod.cfg\n" >> /usr/local/nagios/etc/nagios.cfg'

12. Restarting Nagios

Now we need to restart Nagios to use the NDO broker module. Different Linux distributions have different methods of restarting Nagios Core. 

We will also check the status of the Nagios service to ensure it is running after these changes.


Ubuntu 13.x/14.x

$ sudo service nagios restart
$ sudo service nagios status

Ubuntu 15.x/16.x/17.x

$ sudo systemctl restart nagios.service
$ sudo systemctl status nagios.service

The last command should show Nagios running:

Ubuntu 13.x/14.x

nagios (pid 5345) is running…

Ubuntu 15.x/16.x/17.x

● nagios.service – LSB: Starts and stops the Nagios monitoring server
Loaded: loaded (/etc/rc.d/init.d/nagios)
Active: active (running) since Tue 2021-03-30 12:31:00 AEDT; 22s ago

13. Check NDOUtils Is Working

There are a couple of different ways to ensure NDO2DB is working.

This command will show Nagios successfully loaded the NDO module:

$ grep ndo /usr/local/nagios/var/nagios.log

The last command should output something like:

[1475544660] ndomod: NDOMOD 2.1.1 (09-06-2016) Copyright (c) 2009 Nagios Core Development Team and Community Contributors
[1475544660] ndomod: Successfully connected to data sink. 0 queued items to flush.
[1475544660] ndomod registered for process data
[1475544660] ndomod registered for timed event data
[1475544660] ndomod registered for log data'
[1475544660] ndomod registered for system command data'
[1475544660] ndomod registered for event handler data'
[1475544660] ndomod registered for notification data'
[1475544660] ndomod registered for service check data'
[1475544660] ndomod registered for host check data'
[1475544660] ndomod registered for comment data'
[1475544660] ndomod registered for downtime data'
[1475544660] ndomod registered for flapping data'
[1475544660] ndomod registered for program status data'
[1475544660] ndomod registered for host status data'
[1475544660] ndomod registered for service status data'
[1475544660] ndomod registered for adaptive program data'
[1475544660] ndomod registered for adaptive host data'
[1475544660] ndomod registered for adaptive service data'
[1475544660] ndomod registered for external command data'
[1475544660] ndomod registered for aggregated status data'
[1475544660] ndomod registered for retention data'
[1475544660] ndomod registered for contact data'
[1475544660] ndomod registered for contact notification data'
[1475544660] ndomod registered for acknowledgement data'
[1475544660] ndomod registered for state change data'
[1475544660] ndomod registered for contact status data'
[1475544660] ndomod registered for adaptive contact data'
[1475544660] Event broker module '/usr/local/nagios/bin/ndomod.o' initialized successfully.


Service Commands for NDOUtils in Ubuntu

Different Linux distributions have different methods of starting/stopping/restarting/status ndo2db following are some service commands:


Ubuntu 13.x/14.x

$ sudo start ndo2db
$ sudo stop ndo2db
$ sudo restart ndo2db
$ sudo status ndo2db

Ubuntu 15.x/16.x/17.x

$ sudo systemctl start ndo2db.service
$ sudo systemctl stop ndo2db.service
$ sudo systemctl restart ndo2db.service
$ sudo systemctl status ndo2db.service


How to fix ndo2db not running?

So far we saw how to install NDOUtils in Ubuntu now we will see how to fix one of the common error seen with NDOUtils.

Nagios server shuts off unexpectedly and we can see the "database backend" with a red exclamation in the web GUI.

And when we try to start the process, it comes back with ndo2db is not running.


Steps to fix ndo2db not running issue:

1. Firstly, we will verify whether ndo2db is not running using the following command:

# service ndo2db status
ndo2db is not running

2. After that, we will stop the Nagios service for not interrupting any processes.

# service nagios stop

3. Then we will run the ‘ls’ command to find the output similar to the one given below:

# ls -l /usr/local/nagios/var/ndo*
-rw-r--r-- 1 nagios nagios 0 Oct 18 09:02 /usr/local/nagios/var/ndo2db.debug
-rw-r--r-- 1 nagios nagios 6 Oct 23 10:13 /usr/local/nagios/var/ndo2db.lock
-rw-r--r-- 1 nagios nagios 0 Nov 12 12:43 /usr/local/nagios/var/ndomod.tmp
srwxr-xr-x 1 nagios nagios 0 Oct 23 10:13 /usr/local/nagios/var/ndo.sock

4. Now we will rename/move the two files using the following commands:

# mv /usr/local/nagios/var/ndo2db.lock /usr/local/nagios/var/ndo2db.lock.bak
# mv /usr/local/nagios/var/ndo.sock /usr/local/nagios/var/ndo.sock.bak

5. After that, we will restart the Nagios service and ndo2db service using the following commands:

# service nagios start
# service ndo2db start
Finally, we will run the service status command to verify it is now running.
# service ndo2db status
ndo2db (pid 3047) is running...


[Need assistance in installing Missing Packages on Ubuntu Server? We are available 24*7. ]


Conclusion

This article covers how to install NDOUtils in Ubuntu. NDOUtils is basically the Database Output for Nagios Core. 

NDOUtils stands for Nagios Data Output Utilities which is an addon that allows you to move status and event information from Nagios to a MySQL Database for later retrieval and processing.


NDOUtils consists of the following parts:

1. The NDOMOD event broker module. This module is intended to be loaded by the Nagios process at runtime. Its only role is to dump all events and data from Nagios to a TCP socket or a regular file or Unix domain socket on the local filesystem somewhere. If you want Realtime transfer of data to MySQL, dump the data to a TCP or Unix domain socket. If you want delayed transfer of data into MySQL (i.e. you need to transfer the data to another host first), dump the data to a regular file.


2. The NDO2DB daemon. This standalone daemon reads input (that was produced by the NDOMOD broker module) from a TCP or Unix domain socket, parses that data, and then dumps it into one or more MySQL databases. The daemon is capable of handling multiple client connections simultaneously, so you can have multiple instances of the NDOMOD module writing to the same TCP or Unix domain socket at the same time.


3. The FILE2SOCK utility. This simple utility reads data from a standard file and dumps it to either a TCP or a Unix domain socket. This is useful if you are having the NDOMOD module write to a standard file that you later want to send to the NDO2DB daemon. If the module and the daemon are running on different machines, you can periodically use SSH to transfer the file from the monitoring machine to the machine running the NDO2DB daemon, and then use the FILE2SOCK utility to send the contents of that file to the TCP socket or Unix domain socket that the NDO2DB daemon is reading.


4. The LOG2NDO utility. This utility is used for importing historical log archives from NetSaint and Nagios and sending them to the NDO2DB daemon. It takes a single log file as its input and can output data to either a TCP socket, a Unix domain socket or standard output.


To compile the NDO broker module, NDO2DB daemon, and additional utilities:

1. Run the commands below;

./configure

make all

2. If the configure script is unable to locate your MySQL development libraries, you may need to help it out by using the --with-mysql-lib option. 

Here's an example:

./configure --with-mysql-lib=/usr/lib/mysql


NDOUTILS Tuning Kernel Parameters includes:

NDOUTILS uses a single message queue to communicate between the broker module and the NDO2DB daemon. Depending on the operating system, there may be parameters that need to be tuned in order for this communication to work correctly.

1. kernel.msgmax is the maximum size of a single message in a message queue

2. kernel.msgmni is the maximum number of messages allowed in any one message queue

3. kernel.msgmnb is the total number of bytes allow in all messages in any one message queue


How to initialize the Database for NDOUtils installation:

Before you start using NDOUtils, you should create the database where you will be storing all Nagios related information.

Note: Only MySQL Databases are supported!

i. Create a database for storing the data (e.g. nagios)

ii. Create a username/password that has at least the following privileges for the database:

SELECT, INSERT, UPDATE, DELETE

iii. Run the DB installation script in the db/ subdirectory of the NDO distribution to create the necessary tables in the database.

cd db

./installdb

iv. Make sure the database name, prefix, and username/password you just created and setup match the variable specified in the NDO2DB config file.