From 43daa9b0c3e18042be76ac46ecd9e3e076dcb068 Mon Sep 17 00:00:00 2001 From: Sean Mancini Date: Sun, 16 Aug 2026 22:41:58 -0400 Subject: [PATCH 1/2] for for 750 --- thold_functions.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/thold_functions.php b/thold_functions.php index a3bab97..9b2e90e 100644 --- a/thold_functions.php +++ b/thold_functions.php @@ -3390,7 +3390,7 @@ function thold_check_threshold(&$thold_data) { 'host_id' => $thold_data['host_id'], 'local_graph_id' => $thold_data['local_graph_id'], 'threshold_id' => $thold_data['id'], - 'threshold_value' => ($breach_up ? $thold_data['time_hi'] : $thold_data['time_low']), + 'threshold_value' => ($warning_breach_up ? $thold_data['time_warning_hi'] : $thold_data['time_warning_low']), 'current' => $thold_data['lastread'], 'status' => ($ra ? ST_NOTIFYRAW : ST_NOTIFYWA), 'description' => ($maint_dev ? $subject . '. ' . __('Only logging, maint device', 'thold') : $subject), @@ -3406,7 +3406,7 @@ function thold_check_threshold(&$thold_data) { 'host_id' => $thold_data['host_id'], 'local_graph_id' => $thold_data['local_graph_id'], 'threshold_id' => $thold_data['id'], - 'threshold_value' => ($warning_breach_up ? $thold_data['time_hi'] : $thold_data['time_low']), + 'threshold_value' => ($warning_breach_up ? $thold_data['time_warning_hi'] : $thold_data['time_warning_low']), 'current' => $thold_data['lastread'], 'status' => ST_NOTIFYRAW, 'description' => ($maint_dev ? $subject . '. ' . __('Only logging, maint device', 'thold') : $subject), @@ -3420,7 +3420,7 @@ function thold_check_threshold(&$thold_data) { 'host_id' => $thold_data['host_id'], 'local_graph_id' => $thold_data['local_graph_id'], 'threshold_id' => $thold_data['id'], - 'threshold_value' => ($warning_breach_up ? $thold_data['time_hi'] : $thold_data['time_low']), + 'threshold_value' => ($warning_breach_up ? $thold_data['time_warning_hi'] : $thold_data['time_warning_low']), 'current' => $thold_data['lastread'], 'status' => ST_TRIGGERW, 'description' => ($maint_dev ? $subject . '. ' . __('Only logging, maint device', 'thold') : $subject), From 80839948cd376f50163b878b86fc6420ce0b0792 Mon Sep 17 00:00:00 2001 From: Sean Mancini Date: Sun, 16 Aug 2026 23:04:29 -0400 Subject: [PATCH 2/2] Fix #753: Enable CDEF/calculated data source value alerting thold_modify_values_by_cdef() had two logic bugs that prevented CDEF-based thresholds from triggering: 1. Contradictory condition: The CDEF was only looked up from graph items when data_type != 1 OR cdef was empty, but only applied when data_type == 1. When a user explicitly set a CDEF on a threshold (data_type=1, cdef set), the lookup was skipped and $cdef stayed false, so the CDEF was never applied to the threshold values. 2. Double transformation: lastread was already CDEF-transformed by thold_poller_output (or thold_process.php for daemon mode) before being stored in the database. thold_modify_values_by_cdef() then applied the CDEF to lastread again, producing an incorrect value. The fix restructures the CDEF lookup to use the threshold's explicitly configured CDEF when data_type=1, falling back to auto-detection from graph items. It also removes the redundant lastread transformation, applying the CDEF only to the threshold values (thold_hi, thold_low, etc.) so the comparison between the already-transformed lastread and the threshold values is consistent. --- thold_functions.php | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/thold_functions.php b/thold_functions.php index 9b2e90e..4468479 100644 --- a/thold_functions.php +++ b/thold_functions.php @@ -4317,22 +4317,28 @@ function get_thold_restoral_text($data_source_name, $thold, $h, $currentval, $lo function thold_modify_values_by_cdef(&$thold_data) { $cdef = false; - if ($thold_data['data_type'] != 1 || empty($thold_data['cdef'])) { - // Check is the graph item has a cdef - $cdef = db_fetch_cell_prepared('SELECT MAX(cdef_id) - FROM graph_templates_item AS gti - INNER JOIN data_template_rrd AS dtr - ON gti.task_item_id = dtr.id - WHERE local_graph_id = ? - AND dtr.id = ? - AND gti.graph_type_id IN (4, 5, 6, 7, 8, 20) - AND dtr.data_source_name = ?', - [$thold_data['local_graph_id'], $thold_data['data_template_rrd_id'], $thold_data['data_source_name']]); - } - - if ($cdef !== false && $cdef > 0 && $thold_data['data_type'] == 1) { - $thold_data['lastread'] = thold_build_cdef($cdef, $thold_data['lastread'], $thold_data['local_data_id'], $thold_data['data_template_rrd_id']); - + if ($thold_data['data_type'] == 1) { + if (!empty($thold_data['cdef'])) { + // Use the CDEF explicitly configured on the threshold + $cdef = $thold_data['cdef']; + } else { + // Auto-detect a CDEF from the graph item for this data source + $cdef = db_fetch_cell_prepared('SELECT MAX(cdef_id) + FROM graph_templates_item AS gti + INNER JOIN data_template_rrd AS dtr + ON gti.task_item_id = dtr.id + WHERE local_graph_id = ? + AND dtr.id = ? + AND gti.graph_type_id IN (4, 5, 6, 7, 8, 20) + AND dtr.data_source_name = ?', + [$thold_data['local_graph_id'], $thold_data['data_template_rrd_id'], $thold_data['data_source_name']]); + } + } + + if ($cdef !== false && $cdef > 0) { + // Note: lastread is already CDEF-transformed by thold_poller_output before + // being stored, so we must not apply the CDEF to it again here. We only + // transform the threshold values so the comparison is consistent. if ($thold_data['thold_type'] == 0) { $thold_data['thold_hi'] = thold_build_cdef($cdef, $thold_data['thold_hi'], $thold_data['local_data_id'], $thold_data['data_template_rrd_id']); $thold_data['thold_low'] = thold_build_cdef($cdef, $thold_data['thold_low'], $thold_data['local_data_id'], $thold_data['data_template_rrd_id']);