Skip to content

fix(status): define collector threshold defaults before the Status tab dispatches (#491) - #492

Merged
TheWitness merged 2 commits into
developfrom
fix/491-collector-default-constants
Dec 1, 2026
Merged

TheWitness merged 2 commits into
developfrom
fix/491-collector-default-constants

Conversation

@bmfmancini

Copy link
Copy Markdown
Member

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 down syslog.php, after the tab dispatch calls syslog_status(). PHP hoists functions but runs define() 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

  • Move both definitions, with if (!defined(...)) guards, into includes/functions.php. syslog_connect() loads that file at the top of syslog.php, before the dispatch.
  • Remove the test-local define()s in CollectorHealthTest and PipelineHealthTest that were hiding the bug.
  • Add regression tests:
    • syslog.php must not define the constants, includes/functions.php must, and syslog_connect() must come before syslog_status(). A fresh PHP process that loads only includes/functions.php must print 300,10000.
    • With both settings at '0', the health card falls back to 300 s / 10000 messages and warns.

Testing

  • A standalone script runs the real syslog_status_collector_health() with both settings at '0':
    • On develop: FATAL: Undefined constant "SYSLOG_COLLECTOR_STALE_SECONDS" (same error as the report).
    • On this branch: OK warning=true text=unprocessed messages are 6 minutes old; incoming backlog of 10,001 messages.
  • php -l passes on all changed files.
  • I couldn't run Pest locally (the local PHP/vendor setup is broken), so CI is the first Pest run for this change.

Fixes #491

…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
Copilot AI balanced review requested due to automatic review settings December 1, 2026 01:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 somethingwithproof left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@sonarqubecloud

sonarqubecloud Bot commented Dec 1, 2026

Copy link
Copy Markdown

@TheWitness
TheWitness merged commit 7a1e152 into develop Dec 1, 2026
8 checks passed
@TheWitness
TheWitness deleted the fix/491-collector-default-constants branch December 1, 2026 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Server 500 encountered when staleness threshold set to "default"

4 participants