Repository navigation
bug: Open the Syslog database connection before the Syslog panels query it - #474
Conversation
…ry it
The Intropage Syslog panels (plugin_syslog_trend, plugin_syslog_levels_trend,
plugin_syslog_devices and plugin_syslog_devices_detail) require the Syslog
plugin's database library and then call its syslog_db_*() helpers, but never
opened the Syslog database connection. Those helpers route through the global
$syslog_cnn connection; with it unset they fall back to the Cacti connection,
so on an installation whose Syslog tables live in a database separate from
Cacti's the panels fail in the poller with:
ERROR: A DB Row Failed!, Error: Table 'cacti.syslog' doesn't exist
and the empty result then triggers "foreach() argument must be of type
array|object, false given".
Add an intropage_syslog_connect() helper that loads the Syslog library and
calls syslog_connect() -- the entry point every Syslog consumer uses, which
populates $syslog_cnn and is internally guarded to run its one-time schema
check only once per process. Each panel now routes through the helper and
skips its update cleanly (logging once) when the connection cannot be opened,
and the levels collector tolerates a non-array result defensively.
Replace the now-obsolete SyslogDatabaseLoaderTest, which asserted the old
"load the library from either path" behaviour, with SyslogPanelConnectionTest
covering the connection contract.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
The Syslog helper ignores an explicit connection failure when a connection remains populated, and failed query results still enter the loop, causing warnings and corrupting the priority-0 count.
2 open issues
What changed in this PR
This PR addresses Intropage Syslog panels querying Cacti’s database when Syslog uses a separate database.
Changes:
- Adds a shared connection helper used by four Syslog callbacks, with failure handling.
- Adds defensive handling for non-array levels-query results.
- Replaces library-loading tests with connection-focused tests and documents the fix.
| File | Description |
|---|---|
tests/Unit/SyslogPanelConnectionTest.php |
Adds connection success, failure, and panel-update tests. |
tests/Unit/SyslogDatabaseLoaderTest.php |
Removes the previous library-path loading tests. |
panellib/syslog.php |
Centralizes Syslog connection setup and updates panel failure handling. |
CHANGELOG.md |
Documents the separate-database connection fix. |
Review effort: Balanced
Address code-review feedback on the Syslog connection helper: - intropage_syslog_connect() now honors syslog_connect()'s boolean return. The connection object can open while the Syslog schema readiness check fails, so the helper returned a populated \ yet an overall false; treating that as success let all four panels query an unready database. The helper now fails (and logs) on an explicit false return as well as an empty connection. - plugin_syslog_levels_trend() replaces the (array) \ cast with an is_array() guard. Casting a false query result produced [false], so the loop ran once, emitted array-offset warnings, and overwrote the priority-0 count with null. A false result now yields no iterations. - SyslogPanelConnectionTest covers the populated-connection failure case and a false levels query (no warnings, counts preserved). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Addressed both code-review findings in 289d332:
Added regression tests for both (populated-connection failure; false levels query with no warnings/notices). Validation on AlmaLinux 9 / PHP 8.3.36 against Cacti's vendor tree:
Note: CI itself is currently red due to an unrelated DNS failure in the runner, not these changes. |
The syslog panels now wrap their Waiting for data status text in __(), so the extracted i18n string set changed. Regenerate locales/po/cacti.pot with locales/build_gettext.sh to satisfy the i18n template check. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
# Conflicts: # CHANGELOG.md # locales/po/cacti.pot
Bring the changed lines in panellib/syslog.php to full coverage after the develop merge pulled in the strict patch-coverage gate: - Add unit tests driving the "database unavailable" path of plugin_syslog_trend(), plugin_syslog_devices() and plugin_syslog_devices_detail(). - Mark the one-time Syslog-library include guards in intropage_syslog_connect() with @codeCoverageIgnore; they only run in a real poller context, and the unit harness always has the Syslog functions declared (PHP cannot un-declare them). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|




Description
The Intropage Syslog panels —
plugin_syslog_trend,plugin_syslog_levels_trend,plugin_syslog_devicesandplugin_syslog_devices_detailinpanellib/syslog.php—require_oncethe Syslog plugin's database library and then run itssyslog_db_*()helpers, but they never opened the Syslog database connection. Those helpers route queries through the global$syslog_cnnconnection; with it unset they fall back to the main Cacti connection.On an installation whose Syslog tables live in a database separate from Cacti's, the panels therefore fail during the Intropage poller run:
(the
foreachwarning is the empty/falseresult of the failed query).This PR adds an
intropage_syslog_connect()helper that loads the Syslog library and callssyslog_connect()— the entry point every Syslog consumer uses, which populates$syslog_cnnand is internally guarded to run its one-time schema check only once per process. Each panel now routes through the helper and skips its update cleanly (logging once) when the connection cannot be opened, and the levels collector tolerates a non-array result defensively.Related Issue
Reported on the Cacti forums: https://forums.cacti.net/viewtopic.php?t=64912 (Edit 4). The Syslog-plugin-side fatals from the same thread are handled separately in Cacti/plugin_syslog#439.
Motivation and Context
With a split Syslog database, the Intropage Syslog panels never collect data and spam the log each poll. Opening the Syslog connection the way the Syslog plugin intends fixes both the wrong-database queries and the downstream
foreach-on-falsewarning.How Has This Been Tested?
php -lclean onpanellib/syslog.phpand the new test (PHP 8.3.36).plugins/intropage:php include/vendor/bin/pest --configuration plugins/intropage/phpunit.xml→ 218 passed, 102 skipped (the 2 remaining warnings are pre-existing, in
setup.phpfile pruning, and unrelated to this change).tests/Unit/SyslogPanelConnectionTest.phpcovers the connection contract (ready when the connection opens; logs and fails when it cannot; panel collectors skip cleanly when unavailable). It replacesSyslogDatabaseLoaderTest, which asserted the old "load the library from either path" behaviour that this change supersedes.Testing environment: AlmaLinux 9, PHP 8.3.36, Cacti
1.2.xvendor tree.Types of changes
Checklist: