Author Photo

Ahmer's SysAdmin Recipes is a blog for Linux System Administrators. This blog provides recipes for Installation & Configuration of Linux, Ubuntu, Oracle Database, MySQL, Apache, Nginx, Oracle Cloud Control, FreeIPA, Kerberos & OpenLDAP, Subversion, PXE, DevOps, etc. over Red Hat Enterprise Linux (RHEL), CentOS, Ubuntu and Windows.

Please give me your feedback and help me improve this blog. Please let me know If you want me to write on a specific topic.

Sunday, 12 May 2019

Install NDOUtils for Nagios Core on CentOS 7

Install NDOUtils for Nagios Core on CentOS 7NDOUtils is a plugin for Nagios Core. By default, Nagios Core stores its data in flat files. NDOUtils allow us to export current and historical data from Nagios Core instance/s to a MySQL database. NDOUtils is included with Nagios XI (the commerical version of Nagios). Also many community addons uses NDOUtils as a data source. NDOUtils consist of a standalone daemon, a Nagios event broker and several helper utilities.

In this article, we will install NDOUtils for Nagios Core on CentOS 7. We are assuming that, you already have basic understanding of Nagios and related technologies. Otherwise, it is recommended that, you should read Learning Nagios - Third Edition by Packt Publishing to increase your knowledge in this area.

 

System Specification:

We have a CentOS 7 virtual machine with following specification.

Hostname: nagios-01.example.com
IP Address: 192.168.116.143/24
Operating System: CentOS 7.6
Nagios Version: Nagios Core 4.4

Before moving forward, make sure that you have configured a Nagios Core server. For installation steps, you can refer to our previous article Install & Configure Nagios Core 4.4 on CentOS 7.

 

Installing MariaDB Database on CentOS 7:

NDOUtils requires a MariaDB or MySQL database for storing Nagios Core data. Therefore, we are installing the available MariaDB server from CentOS 7 yum repository.

[root@nagios-01 ~]# yum install -y mariadb-server mariadb-devel mariadb ... Installed: mariadb-server.x86_64 1:5.5.60-1.el7_5 mariadb-devel.x86_64 1:5.5.60-1.el7_5 mariadb.x86_64 1:5.5.60-1.el7_5 Dependency Installed: perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7 perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7 perl-DBD-MySQL.x86_64 0:4.023-6.el7 perl-DBI.x86_64 0:1.627-4.el7 perl-IO-Compress.noarch 0:2.061-2.el7 perl-Net-Daemon.noarch 0:0.48-5.el7 perl-PlRPC.noarch 0:0.2020-14.el7 Complete!

Start and enable MariaDB service.

[root@nagios-01 ~]# systemctl start mariadb.service [root@nagios-01 ~]# systemctl enable mariadb.service Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.

Configure MariaDB database instance.

[root@nagios-01 ~]# mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation. Set root password? [Y/n] Y New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] Y ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] Y ... Success! By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] Y - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] Y ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!

 

Create a MariaDB database for NDOUtils:

Connect to nagios-01.example.com using ssh as root user.

Use mysql command to connect with MariaDB instance as root user.

[root@nagios-01 ~]# mysql -u root -p'123' Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 4 Server version: 5.5.60-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>

Use the following commands to create a database and user for NDOUtils.

MariaDB [(none)]> CREATE DATABASE nagios DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci; Query OK, 1 row affected (0.04 sec) MariaDB [(none)]> CREATE USER 'ndoutils'@'localhost' IDENTIFIED BY 'ahmer123'; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> GRANT USAGE ON *.* TO 'ndoutils'@'localhost' IDENTIFIED BY 'ahmer123' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> GRANT ALL PRIVILEGES ON nagios.* TO 'ndoutils'@'localhost' WITH GRANT OPTION ; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec)

Exit from mysql prompt.

MariaDB [(none)]> QUIT Bye

 

Adjust Kernel Parameters for NDOUtils:

Some Kernel Parameters are required to be set for NDOUtils.

Remove any previous setting of following Kernel parameters from /etc/sysctl.conf.

[root@nagios-01 ~]# sed -i '/msgmnb/d' /etc/sysctl.conf [root@nagios-01 ~]# sed -i '/msgmax/d' /etc/sysctl.conf [root@nagios-01 ~]# sed -i '/shmmax/d' /etc/sysctl.conf [root@nagios-01 ~]# sed -i '/shmall/d' /etc/sysctl.conf

