Skip to content

Guard maint maintenance-window checks against a missing maint functions file - #859

Merged
TheWitness merged 2 commits into
developfrom
fix_maint_include_correct
Oct 15, 2026
Merged

TheWitness merged 2 commits into
developfrom
fix_maint_include_correct

Conversation

@TheWitness

Copy link
Copy Markdown
Member

Summary

Follow-up hardening to #858. That PR corrected the maint functions.php include path, but three plugin_maint_check_cacti_host() calls remained guarded only by api_plugin_is_enabled('maint'). Because the include block now logs and continues when the maint functions file is missing (rather than fataling on the include), those later calls hit an undefined function and fatal the poll.

Changes

Add a function_exists('plugin_maint_check_cacti_host') guard to all three call sites:

  • includes/functions.php — thold_check_threshold()
  • includes/polling.php — the recovering-device loop in thold_update_host_status()
  • includes/polling.php — the down-device loop in thold_update_host_status()

This matches the defensive pattern used in the other maint-aware plugins (servcheck, webseer): when maint is enabled but its functions file cannot be included, the maintenance check is simply skipped instead of crashing the poller.

Tests

  • New tests/Unit/MaintCheckGuardTest.php drives both maintenance-gated notification branches (recovering device and down device) and asserts the "Only logging, maint device" log messages, covering the two changed polling lines.
  • thold_check_threshold() is already exercised by the existing characterization/maint tests.
  • Added an html_split_string() passthrough stub to tests/bootstrap-unit.php so the recovering-device path can be driven in the isolated unit process. (Changes under tests/ are excluded from the patch-coverage gate.)

Notes

The anti-pattern to avoid here is file_exists(require_once(...)) — the merged #858 already uses a correct file_exists($path) probe, which this PR leaves intact; it only adds the missing function_exists() guard at the call sites.

Copilot AI balanced review requested due to automatic review settings October 15, 2026 14:44
…ns file

#858 corrected the maint functions include path but left three
plugin_maint_check_cacti_host() calls guarded only by
api_plugin_is_enabled('maint'). When maint is enabled but its functions
file cannot be included (the include block now logs and continues rather
than fataling), those calls hit an undefined function and fatal the poll.

Add a function_exists('plugin_maint_check_cacti_host') guard to all three
call sites (thold_check_threshold() and both the recovering- and down-device
loops in thold_update_host_status()) so a missing maint include degrades
gracefully, matching the guard other plugins use.

Cover both maintenance-gated notification branches with a new
MaintCheckGuardTest; add an html_split_string() test stub so the
recovering-device path can be driven in the isolated unit process.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@TheWitness
TheWitness force-pushed the fix_maint_include_correct branch from 3bd450a to 4b2dd6d Compare October 15, 2026 14:48

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.

🟡 Changes recommended

Both new tests lack required notification configuration, and the missing-function regression remains untested.

2 open findings
What changed in this PR

Hardens thold’s maintenance integration after #858 so unavailable maint functions do not crash polling.

Changes:

  • Guards all three maintenance-check calls with function_exists().
  • Adds device-status tests and a supporting HTML helper stub.
File Description
tests/​Unit/​MaintCheckGuardTest.php Adds recovery and down-device maintenance tests.
tests/​bootstrap-unit.php Adds an html_split_string() passthrough stub.
includes/​polling.php Guards maintenance checks for device notifications.
includes/​functions.php Guards the threshold maintenance check.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/Unit/MaintCheckGuardTest.php
Comment thread tests/Unit/MaintCheckGuardTest.php
Drop the broad catch(Throwable) in the host-status test helper. A device
inside a maintenance window is logged and the loop continues without the
downstream notification work, so the call returns on its own; removing the
catch means an unexpected error (such as a removed guard fataling on an
undefined maint function) now fails the test instead of being swallowed.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@TheWitness
TheWitness merged commit 2c7593c into develop Oct 15, 2026
3 checks passed
@TheWitness
TheWitness deleted the fix_maint_include_correct branch October 20, 2026 17:25
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.

3 participants