CentLinux | Learn How to Install CentOS/Rocky Linux Servers

Sunday, February 24, 2019

Install NagiosQL Nagios Configurator on CentOS 7

Install NagiosQL Nagios Configurator on CentOS 7

Nagios Core is an free and open source Nework, Server and Application monitoring software. A drawback of Nagios Core is that it lacks a configuration tool, therefore we have to edit configurations files using a text editor. Manually editing configuration files is always a headache and highly prone to typostatic errors.

NagiosQL is a web based configurator for Nagios Core. It completely integrates with Nagios Core and makes configuration management much easier. We have configured another Nagios configurator: Lilac Reloaded in our previous article.

In this article, we will install NagiosQL Nagios configurator on CentOS 7 based Nagios Core server. 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 enhance your knowledge in this area.

Install NagiosQL Nagios Configurator on CentOS 7

Table of Contents:

 

System Specification:

We are using the same CentOS 7 virtual machine, on which we have configured Nagios Core 4.4.

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

 

Installing MariaDB Database on CentOS 7:

NagiosQL requires MariaDB or MySQL database for creating its repository. Therefore, we are installing the available MariaDB server from CentOS 7 yum repository.

# yum install -y mariadb-server

Start and enable MariaDB service.

# systemctl enable mariadb.service
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
# systemctl start mariadb.service

Configure MariaDB database instance.

# 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!

 

Installing Apache HTTP server on CentOS 7:

Since, we are installing on the same server, on which we are running Nagios Core, then there is no need to install Apache HTTP server, because it was already installed during Nagios Core configurations.

 

Installing or Upgrading PHP on CentOS 7:

Since, we are installing on the same server, on which we have configured Nagios Core. Therefore, we have already installed PHP 5.4 on it during Nagios Core configurations. But NagiosQL required PHP 5.5 or above, therefore, we have to upgrade PHP from 5.4 to 5.5.

PHP 5.5 is available through various third party yum repositories. Therefore, we are installing webtatic yum repository.

But first, install EPEL (Extra Packages for Enterprise Linux) as a prerequisite for webtatic yum repository.

# yum install -y epel-release

Download and install webtatic yum repository RPM from Webtatic Website according to your Linux version.

# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
Retrieving https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
warning: /var/tmp/rpm-tmp.OjmyAU: Header V4 RSA/SHA1 Signature, key ID 62e74ca5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:webtatic-release-7-3             ################################# [100%]

Build yum cache for newly added yum repositories.

# yum makecache fast
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
epel/x86_64/metalink                                     | 7.7 kB     00:00
 * base: mirrors.ges.net.pk
 * epel: mirror1.ku.ac.th
 * extras: mirrors.ges.net.pk
 * updates: mirrors.ges.net.pk
 * webtatic: uk.repo.webtatic.com
base                                                     | 3.6 kB     00:00
extras                                                   | 3.4 kB     00:00
updates                                                  | 3.4 kB     00:00
webtatic                                                 | 3.6 kB     00:00
(1/2): webtatic/x86_64/group_gz                            |  448 B   00:00
(2/2): webtatic/x86_64/primary_db                          | 144 kB   00:02
Metadata Cache Created

Remove current version of PHP.

# yum remove -y php-common php php-gd php-cli

Install PHP 5.5 from webtatic yum repository.

# yum install -y php55w-common php55w php55w-gd php55w-cli php55w-mysql php55w-devel php55w-pear

Install libssh2-devel package required by PHP.

# yum install -y libssh2-devel

Install ssh2 extension for PHP from PECL (PHP Extension Community Library).

# pecl channel-update pecl.php.net
Updating channel "pecl.php.net"
Update of Channel "pecl.php.net" succeeded
# pecl install ssh2
...
Build process completed successfully
Installing '/usr/lib64/php/modules/ssh2.so'
install ok: channel://pecl.php.net/ssh2-0.13
configuration option "php_ini" is not set to php.ini location
You should add "extension=ssh2.so" to php.ini

Add following directives in /etc/php.ini.

# echo "date.timezone='Asia/Karachi'" >> /etc/php.ini
# echo "extension=ssh2.so" >> /etc/php.ini

Restart Apache service.

# systemctl restart httpd

We have installed all the NagiosQL prerequisite packages on our CentOS 7 server.

 

Installing NagiosQL on CentOS 7:

NagiosQL is available at Nagios Exchange and SourceForge. While you can also download NagiosQL Documentation from SourceForge website.

Download NagiosQL latest version and copy it in home directory of root user.

# tar xjf nagiosql-3.4.0.tar.bz2 -C /var/www/html/

# mv /var/www/html/nagiosql-3.4.0/ /var/www/html/nagiosql

Reapply SELinux security context for /var/www/html/nagiosql/ directory.

# restorecon -Rv /var/www/html/nagiosql/

Create a directory for NagiosQL to place Nagios Core configuration files.

# mkdir /usr/local/nagios/etc/nagiosql
# chown apache:apache /usr/local/nagios/etc/nagiosql/