Now, add required values for these parameters as follows.

[root@nagios-01 ~]# cat >> /etc/sysctl.conf << EOF > kernel.msgmnb = 131072000 > kernel.msgmax = 131072000 > kernel.shmmax = 4294967295 > kernel.shmall = 268435456 > EOF

Reload Kernel parameters from configuration files.

[root@nagios-01 ~]# sysctl -p kernel.msgmnb = 131072000 kernel.msgmax = 131072000 kernel.shmmax = 4294967295 kernel.shmall = 268435456

 

Installing NDOUtils for Nagios Core on CentOS 7:

Download NDOUtils source from SourceForge website.

[root@nagios-01 tmp]# wget -O ndoutils.tar.gz https://sourceforge.net/projects/nagios/files/ndoutils-2.x/ndoutils-2.1.3/ndoutils-2.1.3.tar.gz/download --2019-05-12 00:01:44-- https://sourceforge.net/projects/nagios/files/ndoutils-2.x/ndoutils-2.1.3/ndoutils-2.1.3.tar.gz/download Resolving sourceforge.net (sourceforge.net)... 216.105.38.13 Connecting to sourceforge.net (sourceforge.net)|216.105.38.13|:443... connected. HTTP request sent, awaiting response... 302 Found Location: https://downloads.sourceforge.net/project/nagios/ndoutils-2.x/ndoutils-2.1.3/ndoutils-2.1.3.tar.gz?r=&ts=1557601303&use_mirror=liquidtelecom [following] --2019-05-12 00:01:46-- https://downloads.sourceforge.net/project/nagios/ndoutils-2.x/ndoutils-2.1.3/ndoutils-2.1.3.tar.gz?r=&ts=1557601303&use_mirror=liquidtelecom Resolving downloads.sourceforge.net (downloads.sourceforge.net)... 216.105.38.13 Connecting to downloads.sourceforge.net (downloads.sourceforge.net)|216.105.38.13|:443... connected. HTTP request sent, awaiting response... 302 Found Location: https://liquidtelecom.dl.sourceforge.net/project/nagios/ndoutils-2.x/ndoutils-2.1.3/ndoutils-2.1.3.tar.gz [following] --2019-05-12 00:01:47-- https://liquidtelecom.dl.sourceforge.net/project/nagios/ndoutils-2.x/ndoutils-2.1.3/ndoutils-2.1.3.tar.gz Resolving liquidtelecom.dl.sourceforge.net (liquidtelecom.dl.sourceforge.net)... 197.155.77.8 Connecting to liquidtelecom.dl.sourceforge.net (liquidtelecom.dl.sourceforge.net)|197.155.77.8|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 2182958 (2.1M) [application/x-gzip] Saving to: ândoutils.tar.gzâ 100%[======================================>] 2,182,958 381KB/s in 6.4s 2019-05-12 00:01:55 (332 KB/s) - ândoutils.tar.gzâ saved [2182958/2182958]

Extract downloaded file.

[root@nagios-01 tmp]# tar xvf ndoutils.tar.gz ... ndoutils-2.1.3/startup/newbsd-init.in ndoutils-2.1.3/startup/openbsd-init.in ndoutils-2.1.3/startup/openrc-conf.in ndoutils-2.1.3/startup/openrc-init.in ndoutils-2.1.3/startup/rh-upstart-init.in ndoutils-2.1.3/startup/solaris-inetd.xml.in ndoutils-2.1.3/startup/solaris-init.xml.in ndoutils-2.1.3/startup/tmpfile.conf.in ndoutils-2.1.3/startup/upstart-init.in ndoutils-2.1.3/update-version

Compile NDOUtils binaries from source.

