diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index 2e55a09e87..0e891a031e 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -216,6 +216,10 @@ function discover_volt($device, $oid, $index, $type, $descr, $precision = 1, $lo if (mysql_result(mysql_query("SELECT count(volt_id) FROM `voltage` WHERE device_id = '".$device['device_id']."' AND volt_type = '$type' AND `volt_index` = '$index'"),0) == '0') { + + if(!$high_limit && isset($current)) { $high_limit = round($current * 1.05, 2); } + if(!$low_limit && isset($current)) { $low_limit = round($current * 0.95, 2); } + $query = "INSERT INTO voltage (`device_id`, `volt_oid`, `volt_index`, `volt_type`, `volt_descr`, `volt_precision`, `volt_limit`, `volt_limit_low`, `volt_current`) "; $query .= " VALUES ('".$device['device_id']."', '$oid', '$index', '$type', '$descr', '$precision', '$high_limit', '$low_limit', '$current')"; mysql_query($query); @@ -224,16 +228,25 @@ function discover_volt($device, $oid, $index, $type, $descr, $precision = 1, $lo } else { + $volt_entry = mysql_fetch_array(mysql_query("SELECT * FROM `voltage` WHERE device_id = '".$device['device_id']."' AND volt_type = '$type' AND `volt_index` = '$index'")); - if($oid == $volt_entry['volt_oid'] && $descr == $volt_entry['volt_descr'] && $precision == $volt_entry['volt_precision']) + + if(!isset($current) && isset($volt_entry['current'])) { $current = $volt_entry['current']; } + + + if(!$high_limit && !$volt_entry['volt_limit'] && $current) { $high_limit = round($current * 1.05, 2); } elseif (!$high_limit && $volt_entry['volt_limit']) { $high_limit = $volt_entry['volt_limit']; } + if(!$low_limit && !$volt_entry['volt_limit_low'] && $current) { $low_limit = round($current * 0.95, 2); } elseif (!$low_limit && $volt_entry['volt_limit_low']) { $low_limit = $volt_entry['volt_limit_low']; } + + if($oid == $volt_entry['volt_oid'] && $descr == $volt_entry['volt_descr'] && $precision == $volt_entry['volt_precision'] && $volt_entry['volt_limit'] == $high_limit && $volt_entry['volt_limit_low'] == $low_limit) { echo("."); } else { - mysql_query("UPDATE voltage SET `volt_descr` = '$descr', `volt_oid` = '$oid', `volt_precision` = '$precision' WHERE `device_id` = '" . $device['device_id'] . "' AND volt_type = '$type' AND `volt_index` = '$index' "); + $sql = "UPDATE voltage SET `volt_descr` = '$descr', `volt_oid` = '$oid', `volt_precision` = '$precision', `volt_limit_low` = '$low_limit', `volt_limit` = '$high_limit' WHERE `device_id` = '" . $device['device_id'] . "' AND volt_type = '$type' AND `volt_index` = '$index'"; + $query = mysql_query($sql); echo("U"); - if($debug) { echo("$query ". mysql_affected_rows() . " updated"); } + if($debug) { echo("$sql ". mysql_affected_rows() . " updated"); } } }