In this recipe, you'll learn how to install the NDOUtils extension to Nagios Core in order to have all of Nagios Core's configuration and data written into a MySQL database. This allows us to easily develop custom reports and interfaces for Nagios Core data with languages such as Perl and PHP and their standard interfaces for the popular MySQL server, as opposed to interacting with Nagios Core's own logs or data format. Some plugins such as NagVis use this format to read information about Nagios Core configuration and objects.
You will need a Nagios Core server version 4.0 or later. NDOUtils will probably still get installed and work on older versions of Nagios Core, but the installation process is slightly different; refer to the INSTALL
file included in the NDO source for more information on this.
Nagios Core uses its event broker functionality to write information to the socket for the MySQL database to pick up. You will need to compile Nagios Core with the --enable-event-broker
flag:
$ ./configure --enable-event-broker $ make # make install
If you are unsure whether you've compiled Nagios Core with this flag, it is probably a good idea to recompile and reinstall Nagios Core from your original sources with this installed. Don't forget to back up your previous installation in case of problems.
In order to compile the ndomod
part of NDOUtils, you will need to have the MySQL client libraries and headers installed on the Nagios Core server. You will also need to have a MySQL server ready to store the data. You don't need to run the MySQL server on the same host as Nagios Core, but the Nagios Core server should be able to connect to it.
Finally, you should take note of the opening paragraph of README
, which at the time of writing points out that NDOUtils for Nagios Core 4.0 is still officially in beta; you should read the note and be aware of the risks in installing it. In the author's own experience, however, the code is stable.
We can install the NDOUtils package for Nagios Core as follows:
.tar.gz
from its Sourceforge site at http://sourceforge.net/projects/nagios/files/ndoutils-2.x/:$ wget http://downloads.sourceforge.net/project/nagios/ndoutils-2.x/ndoutils-2.0.0/ndoutils-2.0.0.tar.gz
.tar.gz
and change into the uncompressed directory:$ tar xzf ndoutils-2.0.0.tar.gz $ cd ndoutils-2.0.0
./configure
and make
to build the software. Note that there is no install
target; we will be performing the installation manually:$ ./configure $ make
Read the output of ./configure
carefully if the build fails, to determine if you are missing any dependencies on your system. The output of ./configure
should end with something like this:
*** Configuration summary for ndoutils 2.0.0 02-28-2014 ***: General Options: ------------------------- NDO2DB user: nagios NDO2DB group: nagios Review the options above for accuracy. If they look okay, type 'make' to compile the NDO utilities.
olympus.example.net
), so the access will be done from localhost
:mysql> CREATE DATABASE nagios; Query OK, 1 row affected (0.10 sec) mysql> CREATE USER 'ndo'@'localhost' IDENTIFIED BY 'mPYxbAYqa'; Query OK, 0 rows affected (0.62 sec) mysql> GRANT ALL ON nagios.* TO 'ndo'@'localhost'; Query OK, 0 rows affected (0.02 sec)
We have used a random password after IDENTIFIED BY
. You should generate your own secure password.
installdb
script in the source to create the various tables Nagios Core will use. Use the database details established in the previous step:$ cd db $ ./installdb -u ndo -p mPYxbAYqa -h localhost -d nagios ** Creating tables for version 2.0.1 Using mysql.sql for installation... ** Updating table nagios_dbversion Done!
Don't be concerned about the following error message; it appears because you are installing the extension for the first time:
DBD::mysql::db do failed: Table 'nagios.nagios_dbversion' doesn't exist at ./installdb line 51.
ndomod-4x.o
module into the /usr/local/nagios/bin
directory:# cd .. # cp src/ndomod-4x.o /usr/local/nagios/bin/ndomod.o
/usr/local/nagios/etc
:# cp config/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg
nagios
user:# chown nagios.nagios /usr/local/nagios/etc/ndomod.cfg # chmod 0600 /usr/local/nagios/etc/ndomod.cfg
nagios.cfg
file:# vi /usr/local/nagios/etc/nagios.cfg
broker_module
definition to the file and verify that the event_broker_options
directive is set to -1
:broker_module=/usr/local/nagios/bin/ndomod.o config_file=/usr/local/nagios/etc/ndomod.cfg event_broker_options=-1
Note that the broker_module
and config_file
definitions should be on the same line, but event_broker_options
should be on a seperate line.
With this done, the broker module is said to be successfully installed and we can move on to installing the ndo2db
daemon. To install the same, follow these steps:
ndo2db-4x
binary into the /usr/local/nagios/bin
directory:# cp src/ndo2db-4x /usr/local/nagios/bin/ndo2db
/usr/local/nagios/etc
:# cp config/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg
nagios
user:# chown nagios.nagios /usr/local/nagios/etc/ndo2db.cfg # chmod 0600 /usr/local/nagios/etc/ndo2db.cfg
# vi /usr/local/nagios/etc/ndo2db.cfg
ndo2db.cfg
to reflect the database details:db_host=localhost db_port=3306 db_name=nagios db_user=ndo db_pass=mPYxbAYqa
ndo2db
daemon by starting it and verifying that it is running with pgrep(1)
:# /usr/local/nagios/bin/ndo2db -c /usr/local/nagios/etc/ndo2db.cfg # pgrep ndo2db 32285
If it works, you should add this command into your system's init
scripts so that the daemon is started at boot time. The daemon-init
file in the distribution may be helpful regarding this.
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg # /etc/init.d/nagios restart
nagios_services
table:$ mysql --user=ndo --password --database=nagios mysql> select count(1) from nagios_services; +----------+ | count(1) | +----------+ | 54 | +----------+ 1 row in set (0.00 sec)
NDOUtils is in fact a collection of components, two of which we have installed in the previous section:
ndomod.o
: This is used as a broker module to write events and data from Nagios Core to a Unix socket in /usr/local/nagios/var/ndo.sock
. It runs as a module of the Nagios Core server.ndo2db
: This is used as a database backend to read the events and data from the Unix socket to which ndomod
writes and to apply them as MySQL database operations. It runs independently as a daemon on the system and performs the MySQL connections and transactions.The broker_module
command updates these tables as plugins are run, hosts and services change state, notifications are issued, and other Nagios Core behavior takes place. It covers most of the data of interest to us quite comprehensively. Note that it includes the following information:
The main reason to install NDOUtils is to put Nagios Core's data into a standardized format so that it can be read and processed by external applications, whether simple table-style reports or completely new application interfaces to the Nagios Core data. This tends to be much easier than custom building a Nagios Core CGI of your own!
NDOUtils is useful, but some administrators find the overhead of maintaining the database server for it unnecessary. For very large installations with a lot of configuration and historical data, queries on the data can also be slow or otherwise delayed. This leads many administrators to prefer the use of MK Livestatus as an alternative. This program is also discussed in this chapter in the Reading status from a UNIX socket with MK Livestatus recipe.
To get the most out of NDOUtils, it's a good idea to take a look at its documentation at https://assets.nagios.com/downloads/nagioscore/docs/ndoutils/NDOUtils.pdf.
3.15.219.217