[root@nagios-01 tmp]# cd ndoutils-2.1.3 [root@nagios-01 ndoutils-2.1.3]# ./configure ... config.status: creating startup/tmpfile.conf config.status: creating startup/upstart-init config.status: creating startup/rh-upstart-init config.status: creating include/config.h *** Configuration summary for ndoutils 2.1.3 2017-04-13 ***: General Options: ------------------------- NDO2DB user: nagios NDO2DB group: nagios NDO2DB tcp port: 5668 Review the options above for accuracy. If they look okay, type 'make all' to compile the NDO utilities, or type 'make' to get a list of make options. [root@nagios-01 ndoutils-2.1.3]# make all ... make[2]: Leaving directory `/tmp/ndoutils-2.1.3/src' make ndomod-4x.o make[2]: Entering directory `/tmp/ndoutils-2.1.3/src' gcc -fPIC -fPIC -g -O2 -I/usr/include/mysql -DHAVE_CONFIG_H -I ../include/nagios-4x -D BUILD_NAGIOS_4X -o ndomod-4x.o ndomod.c io.o utils.o -shared -lnsl make[2]: Leaving directory `/tmp/ndoutils-2.1.3/src' gcc -fPIC -g -O2 -I/usr/include/mysql -DHAVE_CONFIG_H -o sockdebug sockdebug.c io.o utils.o -lm -lnsl make[1]: Leaving directory `/tmp/ndoutils-2.1.3/src'

Install NDOUtils binaries.

[root@nagios-01 ndoutils-2.1.3]# make install cd ./src && make install make[1]: Entering directory `/tmp/ndoutils-2.1.3/src' /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/bin /usr/bin/install -c -m 755 -o nagios -g nagios ndo2db-4x /usr/local/nagios/bin/ndo2db /usr/bin/install -c -m 755 -o nagios -g nagios ndomod-4x.o /usr/local/nagios/bin/ndomod.o /usr/bin/install -c -m 774 -o nagios -g nagios file2sock /usr/local/nagios/bin /usr/bin/install -c -m 774 -o nagios -g nagios log2ndo /usr/local/nagios/bin /usr/bin/install -c -m 774 -o nagios -g nagios sockdebug /usr/local/nagios/bin Hint: NDOUtils Installation against Nagios v4.x completed. If you want to install NDOUtils for Nagios v3.x please type 'make install-3x If you want to install NDOUtils for Nagios v2.x please type 'make install-2x Next step should be the database initialization/upgrade cd into the db/ directory and either: ./installdb (for a new installation) or: ./upgradedb (for an existing one) make[1]: Leaving directory `/tmp/ndoutils-2.1.3/src' Main NDOUtils components installed

Create database tables to store Nagios data.

[root@nagios-01 ndoutils-2.1.3]# cd db [root@nagios-01 db]# ./installdb -u 'ndoutils' -p 'ahmer123' -h 'localhost' -d nagios 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!

Ignore the failed warning, it is here to check if database is already initialized.

Install NDOUtils configuration files.

[root@nagios-01 ndoutils-2.1.3]# make install-config /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var /usr/bin/install -c -m 644 -o nagios -g nagios config/ndo2db.cfg-sample /usr/local/nagios/etc /usr/bin/install -c -m 644 -o nagios -g nagios config/ndomod.cfg-sample /usr/local/nagios/etc *** Config files installed *** Remember, these are *SAMPLE* config files. You'll need to rename the files in order to use them. Please read the documentation to know what they are doing.

Edit these configuration files according to your environment.

We are only defining MariaDB user credentials here leaving all the other settings as defaults.

[root@nagios-01 ndoutils-2.1.3]# cd /usr/local/nagios/etc/ [root@nagios-01 etc]# mv ndo2db.cfg-sample ndo2db.cfg [root@nagios-01 etc]# mv ndomod.cfg-sample ndomod.cfg [root@nagios-01 etc]# sed -i 's/^db_user=.*/db_user=ndoutils/g' ndo2db.cfg [root@nagios-01 etc]# sed -i 's/^db_pass=.*/db_pass=ahmer123/g' ndo2db.cfg

Install NDOUtils service.

[root@nagios-01 etc]# cd /tmp/ndoutils-2.1.3/ [root@nagios-01 ndoutils-2.1.3]# make install-init /usr/bin/install -c -m 644 startup/default-service /usr/lib/systemd/system/ndo2db.service

Start and enable ndo2db.service.

[root@nagios-01 ndoutils-2.1.3]# systemctl start ndo2db.service [root@nagios-01 ndoutils-2.1.3]# systemctl enable ndo2db.service Created symlink from /etc/systemd/system/multi-user.target.wants/ndo2db.service to /usr/lib/systemd/system/ndo2db.service.

 

Configure Nagios Core to user NDOUtils Broker Module:

Edit nagios.cfg file, so Nagios Core can use NDOUtils broker module.

[root@nagios-01 ndoutils-2.1.3]# cat >> /usr/local/nagios/etc/nagios.cfg << EOF > #NDOUtils Broker Module > broker_module=/usr/local/nagios/bin/ndomod.o config_file=/usr/local/nagios/etc/ndomod.cfg > EOF

