Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webinterface doesn't read cgi.cfg file from the specified (modified) path #928

Open
simobri opened this issue Aug 21, 2023 · 0 comments
Open
Labels

Comments

@simobri
Copy link

simobri commented Aug 21, 2023

Dear all,

I think there are some issue with the configuration file parsing about the cgi.cfg file from the WebUI

Premise that this is a fresh install from source, without any configuration (yet).
Also the PHP and Apache are compiled from source

I installed the latest version of Nagios 4.4.14 on a Ubuntu 22.04LTS machine, with the following compiling options:

./configure --prefix=/hsr/app/nagios-4.4.14 --with-nagios-user=nagios --with-nagios-group=nagios --with-command-group=nagioscmd --with-lockfile=/var/lock/nagios/nagios.lock --with-httpd-conf=/hsr/app/apache2/conf/conf.d/sites-avaiable --with-mail --with-ssl --with-htmurl= --with-cgiurl=/cgi-bin

Costomized the Apache configuration to make it a virtual host. And all works fine. Then since I need to clusterize the daemon with pacemaker between multiple noes; I copy (preserving file permissions) the /etc and /var folders to another path (available to all nodes): /hafs/app/nagios/ and make the necessary path changes inside the /hafs/app/nagios/etc/nagios.cfg and /hafs/app/nagios/etc/cgi.cfg file to match the new paths properly. Also update the systemd unit file to start the daemon with the proper parameters:

ExecStart=/hsr/app/nagios-4.4.14/bin/nagios -d /hafs/app/nagios/etc/nagios.cfg

Nagios daemon start and work properly, without any issue; while the WebUI doesn't and report the error: "process is not running".

So, searching inside the <prefixdir>/share/ directory, I found that the file config.inc.php, have references about the following configuration files: cgi.cfg, nagios.cfg, status.dat and retention.dat; with absolute paths. Since has been moved elsewhere, I adapt them to the correct one:

$cfg['cgi_config_file']='/hafs/app/nagios/etc/cgi.cfg';  // location of the CGI config file

// FILE LOCATION DEFAULTS
$cfg['main_config_file']='/hafs/app/nagios/etc/nagios.cfg';  // default location of the main Nagios config file
$cfg['status_file']='/hafs/app/nagios/var/status.dat'; // default location of Nagios status file
$cfg['state_retention_file']='/hafs/app/nagios/var/retention.dat'; // default location of Nagios retention file

Without any changes to the behavior.

So with the suspect that config.inc.php file settings about the cgi.cfg file is ignored (also the other vars seems to be ignored too, see at the end): to prove, I renamed the original cgi.cfg file to cgi.cfg.orig and refresh the webpage and as I suspect, the error become:

Error: Could not open CGI config file '/hsr/app/nagios-4.4.14/etc/cgi.cfg' for reading!

For sure...is the wrong path....
A simple "grep -R" on the all WebUI files (/share folder) doesn't has any other references to the 'cgi.cfg' file...so what I see is probably the hard-coded default path written during the compilation of the source code.

# cd /hsr/app/nagios-4.4.14/share
# grep -R "cgi.cfg" *
config.inc.php:$cfg['cgi_config_file']='/hafs/app/nagios/etc/cgi.cfg';  // location of the CGI config file

Next troubleshooting step was: If the content of the variable is not parsed, can I remove entirely to avoid mess with defined path?
If I do so, commenting out the $cfg['cgi_config_file'] variable from the conf.inc.php file, an undefined variable error is show:

Warning: Undefined array key "cgi_config_file" in /hsr/app/nagios-4.4.14/share/includes/utils.inc.php on line 207

So, the variable is required and is used somewhere, the specified cgi.cfg file: by reading and modify the PHP code to print the file content on the webpage is actual being read properly inside the PHP function "read_cgi_config_file()", but then, somewhere, it's contents are not used properly.

Passing the variable via Apache Environment variables as KB https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/4/en/configcgi.html seems to work and resolve the issue; but the requirement of a variable inside the config.inc.php to be set with any kind of content different than 0 as length must match to avoid error; so I set, as 'memo' for the future:

$cfg['cgi_config_file']='/see/apache/env/vars/inside/vhost'; // location of the CGI config file

Earlier I mentioned that vars defined inside config.inc.php seems to be not parsed.
If I remove also the following other vars; I receive errors about missing variables; but if I point to inexisting paths and file, no error are displayed and all keep to work;

// FILE LOCATION DEFAULTS
$cfg['main_config_file']='/path/to/inexistent/nagios.cfg';  // default location of the main Nagios config file
$cfg['status_file']='/path/to/inexistent/status.dat'; // default location of Nagios status file
$cfg['state_retention_file']='/path/to/inexistent/retention.dat'; // default location of Nagios retention file

For sure this variables somehow has to be read by the WebUI, probably directly from the main nagios.cfg file, known to the UI via the cgi.cfg file; but for safety I prefer keep all of them, except the one for the main cgi.cfg file path, properly set anyway.

Can you check?
System environment:

# uname -a
Linux <hostname> 5.15.0-78-generic #85-Ubuntu SMP Fri Jul 7 15:25:09 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

# cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.3 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.3 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy

# php-fpm -v
PHP 8.2.9 (fpm-fcgi) (built: Aug 18 2023 08:52:35)
Copyright (c) The PHP Group
Zend Engine v4.2.9, Copyright (c) Zend Technologies

# apachectl -v
Server version: Apache/2.4.57 (Unix)
Server built:   Aug 16 2023 15:04:35

Kind Regards

@sawolf sawolf added the Bug label Aug 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants