Skip to content

Fix #746: Correct inverted type 2 normal restoral conditions - #796

Open
bmfmancini wants to merge 2 commits into
Cacti:developfrom
bmfmancini:fix/issue-746-inverted-type2-restoral-conditions
Open

Fix #746: Correct inverted type 2 normal restoral conditions#796
bmfmancini wants to merge 2 commits into
Cacti:developfrom
bmfmancini:fix/issue-746-inverted-type2-restoral-conditions

Conversation

@bmfmancini

Copy link
Copy Markdown
Member

Summary

Fixes #746

In thold_functions.php, the type 2 (time-based) normal restoral logic in thold_check_threshold() (lines ~3443 and ~3512) used < instead of >= for the fail count comparisons:

// Warning restoral (inverted):
if ($alertstat != 0 && $warning_failures < $warning_trigger && $thold_data['restored_alert'] != 'on') {

// Alert restoral (inverted):
} elseif ($alertstat != 0 && $failures < $trigger && $thold_data['restored_alert'] != 'on') {

Impact

The < vs >= inversion caused:

  • Restorals to fire for thresholds that were never triggered — when the fail count was below the trigger (no alert was ever sent), a restoral notification was incorrectly generated.
  • Restorals to be silently suppressed for thresholds that were triggered — when the fail count reached or exceeded the trigger (an alert was sent), the restoral was incorrectly blocked.

Fix

Changed < to >= for both $warning_failures and $failures comparisons in the type 2 restoral block:

// Warning restoral (fixed):
if ($alertstat != 0 && $warning_failures >= $warning_trigger && $thold_data['restored_alert'] != 'on') {

// Alert restoral (fixed):
} elseif ($alertstat != 0 && $failures >= $trigger && $thold_data['restored_alert'] != 'on') {

This matches the correct pattern used in the type 0 restoral logic (line ~2685), which checks:

if ($thold_data['thold_warning_fail_count'] >= $warning_trigger && $thold_data['restored_alert'] != 'on' && !$maint_dev) {

Testing

  • Verified PHP syntax with php -l thold_functions.php — no syntax errors.
  • Confirmed the corrected conditions match the semantics of the type 0 restoral path.

The type 2 (time-based) restoral logic in thold_check_threshold() used
'<' instead of '>=' for the fail count comparisons:

- Warning restoral: $warning_failures < $warning_trigger
- Alert restoral: $failures < $trigger

This inversion caused restorals to fire for thresholds that were never
triggered (count below trigger), while silently suppressing restorals
for thresholds that were actually triggered (count at or above trigger).

Changed '<' to '>=' for both comparisons, matching the correct pattern
used in the type 0 restoral logic which checks:
  $thold_data['thold_warning_fail_count'] >= $warning_trigger
Copilot AI lite review requested due to automatic review settings August 17, 2026 02:56

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

Bug: Type 2 normal restoral conditions inverted — fires for un-triggered thresholds

3 participants