From a586eb21d00b48f5b24ba81de0f797c998445cdf Mon Sep 17 00:00:00 2001 From: laf Date: Tue, 12 May 2015 10:10:03 +0100 Subject: [PATCH] Added a new db field to record when custom high/low limits are set and stop them being overwrote --- html/forms/health-update.inc.php | 2 +- includes/discovery/functions.inc.php | 8 ++++---- sql-schema/050.sql | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 sql-schema/050.sql diff --git a/html/forms/health-update.inc.php b/html/forms/health-update.inc.php index cb4f9e1822..0e762923e4 100644 --- a/html/forms/health-update.inc.php +++ b/html/forms/health-update.inc.php @@ -21,7 +21,7 @@ if(!is_numeric($_POST['device_id']) || !is_numeric($_POST['sensor_id']) || (empt } else { - $update = dbUpdate(array($_POST['value_type'] => $_POST['data']), 'sensors', '`sensor_id` = ? AND `device_id` = ?', array($_POST['sensor_id'],$_POST['device_id'])); + $update = dbUpdate(array($_POST['value_type'] => $_POST['data'], 'sensor_custom' => 'Yes'), 'sensors', '`sensor_id` = ? AND `device_id` = ?', array($_POST['sensor_id'],$_POST['device_id'])); if(!empty($update) || $update == '0') { echo('success'); diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index de62837cc6..fb216684ae 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -223,7 +223,7 @@ function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr, list($high_limit, $low_limit) = array($low_limit, $high_limit); } - if ($high_limit != $sensor_entry['sensor_limit']) + if ($high_limit != $sensor_entry['sensor_limit'] && $sensor_entry['sensor_custom'] == 'No') { $update = array('sensor_limit' => ($high_limit == NULL ? array('NULL') : $high_limit)); $updated = dbUpdate($update, 'sensors', '`sensor_id` = ?', array($sensor_entry['sensor_id'])); @@ -232,7 +232,7 @@ function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr, log_event("Sensor High Limit Updated: ".mres($class)." ".mres($type)." ". mres($index)." ".mres($descr)." (".$high_limit.")", $device, 'sensor', $sensor_id); } - if ($sensor_entry['sensor_limit_low'] != $low_limit) + if ($sensor_entry['sensor_limit_low'] != $low_limit && $sensor_entry['sensor_custom'] == 'No') { $update = array('sensor_limit_low' => ($low_limit == NULL ? array('NULL') : $low_limit)); $updated = dbUpdate($update, 'sensors', '`sensor_id` = ?', array($sensor_entry['sensor_id'])); @@ -241,7 +241,7 @@ function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr, log_event("Sensor Low Limit Updated: ".mres($class)." ".mres($type)." ". mres($index)." ".mres($descr)." (".$low_limit.")", $device, 'sensor', $sensor_id); } - if ($warn_limit != $sensor_entry['sensor_limit_warn']) + if ($warn_limit != $sensor_entry['sensor_limit_warn'] && $sensor_entry['sensor_custom'] == 'No') { $update = array('sensor_limit_warn' => ($warn_limit == NULL ? array('NULL') : $warn_limit)); $updated = dbUpdate($update, 'sensors', '`sensor_id` = ?', array($sensor_entry['sensor_id'])); @@ -250,7 +250,7 @@ function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr, log_event("Sensor Warn High Limit Updated: ".mres($class)." ".mres($type)." ". mres($index)." ".mres($descr)." (".$warn_limit.")", $device, 'sensor', $sensor_id); } - if ($sensor_entry['sensor_limit_low_warn'] != $low_warn_limit) + if ($sensor_entry['sensor_limit_low_warn'] != $low_warn_limit && $sensor_entry['sensor_custom'] == 'No') { $update = array('sensor_limit_low_warn' => ($low_warn_limit == NULL ? array('NULL') : $low_warn_limit)); $updated = dbUpdate($update, 'sensors', '`sensor_id` = ?', array($sensor_entry['sensor_id'])); diff --git a/sql-schema/050.sql b/sql-schema/050.sql new file mode 100644 index 0000000000..70413dcaf3 --- /dev/null +++ b/sql-schema/050.sql @@ -0,0 +1 @@ +ALTER TABLE `sensors` ADD `sensor_custom` ENUM( 'No', 'Yes' ) NOT NULL DEFAULT 'No' AFTER `sensor_alert` ;