Restart nagios.service to reload changes.

[root@nagios-01 ndoutils-2.1.3]# systemctl restart nagios.service

 

Test NDOUtils Integration with Nagios Core:

Check NDOUtils broker module is used by Nagios Core by quering Nagios logs.

[root@nagios-01 ndoutils-2.1.3]# grep ndo /usr/local/nagios/var/nagios.log [1557602671] ndomod: NDOMOD 2.1.3 (2017-04-13) Copyright (c) 2009 Nagios Core Development Team and Community Contributors [1557602671] ndomod: Successfully connected to data sink. 0 queued items to flush. [1557602671] ndomod registered for process data [1557602671] ndomod registered for timed event data [1557602671] ndomod registered for log data' [1557602671] ndomod registered for system command data' [1557602671] ndomod registered for event handler data' [1557602671] ndomod registered for notification data' [1557602671] ndomod registered for service check data' [1557602671] ndomod registered for host check data' [1557602671] ndomod registered for comment data' [1557602671] ndomod registered for downtime data' [1557602671] ndomod registered for flapping data' [1557602671] ndomod registered for program status data' [1557602671] ndomod registered for host status data' [1557602671] ndomod registered for service status data' [1557602671] ndomod registered for adaptive program data' [1557602671] ndomod registered for adaptive host data' [1557602671] ndomod registered for adaptive service data' [1557602671] ndomod registered for external command data' [1557602671] ndomod registered for aggregated status data' [1557602671] ndomod registered for retention data' [1557602671] ndomod registered for contact data' [1557602671] ndomod registered for contact notification data' [1557602671] ndomod registered for acknowledgement data' [1557602671] ndomod registered for state change data' [1557602671] ndomod registered for contact status data' [1557602671] ndomod registered for adaptive contact data' [1557602671] Event broker module '/usr/local/nagios/bin/ndomod.o' initialized successfully.

Check whether NDOUtils is forwarding entries to our MariaDB database.