Give write permission to all users on config directory for creating configuration files.

# chmod o+w /var/www/html/nagiosql/config

Browse URL http://nagios-01.example.com/nagiosql/ to run NagiosQL installation wizard.

nagiosql-installation-wizard-01

Since, we are running NagiosQL installation wizard for the first time and there isn’t any settings.php file exists in config folder, therefore the wizard is giving us the following warning

“Settings file not found or not readable (config/settings.php). Upgrade not available!”

It is save to ignore it.

Click on START INSTALLATION.

nagiosql-installation-requirements-01

NagiosQL installation wizard is checking for requirments and will give warnings, if a prerequisite is missing.

If you have followed the steps above correctly, then it won’t give you any warning.

Click on Next.

nagiosql-installation-setup-01

Define the settings according to the above screenshot.

Click on Next.

nagiosql-installation-finishing-setup-01

Click on Next.

If everything goes fine, then you will reach at the NagiosQL login page.

nagiosql-login-01

Login as admin user.

nagiosql-dashboard-01

 

NagiosQL Post Installation Configurations:

NagiosQL has been installed, we can now delete install directory to prevent anyone to run installation wizard again.

# rm -rf /var/www/html/nagiosql/nagiosql-3.4.0/install/

We have successfully generated settings.php file. Therefore, revoke write permissions from other users for security.

# chmod o-w /var/www/html/nagiosql/config

 

Import Nagios Core configuration in NagiosQL:

NagiosQL is installed with zero configurations, therefore, we have to import our existing Nagios Core configurations.

Go to Administration > Config Targets.

nagiosql-config-target-01

Click on Modify under Function column.

nagiosql-domain-administration-01

Adjust directory paths according to you environment and click on Save.

Go to Tools > Data Import.

Select all import files and click on Import.

nagiosql-import-files-01

Go to Supervision tab and you may observe that there are now some active groups has been imported.

nagiosql-define-services-01

File status is missed because we haven’t save our files yet. Therefore, Click on Write all config files.

nagiosql-define-services-02

You may observe that the file status is now up-to-date.

Repeat the process for other targets/configurations like hosts, commands, templates, etc to save them in NagiosQL configure directory.

Finally, we have to edit nagios.cfg file to remove current cfg_dir directives and add our new configuration directory actively managed by NagiosQL. This can be achieved by following two commands.

# sed -i 's/^cfg/#cfg/' /usr/local/nagios/etc/nagios.cfg
# echo "cfg_dir=/usr/local/nagios/etc/nagiosql/" >> /usr/local/nagios/etc/nagios.cfg

Restart nagios.service to check is there any configuration errors.

# systemctl restart nagios.service

If you have performed above steps correctly, then there should be no error.

Now, Nagios Core is using configurations from NagiosQL configuration directory.

We have successfully installed NagiosQL Nagios Configurator on CentOS 7 server.

If you find this article useful? Consider supporting us by Buy Me A Coffee


