Repository navigation
fix(thold): substitution loop, empty THOLD_DOWNTIME, time-based graph tags and other small defects - #901
Merged
TheWitness merged 11 commits intoDec 3, 2026
Conversation
thold_substitute_custom_data() looks for the closing escape after each |custom_ token. When there is none, strpos() returns false, the next scan starts again at offset 0 and finds the same token, so the loop never ends and the process runs out of memory. A trigger command or notification text with a stray "|custom_x" therefore hung the poller or daemon. Stop scanning at an unterminated token and leave it as typed. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
The down branch of thold_update_host_status() exported THOLD_DOWNTIME from $last_time_duration, a variable that is never assigned. The command always received an empty value and the poller logged an undefined variable warning for every device that went down. The email for the same event already uses $last_state_duration; export that. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
thold_rrd_graph_graph_options() reads a tagged bound from the time_* columns for time-based thresholds, but the branch tested thold_type == 1, which the preceding Hi/Low and Baseline branch already handles. Time-based thresholds (type 2) never reached it, $value was left undefined, and the graph item carrying the tag was dropped from the graph. Test for type 2. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Four functions read a variable that only some branches assign: - thold_get_device_notification_format_file() read $notify_format_file when the device event had no notification list. - thold_check_baseline() read $ref_value for the CF deviation types when bl_cf held none of AVG/MIN/MAX/LAST. - thold_mail() read $from_name when the caller passed its own sender. - thold_template_import() kept $tname across templates, so a template without a name was reported under the previous template's name, or raised a warning when it came first. Each now starts from an empty value. The test bootstrap gains xml2array() and db_column_exists() shims, and the mailer() shim records the sender. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
thold_substitute_custom_data() returned null when $local_data_id was empty, so thold_expand_string() went on with a null string instead of the text it passed in. With no data source there is nothing to look up; return the input as given. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Several docblocks used "@PARAM array - text" and "@return - text", which PHPDoc parsers reject, so PHPStan ignored them. Give each tag a type and a variable name, and correct the ones that disagreed with the code: thold_set_environ() returns the queued environment, the delay functions return nothing, and thold_cli_autocreate() receives the id lists already split into arrays. No code changes. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
- Drop the break statements that follow a return or exit. - Drop the $banner block on the threshold edit page; nothing has set $banner since messages moved to raise_message(). - Stop printing the result of html_host_filter(), which prints its own markup and returns nothing. - Return nothing from thold_wizard(), which is declared void and whose callers ignore the result. - Pass html_header_sort() its default colspan of 1 instead of false. - Return an empty label from get_bl_type() for an unknown type instead of falling off the end of the function. No behaviour change. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
thold_edit() and template_edit() build the "Data Sources" hint from $dsname[], which is only assigned inside the loop over the data source's rows. With no rows, implode() received an undefined variable and PHP 8 threw a TypeError, so the edit page for a threshold or template whose data source has no items failed to render. Start from an empty list. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
thold.php sent an action submitted with no threshold selected to tholds.php, which does not exist, so the user got a missing-page error instead of the list and the 'select at least one' message. Redirect to thold.php like the page's other redirects, and test that every Location redirect in the plugin names an existing page. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
The template list showed thold_warning_hi/low as the warning bounds of a time-based template. Time-based templates keep them in time_warning_hi and time_warning_low, as the alert bounds in the same branch already do. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
thold_template_import() sets $save['id'] only when the template has a hash, then read it to choose between 'Imported' and 'Updated', raising an undefined-key warning. Without a hash there is nothing to match, and sql_save() inserts a new row, so report it as an import. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
|
TheWitness
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.



Closes #900.
Small, local fixes found with PHPStan level 8. The threshold evaluator (
thold_check_threshold) and the functions changed by #892 and #898 are untouched, and so isCHANGELOG.md(both open PRs edit it; the entry can be added at merge).Fixes
thold_substitute_custom_data(): stop the scan at an unterminated|custom_token instead of restarting it forever.THOLD_DOWNTIMEinstead of an unset variable.|thold:...|graph tags: resolve thetime_*bounds for time-based thresholds.thold_mailsender name, template import name), and return the text unchanged when there is no data source id.thold.phpinstead of the missingtholds.php.time_warning_*bounds for time-based templates in the template list.$save['id'].Cleanup (no behaviour change)
Tests