[root@nagios-01 ndoutils-2.1.3]# echo 'select * from nagios.nagios_logentries;' | mysql -u ndoutils -p'ahmer123' logentry_id instance_id logentry_time entry_time entry_time_useclogentry_type logentry_data realtime_data inferred_data_extracted 1 1 2019-05-12 00:24:31 2019-05-12 00:24:31 767227 262144 ndomod registered for log data' 1 1 2 1 2019-05-12 00:24:31 2019-05-12 00:24:31 767255 262144 ndomod registered for system command data' 1 1 3 1 2019-05-12 00:24:31 2019-05-12 00:24:31 767270 262144 ndomod registered for event handler data' 1 1 4 1 2019-05-12 00:24:31 2019-05-12 00:24:31 767284 262144 ndomod registered for notification data' 1 1 5 1 2019-05-12 00:24:31 2019-05-12 00:24:31 767298 262144 ndomod registered for service check data' 1 1 6 1 2019-05-12 00:24:31 2019-05-12 00:24:31 767312 262144 ndomod registered for host check data' 1 1 7 1 2019-05-12 00:24:31 2019-05-12 00:24:31 767326 262144 ndomod registered for comment data' 1 1 8 1 2019-05-12 00:24:31 2019-05-12 00:24:31 767340 262144 ndomod registered for downtime data' 1 1 9 1 2019-05-12 00:24:31 2019-05-12 00:24:31 767354 262144 ndomod registered for flapping data' 1 1 10 1 2019-05-12 00:24:31 2019-05-12 00:24:31 767367 262144 ndomod registered for program status data' 1 1 11 1 2019-05-12 00:24:31 2019-05-12 00:24:31 767381 262144 ndomod registered for host status data' 1 1 12 1 2019-05-12 00:24:31 2019-05-12 00:24:31 767395 262144 ndomod registered for service status data' 1 1 13 1 2019-05-12 00:24:31 2019-05-12 00:24:31 767408 262144 ndomod registered for adaptive program data' 1 1 14 1 2019-05-12 00:24:31 2019-05-12 00:24:31 767422 262144 ndomod registered for adaptive host data' 1 1 15 1 2019-05-12 00:24:31 2019-05-12 00:24:31 767436 262144 ndomod registered for adaptive service data' 1 1 16 1 2019-05-12 00:24:31 2019-05-12 00:24:31 767449 262144 ndomod registered for external command data' 1 1 17 1 2019-05-12 00:24:31 2019-05-12 00:24:31 767463 262144 ndomod registered for aggregated status data' 1 1 18 1 2019-05-12 00:24:31 2019-05-12 00:24:31 767476 262144 ndomod registered for retention data' 1 1 19 1 2019-05-12 00:24:31 2019-05-12 00:24:31 767490 262144 ndomod registered for contact data' 1 1 20 1 2019-05-12 00:24:31 2019-05-12 00:24:31 767504 262144 ndomod registered for contact notification data' 1 1 21 1 2019-05-12 00:24:31 2019-05-12 00:24:31 767518 262144 ndomod registered for acknowledgement data' 1 1 22 1 2019-05-12 00:24:31 2019-05-12 00:24:31 767532 262144 ndomod registered for state change data' 1 1 23 1 2019-05-12 00:24:31 2019-05-12 00:24:31 767546 262144 ndomod registered for contact status data' 1 1 24 1 2019-05-12 00:24:31 2019-05-12 00:24:31 767560 262144 ndomod registered for adaptive contact data' 1 1 25 1 2019-05-12 00:24:31 2019-05-12 00:24:31 767574 262144 Event broker module '/usr/local/nagios/bin/ndomod.o' initialized successfully. 11 26 1 2019-05-12 00:24:31 2019-05-12 00:24:31 768861 8 Warning: Service 'Current Load' on host 'localhost' has no check time period defined! 1 1 27 1 2019-05-12 00:24:31 2019-05-12 00:24:31 768884 8 Warning: Service 'Current Users' on host 'localhost' has no check time period defined! 1 1 28 1 2019-05-12 00:24:31 2019-05-12 00:24:31 768900 8 Warning: Service 'HTTP' on host 'localhost' has no check time period defined! 11 29 1 2019-05-12 00:24:31 2019-05-12 00:24:31 768914 8 Warning: Service 'PING' on host 'localhost' has no check time period defined! 11 30 1 2019-05-12 00:24:31 2019-05-12 00:24:31 768929 8 Warning: Service 'Root Partition' on host 'localhost' has no check time period defined! 1 1 31 1 2019-05-12 00:24:31 2019-05-12 00:24:31 768944 8 Warning: Service 'SSH' on host 'localhost' has no check time period defined! 11 32 1 2019-05-12 00:24:31 2019-05-12 00:24:31 768958 8 Warning: Service 'Swap Usage' on host 'localhost' has no check time period defined! 1 1 33 1 2019-05-12 00:24:31 2019-05-12 00:24:31 768973 8 Warning: Service 'Total Processes' on host 'localhost' has no check time period defined! 1 1 34 1 2019-05-12 00:24:31 2019-05-12 00:24:31 768996 8 Warning: Service 'C: Drive Space' on host 'winserver' has no check time period defined! 1 1 35 1 2019-05-12 00:24:31 2019-05-12 00:24:31 769012 8 Warning: Service 'CPU Load' on host 'winserver' has no check time period defined!1 1 36 1 2019-05-12 00:24:31 2019-05-12 00:24:31 769026 8 Warning: Service 'Explorer' on host 'winserver' has no check time period defined!1 1 37 1 2019-05-12 00:24:31 2019-05-12 00:24:31 769040 8 Warning: Service 'Memory Usage' on host 'winserver' has no check time period defined! 1 1 38 1 2019-05-12 00:24:31 2019-05-12 00:24:31 769054 8 Warning: Service 'NSClient++ Version' on host 'winserver' has no check time period defined! 1 1 39 1 2019-05-12 00:24:31 2019-05-12 00:24:31 769068 8 Warning: Service 'Uptime' on host 'winserver' has no check time period defined! 11 40 1 2019-05-12 00:24:31 2019-05-12 00:24:31 769082 8 Warning: Service 'W3SVC' on host 'winserver' has no check time period defined! 11 41 1 2019-05-12 00:24:31 2019-05-12 00:24:31 769103 8 Warning: Contact 'nagiosadmin' has no host notification time period defined! 11 42 1 2019-05-12 00:24:31 2019-05-12 00:24:31 821974 262144 Successfully launched command file worker with pid 14112 1 1

We have successfully installed NDOUtils for Nagios Core on CentOS 7.

Install NDOUtils for Nagios Core on CentOS 7


YOU MIGHT ALSO LIKE:

No comments:

Post a Comment