28 comments:

  1. Hi Sir It was a good post . Can you please post how to install NAGIOSQL along with ICINGA2 .

    ReplyDelete
    Replies
    1. Thank you. I will surely work on your requirement but its need a little time.

      Delete
    2. Thanks for your response . I haven't seen any thread relating to it . Will eagerly wait for your update .

      Delete
  2. Hi Ahmer. Great work.

    ReplyDelete
  3. Hello Ahmer,

    Afeter following all the above steps, I found this problem when restarting Nagios:
    Error: Failed to locate check_period '24x7' for host 'hplj2605dn'!
    Error: Could not register host (config file '/usr/local/nagios/etc/nagiosql/hosts/hplj2605dn.cfg', starting on line 16)
    Do you have any ideas about this error?
    Thanks beforehand

    ReplyDelete
    Replies
    1. Hi,
      Make sure that you have imported timeperiods.cfg in nagiosql.
      Also, this host file (hplj2605dn.cfg) is related to a printer. and you can safely remove it, if do not want to configure a printer.

      Delete
  4. Hello,
    I get this error at the end

    [root@nagios01 etc]# systemctl restart nagios.service
    Job for nagios.service failed because the control process exited with error code. See "systemctl status nagios.service" and "journa lctl -xe" for details.


    [root@nagios01 etc]# systemctl status nagios.service
    ● nagios.service - Nagios Core 4.4.3
    Loaded: loaded (/usr/lib/systemd/system/nagios.service; enabled; vendor preset: disabled)
    Active: failed (Result: exit-code) since Wed 2019-04-17 14:56:32 PDT; 7min ago
    Docs: https://www.nagios.org/documentation
    Process: 24140 ExecStopPost=/usr/bin/rm -f /usr/local/nagios/var/rw/nagios.cmd (code=exited, status=0/SUCCESS)
    Process: 24137 ExecStop=/usr/bin/kill -s TERM ${MAINPID} (code=exited, status=0/SUCCESS)
    Process: 24142 ExecStartPre=/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg (code=exited, status=1/FAILURE)
    Main PID: 7011 (code=exited, status=0/SUCCESS)

    Apr 17 14:56:32 nagios01.cci.local nagios[24142]: Check your configuration file(s) to ensure that they contain valid
    Apr 17 14:56:32 nagios01.cci.local nagios[24142]: directives and data definitions. If you are upgrading from a previous
    Apr 17 14:56:32 nagios01.cci.local nagios[24142]: version of Nagios, you should be aware that some variables/definitions
    Apr 17 14:56:32 nagios01.cci.local nagios[24142]: may have been removed or modified in this version. Make sure to read
    Apr 17 14:56:32 nagios01.cci.local nagios[24142]: the HTML documentation regarding the config files, as well as the
    Apr 17 14:56:32 nagios01.cci.local nagios[24142]: 'Whats New' section to find out what has changed.
    Apr 17 14:56:32 nagios01.cci.local systemd[1]: nagios.service: control process exited, code=exited status=1
    Apr 17 14:56:32 nagios01.cci.local systemd[1]: Failed to start Nagios Core 4.4.3.
    Apr 17 14:56:32 nagios01.cci.local systemd[1]: Unit nagios.service entered failed state.
    Apr 17 14:56:32 nagios01.cci.local systemd[1]: nagios.service failed.
    [root@nagios01 etc]#

    ReplyDelete
    Replies
    1. Hi,
      It looks like, you may have some syntax errors in Nagios configuration files.
      Use following command to find these errors.

      # nagios -v /usr/local/nagios/etc/nagios.cfg

      Rectify all errors and then start nagios service.

      Delete
    2. I have the same issue as above. If I try and run the command nagios -v /usr/local/nagios/etc/nagios.cfg I get an error message -bash: nagios: command not found.

      What am I doing wrong?

      Delete
    3. Hi,
      You might have problem with your nagios installation. Reinstall it please.

      Delete
  5. Hi, I follow your procedure, and in he last step, an error occurs:

    "Job for nagios.service failed because the control process exited with error code. See "systemctl status nagios.service" and "journalctl -xe" for details."

    And Nagios don't start anymore.

    The web interface it is working, but this is the message "Unable to get process status"

    And the log is:

    [05-24-2019 15:09:36] Successfully shutdown... (PID=9027)
    Program End[05-24-2019 15:09:36] Caught SIGTERM, shutting down...
    Program End[05-24-2019 15:09:36] Caught SIGTERM, shutting down...



    What could be the problem?

    Thanks in advance.

    Best regards.


    ReplyDelete
    Replies
    1. Hi,
      Usually, this kind of problem is encountered due to typo-static error in config files.
      Therefore, you should check you config files using following command.

      /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

      and rectify any possible error.

      Delete
  6. I am encountering an issue with not being able to use two Nagios Control Buttons:
    Check Configuration Files - error: Cannot find the Nagios binary or no execute permissions!
    And
    Restart Nagios: Nagios daemon is not running, cannot send restart command!

    Everything else is working between Nagiosql and Nagios.

    ReplyDelete
    Replies
    1. Hi,
      It looks like that you have some file permission issue with Nagios configuration files. Pls check and rectify.

      Delete
  7. Hi, I have a problem - I cant get nagiosql to populate nagios core. I have added a host in nagiosql but when i checked nagios core it is not showing up. Any assistance will be highly appreciated.

    ReplyDelete
    Replies
    1. If service is started successfully, then verify that you have place the configuration file at correct location and with required privileges.

      Delete
  8. Great document.
    I am having an issue where checks will not send notifications until the host goes into a down state.
    Do you know why?

    Dennis

    ReplyDelete
    Replies
    1. Thank you.
      Please discuss it on our Facebook Page. Elaborate your problem there and it is even better if you can share a screenshot of the problem.

      Delete
    2. Ahmer,
      Thank you for your time. I found the answer (RTFM....) and it was Max. Check attempts *.
      I misunderstood it in the beginning and set it to 999999 thinking it would continually check.
      Now i see it would check but only be in a soft state so no alerts.
      I will check out the FB page.

      Dennis

      Delete
  9. I have problem in "tar xvjf nagiosql-3.4.0.tar.bz2 -C /var/www/html/" should I first download it with wget?

    ReplyDelete
  10. Hello,
    after i setup the nagiosql plugin i got an error 500, the httpd error log does not help me. any suggetions?

    ReplyDelete
    Replies
    1. Please discuss this issue with me on our Facebook Page.

      Delete
  11. Hi, very helpful, was able to go about on some errors, but when I do Write All config - the file will go out-of-date. actually ever since still out of date, but it is working though. I was able to add host and services

    ReplyDelete
  12. Nagios daemon is not running, cannot send restart command! can you help me resolve this issue

    ReplyDelete
    Replies
    1. Hi, this problem is too generic, use journalctl to look for the actual cause.
      Please contact us at Facebook page, if the problem remain unresolved.

      Delete

© 2023 CentLinux. All Rights Reserved.