mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
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:
@ -382,29 +382,20 @@ function discover_sensor(&$valid, $class, $device, $oid, $index, $type, $descr,
|
||||
|
||||
function sensor_low_limit($class, $current)
|
||||
{
|
||||
$limit = null;
|
||||
|
||||
// matching an empty case executes code until a break is reached
|
||||
switch ($class) {
|
||||
case 'temperature':
|
||||
$limit = $current - 10;
|
||||
break;
|
||||
case 'voltage':
|
||||
$limit = $current * 0.85;
|
||||
$limit = $current * 0.85;
|
||||
break;
|
||||
case 'humidity':
|
||||
$limit = 30;
|
||||
break;
|
||||
case 'count':
|
||||
case 'current':
|
||||
$limit = null;
|
||||
break;
|
||||
case 'fanspeed':
|
||||
$limit = $current * 0.80;
|
||||
break;
|
||||
case 'power':
|
||||
$limit = null;
|
||||
break;
|
||||
case 'power_consumed':
|
||||
case 'power_factor':
|
||||
$limit = -1;
|
||||
break;
|
||||
@ -412,34 +403,24 @@ function sensor_low_limit($class, $current)
|
||||
$limit = -80;
|
||||
break;
|
||||
case 'airflow':
|
||||
case 'dbm':
|
||||
case 'snr':
|
||||
case 'frequency':
|
||||
case 'pressure':
|
||||
case 'cooling':
|
||||
$limit = $current * 0.95;
|
||||
break;
|
||||
case 'delay':
|
||||
case 'quality_factor':
|
||||
case 'chromatic_dispersion':
|
||||
case 'ber':
|
||||
case 'eer':
|
||||
case 'waterflow':
|
||||
default:
|
||||
return null;
|
||||
}//end switch
|
||||
|
||||
if (is_numeric($limit)) {
|
||||
return round($limit, 11);
|
||||
}
|
||||
|
||||
return $limit;
|
||||
return round($limit, 11);
|
||||
}
|
||||
|
||||
//end sensor_low_limit()
|
||||
|
||||
function sensor_limit($class, $current)
|
||||
{
|
||||
$limit = null;
|
||||
|
||||
// matching an empty case executes code until a break is reached
|
||||
switch ($class) {
|
||||
case 'temperature':
|
||||
$limit = $current + 20;
|
||||
@ -450,18 +431,12 @@ function sensor_limit($class, $current)
|
||||
case 'humidity':
|
||||
$limit = 70;
|
||||
break;
|
||||
case 'count':
|
||||
case 'current':
|
||||
case 'power':
|
||||
$limit = $current * 1.50;
|
||||
break;
|
||||
case 'power_consumed':
|
||||
case 'power_factor':
|
||||
$limit = 1;
|
||||
break;
|
||||
case 'fanspeed':
|
||||
$limit = $current * 1.80;
|
||||
break;
|
||||
case 'power_factor':
|
||||
$limit = 1;
|
||||
break;
|
||||
case 'signal':
|
||||
$limit = -30;
|
||||
break;
|
||||
@ -469,20 +444,17 @@ function sensor_limit($class, $current)
|
||||
$limit = 80;
|
||||
break;
|
||||
case 'airflow':
|
||||
case 'dbm':
|
||||
case 'snr':
|
||||
case 'frequency':
|
||||
case 'pressure':
|
||||
case 'cooling':
|
||||
$limit = $current * 1.05;
|
||||
break;
|
||||
default:
|
||||
return null;
|
||||
}//end switch
|
||||
|
||||
if (is_numeric($limit)) {
|
||||
return round($limit, 11);
|
||||
}
|
||||
|
||||
return $limit;
|
||||
return round($limit, 11);
|
||||
}
|
||||
|
||||
//end sensor_limit()
|
||||
|
Reference in New Issue
Block a user