Repository navigation
fix(status): define collector threshold defaults before the Status tab dispatches (#491) - #492
Conversation
…b dispatches (#491) Selecting "Default" for Collector Staleness Threshold (stored as '0') made the Syslog Status tab fatal with 'Undefined constant "SYSLOG_COLLECTOR_STALE_SECONDS"', and Cacti then disabled the plugin. The same applied to the "Default" Collector Backlog Threshold. Both constants were declared with a top-level define() part way down syslog.php, after the tab dispatch calls syslog_status(). Functions are hoisted but define() only runs when execution reaches it, so the fallback branch referenced constants that did not exist yet. Move the guarded definitions into includes/functions.php, which syslog_connect() loads before the page dispatches. Remove the test-local defines that masked the bug and add regressions: the constants must come from includes/functions.php (checked in a fresh PHP process), and a "Default" (0) setting must fall back to 300 seconds / 10000 messages. Fixes #491
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block approval of the collector threshold initialization fix.
No open issues 🎉
What changed in this PR
Fixes #491 by making collector threshold defaults available before the Syslog Status tab dispatches, preventing fatal errors when either threshold is set to “Default.”
Changes:
- Move both default constants into the shared functions file with guards against redefinition.
- Remove test-local definitions that masked the initialization-order bug.
- Add regression coverage for initialization order, fresh-process loading, and zero-valued settings.
| File | Description |
|---|---|
tests/Unit/PipelineHealthTest.php |
Remove fixture-defined constants so tests use production defaults. |
tests/Unit/CollectorHealthTest.php |
Load production defaults and add initialization and fallback regression tests. |
syslog.php |
Remove constants defined too late for Status tab dispatch. |
includes/functions.php |
Define guarded collector defaults during shared initialization. |
Review effort: Balanced
somethingwithproof
left a comment
There was a problem hiding this comment.
Blocker. Please add an issue#491 entry under --- develop --- in CHANGELOG.md so operators can see that the Status tab works again with the default collector thresholds. The plugin’s changelog instructions require an entry for each change. The fix itself looks good. Both constants load before dispatch, and all 41 collector and pipeline health tests passed locally.
|



Summary
Selecting Default (300 seconds) for Collector Staleness Threshold makes the Syslog Status tab fatal with
Undefined constant "SYSLOG_COLLECTOR_STALE_SECONDS", and Cacti then disables the plugin. Default (10000 messages) for Collector Backlog Threshold has the same problem.Root cause: both constants were declared with a top-level
define()part way downsyslog.php, after the tab dispatch callssyslog_status(). PHP hoists functions but runsdefine()only when execution reaches it. "Default" is stored as'0', which takes the fallback branch that reads the constants. Any other value skips that branch, which is why only "Default" crashed.Changes
if (!defined(...))guards, intoincludes/functions.php.syslog_connect()loads that file at the top ofsyslog.php, before the dispatch.define()s inCollectorHealthTestandPipelineHealthTestthat were hiding the bug.syslog.phpmust not define the constants,includes/functions.phpmust, andsyslog_connect()must come beforesyslog_status(). A fresh PHP process that loads onlyincludes/functions.phpmust print300,10000.'0', the health card falls back to 300 s / 10000 messages and warns.Testing
syslog_status_collector_health()with both settings at'0':develop:FATAL: Undefined constant "SYSLOG_COLLECTOR_STALE_SECONDS"(same error as the report).OK warning=true text=unprocessed messages are 6 minutes old; incoming backlog of 10,001 messages.php -lpasses on all changed files.Fixes #491