Page 1 of 1

PHP Notice: DB is not connected.....

Posted: Mon Jul 10, 2023 11:21 am
by vornado
Hello.

Multiple times per minute this line of text is appended to the /usr/local/nagiosxi/var/nom.log file on our production, development and disaster recovery Nagios servers:

Code: Select all

PHP Notice:  DB is not connected in /usr/local/nagiosxi/html/includes/db.inc.php on line 399
I'm not sure when this started, but there were over 150,000 of these entries on one server. Nagios XI seems to be working fine despite these log entries, but I would like to know how to stop them. Any assistance would be appreciated.

Thanks and best regards,

Steve

Re: PHP Notice: DB is not connected.....

Posted: Wed Aug 02, 2023 1:54 am
by lucasari
I'm having the same error messages in /var/log/apache2/error.log

my current system:
Nagios XI: 5.11.1
PHP: 7.4.3-4ubuntu2.19 (cli) (built: Jun 27 2023 15:49:59) ( NTS )
OS: Ubuntu 20.04.6 LTS

Re: PHP Notice: DB is not connected.....

Posted: Wed Aug 09, 2023 4:58 pm
by danderson
Thanks for reaching out,

Is there anything interesting in the database logs? I'm thinking there may be a crashed table or something similar.

To just turn off notices:
Edit the /etc/php.ini file and find the following option and change it from.

Code: Select all

error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
to

Code: Select all

error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE
Save the change and restart the following as root on the nagios server.

Code: Select all

systemctl restart httpd crond
Otherwise, the only other thing I can think of is that the databases are not being initialized before the escape_sql_param function is being called.
If you want to provide more information on the subject, In the "/usr/local/nagiosxi/html/includes/db.inc.php" file, on line 399, you could change from

Code: Select all

// DB is not connected... so trigger error
// we don't know of an open conenction
trigger_error("DB is not connected", E_USER_NOTICE);
to

Code: Select all

// DB is not connected... so trigger error
 // we don't know of an open conenction
ob_start();
debug_print_backtrace();
$debug_data = ob_get_clean();
trigger_error("DB $dbh is not connected\n" . $debug_data, E_USER_NOTICE);
Then you can attach the new error messages here so I can better see what's going on. This will add a back trace log to the error message so that we can see where the bad escape function is being called.

Re: PHP Notice: DB is not connected.....

Posted: Thu Aug 10, 2023 9:01 am
by CameronWP
Hi:

We are having the same issue since the update. I made the change you mentioned for better logging and this is what was returned:

PHP Notice: DB nagiosxi is not connected
#0 escape_sql_param(location_backend_cache, nagiosxi) called at [/usr/local/nagiosxi/html/includes/utils.inc.php:1045]
#1 get_option(location_backend_cache, /usr/local/nagiosxi/var/backendcache) called at [/usr/local/nagiosxi/html/includes/utils-backend.inc.php:105]
#2 get_backend_cache(get_program_status_xml_output, Array ()) called at [/usr/local/nagiosxi/html/includes/utils-status.inc.php:18]
#3 get_xml_program_status(Array ()) called at [/usr/local/nagiosxi/html/includes/components/reactoreventhandler/reactoreventhandler.inc.php:273]
#4 reactoreventhandler_component_checkeventhandlers() called at [/usr/local/nagiosxi/html/includes/components/reactoreventhandler/reactoreventhandler.inc.php:43]
#5 reactoreventhandler_component_init() called at [/usr/local/nagiosxi/html/includes/components/reactoreventhandler/reactoreventhandler.inc.php:16]
#6 include_once(/usr/local/nagiosxi/html/includes/components/reactoreventhandler/reactoreventhandler.inc.php) called at [/usr/local/na in /usr/local/nagiosxi/html/includes/db.inc.php on line 405

Thanks!

Re: PHP Notice: DB is not connected.....

Posted: Thu Aug 10, 2023 9:11 am
by danderson
@CameronWP What version of XI do you have?

Also, do you have something related to Nagios Reactor in your list of components? You can check in Admin -> System Extensions -> Manage Components

Re: PHP Notice: DB is not connected.....

Posted: Thu Aug 10, 2023 9:13 am
by tgriep
The PHP script is loading the reactor component that talks to an obsolete product called Nagios Reactor and that is causing the messages.
It can be moved from the XI system folders by running the following as root. It will make a backup in the /root folder.

Code: Select all

mv /usr/local/nagiosxi/html/includes/components/reactoreventhandler /root
Also, there was another product called Nagios IM that causes the same message and to remove that if it exists on your server, run this as root.

Code: Select all

mv /usr/local/nagiosxi/html/includes/components/nagiosim /root
Then check the log files to see if the "DB is not connected" messages are gone.