Repository navigation
fix(thold): validate a new threshold before its first save (#691) - #898
Merged
somethingwithproof merged 3 commits intoDec 3, 2026
Merged
Conversation
thold_validate_save() returned true for any threshold with an empty id, so a threshold created from Console > Data Sources could be saved with a High Alert below its Low Alert, or with no limits at all. The skip existed for the non-templated wizard, whose 'Create' step posts only the device, graph and data source and saves an empty threshold. The skip is now an explicit $skip_new argument. save_thold() passes it only for a post without the edit form's thold_type, which is the wizard's step. A failed first save used to redirect to "edit&id=" with no id, which is a blank page. save_thold() now returns false and sets the edit URL to return to, and thold.php does the redirect. thold_edit_url() reopens a new threshold from its data source, graph and device. thold_create_from_template() loses its validation call: the old skip always applied there (id is always 0), so the header()/exit branch was dead, and it runs from device automation and the CLI.
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
A missing thold_type still allows submitted threshold values to reach sql_save(), persisting invalid limits and an empty type instead of limiting the exception to the wizard’s value-free creation request.
1 open issue
What changed in this PR
Addresses #691 by validating new thresholds before saving, while preserving the wizard’s initial creation flow.
Changes:
- Makes validation skipping explicit for new thresholds.
- Returns failed saves to an appropriate edit or list page.
- Adds nine regression tests and a changelog entry.
| File | Description |
|---|---|
thold.php |
Handles save failures and return redirects. |
tests/Unit/TholdValidateNewThresholdTest.php |
Tests validation, wizard saves, and edit URLs. |
includes/functions.php |
Updates validation and builds failure return URLs; removes redundant template validation. |
CHANGELOG.md |
Documents the validation and redirect fixes. |
Review effort: Balanced
…ost (Cacti#691) Omitting thold_type alone no longer marks a new-threshold save as the wizard's empty first save. Validation is skipped only when no threshold type, limit, trigger or baseline value was submitted, and a missing or empty thold_type is now rejected as an unknown type when validated. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…acti#691) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
xmacan
approved these changes
Dec 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.




Fixes #691.
thold_validate_save()returnedtruefor any threshold with an empty id. A threshold created from Console > Data Sources (Template name link) was therefore saved without any checks: High Alert below Low Alert, or no alert limit at all, went straight intothold_data.The skip was there for the non-templated wizard. Its 'Create' step posts only the device, graph and data source, saves an empty threshold, and then opens that threshold in the edit form. Validating that post fails with "Unknown Threshold Type!".
Change
thold_validate_save()takes a new$skip_newargument, and the empty-id skip applies only when the caller passes it.save_thold()passes it only when the post has nothold_type. The edit form always posts that field, and the wizard's step never does. The one case where the form disablesthold_type(Template Enabled checked) returns through the template branch before validation.thold.php?action=edit&id=with no id, andthold_edit()exits on that, which gives a blank page.save_thold()now returnsfalseand sets a return URL by reference.thold.phpdoes the redirect. The newthold_edit_url()reopens a new threshold from its data source, graph and device.thold.phpsends any otherfalsefromsave_thold()(Permission Denied, missing graph item) to the threshold list, so the error is shown. Before, those also ended on the blank page.thold_create_from_template()loses its validation call.idis always 0 there, so the old skip always applied and theheader()/exitbranch was dead. The values come from a template that was validated when it was saved, and the function runs from device automation andcli_thresholds.php, where a redirect is meaningless.The values a user typed are not refilled after a rejected save. Editing an existing threshold already behaves that way. Refilling through
sess_field_valuescould be a follow-up.Testing
tests/Unit/TholdValidateNewThresholdTest.php(9 tests) covers:$skip_newapplies only to a new threshold and never to templates;thold_edit_url()for a saved and an unsaved threshold;save_thold()rejects an impossible new threshold without callingsql_save()and returns the data-source edit URL;save_thold()still saves the wizard's post withoutthold_type.Run in
php:8.3-cliwith pcov, Cacti vendor tree:NotificationQueueClaimTest::default process identity probe…, which fails the same way on unmodifieddevelopin that container.tests/bin/patch-coverage.phpagainstdevelopNot exercised in a live Cacti.
Types of changes