Changes to guessed limit functions for sensors.

Original behaviour
===================

The file `includes/discovery/functions.inc.php` contains
`sensor_limit_low()` and `sensor_limit()` which both attempt to
guess a sane value for sensors when no explicitly defined
low_limit or high_limit can be found during discovery.

Both switch control structures used in those two functions
have empty case statements which means that if one of those matches,
it's going to fall through and run the code for each subsequent
case until a `break` is reached.

For example, when we call `function sensor_low_limit(dbm, -13.036)`
it will return the value `-12.3842` instead of `null`. That is
because there will be a match at `case 'dbm':` which falls through
all the way to `case 'cooling':`, where it performs
`$limit = -13.036 * 0.95` before hitting a `break`.

Changed behaviour
===================

Removed `power_consumed` and `count` guessed low_limit and
high_limit, I personally added those sensor classes in PR #9471
when I didn't understand that a switch control structure has
fall-through behaviour so I can guarantee that guessing limits for
those is a mistake on my behalf. It should not be there, only
power_factor can have guessed limits. Apologies for the issue,
I'm still a beginning programmer!

Furthermore, I removed guessed high_limit values for `current`
and `power` because these are supposed to draw higher values as
more devices or components are installed on for example a PDU or
a chassis.

Finally, I removed guessed low_limit and high_limit for `dbm`
sensors, there is a much too large variance in power budget on
commercially available optical transceivers for there to be a
sensible window where you can guess these values.
This commit is contained in:
Martijn Schmidt
2019-06-12 23:21:29 +02:00
parent 1e2df364bb
commit 30212d2717

View File

@ -382,8 +382,7 @@ function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr,
function sensor_low_limit($class, $current) function sensor_low_limit($class, $current)
{ {
$limit = null; // matching an empty case executes code until a break is reached
switch ($class) { switch ($class) {
case 'temperature': case 'temperature':
$limit = $current - 10; $limit = $current - 10;
@ -394,17 +393,9 @@ function sensor_low_limit($class, $current)
case 'humidity': case 'humidity':
$limit = 30; $limit = 30;
break; break;
case 'count':
case 'current':
$limit = null;
break;
case 'fanspeed': case 'fanspeed':
$limit = $current * 0.80; $limit = $current * 0.80;
break; break;
case 'power':
$limit = null;
break;
case 'power_consumed':
case 'power_factor': case 'power_factor':
$limit = -1; $limit = -1;
break; break;
@ -412,34 +403,24 @@ function sensor_low_limit($class, $current)
$limit = -80; $limit = -80;
break; break;
case 'airflow': case 'airflow':
case 'dbm':
case 'snr': case 'snr':
case 'frequency': case 'frequency':
case 'pressure': case 'pressure':
case 'cooling': case 'cooling':
$limit = $current * 0.95; $limit = $current * 0.95;
break; break;
case 'delay': default:
case 'quality_factor': return null;
case 'chromatic_dispersion':
case 'ber':
case 'eer':
case 'waterflow':
}//end switch }//end switch
if (is_numeric($limit)) {
return round($limit, 11); return round($limit, 11);
}
return $limit;
} }
//end sensor_low_limit() //end sensor_low_limit()
function sensor_limit($class, $current) function sensor_limit($class, $current)
{ {
$limit = null; // matching an empty case executes code until a break is reached
switch ($class) { switch ($class) {
case 'temperature': case 'temperature':
$limit = $current + 20; $limit = $current + 20;
@ -450,18 +431,12 @@ function sensor_limit($class, $current)
case 'humidity': case 'humidity':
$limit = 70; $limit = 70;
break; break;
case 'count':
case 'current':
case 'power':
$limit = $current * 1.50;
break;
case 'power_consumed':
case 'power_factor':
$limit = 1;
break;
case 'fanspeed': case 'fanspeed':
$limit = $current * 1.80; $limit = $current * 1.80;
break; break;
case 'power_factor':
$limit = 1;
break;
case 'signal': case 'signal':
$limit = -30; $limit = -30;
break; break;
@ -469,20 +444,17 @@ function sensor_limit($class, $current)
$limit = 80; $limit = 80;
break; break;
case 'airflow': case 'airflow':
case 'dbm':
case 'snr': case 'snr':
case 'frequency': case 'frequency':
case 'pressure': case 'pressure':
case 'cooling': case 'cooling':
$limit = $current * 1.05; $limit = $current * 1.05;
break; break;
default:
return null;
}//end switch }//end switch
if (is_numeric($limit)) {
return round($limit, 11); return round($limit, 11);
}
return $limit;
} }
//end sensor_limit() //end sensor_limit()