fix: attempt to fix several bugs with sensor limits and incorrect detection (#6176)

This commit is contained in:
Tony Murray
2017-03-12 09:56:56 -05:00
committed by Neil Lathwood
parent 58495a3910
commit ea5a4b3586
3 changed files with 16 additions and 10 deletions

View File

@@ -187,7 +187,7 @@ function discover_device($device, $options = null)
// Discover sensors
function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr, $divisor = '1', $multiplier = '1', $low_limit = null, $low_warn_limit = null, $warn_limit = null, $high_limit = null, $current = null, $poller_type = 'snmp', $entPhysicalIndex = null, $entPhysicalIndex_measured = null)
function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr, $divisor = 1, $multiplier = 1, $low_limit = null, $low_warn_limit = null, $warn_limit = null, $high_limit = null, $current = null, $poller_type = 'snmp', $entPhysicalIndex = null, $entPhysicalIndex_measured = null)
{
$low_limit = set_null($low_limit);
@@ -199,27 +199,27 @@ function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr,
$divisor = 1;
}
d_echo("Discover sensor: $oid, $index, $type, $descr, $poller_type, $precision, $entPhysicalIndex\n");
d_echo("Discover sensor: $oid, $index, $type, $descr, $poller_type, $divisor, $multiplier, $entPhysicalIndex, $current\n");
if (is_null($low_warn_limit) && !is_null($warn_limit)) {
// Warn limits only make sense when we have both a high and a low limit
$low_warn_limit = null;
$warn_limit = null;
} elseif ($low_warn_limit > $warn_limit) {
} elseif (!is_null($warn_limit) && $low_warn_limit > $warn_limit) {
// Fix high/low thresholds (i.e. on negative numbers)
list($warn_limit, $low_warn_limit) = array($low_warn_limit, $warn_limit);
}
if (dbFetchCell('SELECT COUNT(sensor_id) FROM `sensors` WHERE `poller_type`= ? AND `sensor_class` = ? AND `device_id` = ? AND sensor_type = ? AND `sensor_index` = ?', array($poller_type, $class, $device['device_id'], $type, $index)) == '0') {
if (!$high_limit) {
if (is_null($high_limit)) {
$high_limit = sensor_limit($class, $current);
}
if (!$low_limit) {
if (is_null($low_limit)) {
$low_limit = sensor_low_limit($class, $current);
}
if ($low_limit > $high_limit) {
if (!is_null($high_limit) && $low_limit > $high_limit) {
// Fix high/low thresholds (i.e. on negative numbers)
list($high_limit, $low_limit) = array($low_limit, $high_limit);
}

View File

@@ -19,6 +19,6 @@ foreach (explode("\n", $oids) as $data) {
$type = 'rfc1628';
$index = (500 + $current_id);
discover_sensor($valid['sensor'], 'charge', $device, $current_oid, $index, $type, $descr, '1', '1', null, null, null, null, $current);
discover_sensor($valid['sensor'], 'charge', $device, $current_oid, $index, $type, $descr, 1, 1, 15, 50, null, 101, $current);
}
}

View File

@@ -16,8 +16,10 @@ for ($i = 1; $i <= $numPhase; $i++) {
$precision = 1;
$index = 300+$i;
if (is_numeric($current)) {
discover_sensor($valid['sensor'], 'power', $device, $current_oid, $index, $type, $descr, '1', '1', null, null, null, null, $current);
}
}
$oids = trim(snmp_walk($device, ".1.3.6.1.2.1.33.1.3.2.0", "-OsqnU"));
d_echo($oids."\n");
@@ -33,8 +35,10 @@ for ($i = 1; $i <= $numPhase; $i++) {
$precision = 1;
$index = 100+$i;
if (is_numeric($current)) {
discover_sensor($valid['sensor'], 'power', $device, $current_oid, $index, $type, $descr, '1', '1', null, null, null, null, $current);
}
}
$oids = trim(snmp_walk($device, ".1.3.6.1.2.1.33.1.5.2.0", "-OsqnU"));
d_echo($oids."\n");
@@ -50,5 +54,7 @@ for ($i = 1; $i <= $numPhase; $i++) {
$precision = 1;
$index = 200+$i;
if (is_numeric($current)) {
discover_sensor($valid['sensor'], 'power', $device, $current_oid, $index, $type, $descr, '1', '1', null, null, null, null, $current);
}
}