mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Avoid DivisionByZeroError (#16464)
* Avoid DivisionByZeroError * Use match for entPhySensorPrecision * Fix style * Add zepto * Update match condition
This commit is contained in:
@@ -112,41 +112,23 @@ if (! empty($entity_oids)) {
|
|||||||
}
|
}
|
||||||
$valid_sensor = check_entity_sensor($descr, $device);
|
$valid_sensor = check_entity_sensor($descr, $device);
|
||||||
$type = $entitysensor[$entry['entPhySensorType']];
|
$type = $entitysensor[$entry['entPhySensorType']];
|
||||||
// FIXME this stuff is foul
|
|
||||||
if ($entry['entPhySensorScale'] == 'nano') {
|
// Try to handle the scale
|
||||||
$divisor = '1000000000';
|
[$divisor, $multiplier] = match ($entry['entPhySensorScale']) {
|
||||||
$multiplier = '1';
|
'zepto' => [1000000000000000000, 1],
|
||||||
}
|
'nano' => [1000000000, 1],
|
||||||
if ($entry['entPhySensorScale'] == 'micro') {
|
'micro' => [1000000, 1],
|
||||||
$divisor = '1000000';
|
'milli' => [1000, 1],
|
||||||
$multiplier = '1';
|
'units' => [1, 1],
|
||||||
}
|
'kilo' => [1, 1000],
|
||||||
if ($entry['entPhySensorScale'] == 'milli') {
|
'mega' => [1, 1000000],
|
||||||
$divisor = '1000';
|
'giga' => [1, 1000000000],
|
||||||
$multiplier = '1';
|
'yocto' => [1, 1],
|
||||||
}
|
default => [1, 1],
|
||||||
if ($entry['entPhySensorScale'] == 'units') {
|
};
|
||||||
$divisor = '1';
|
|
||||||
$multiplier = '1';
|
if (is_numeric($entry['entPhySensorPrecision']) && $entry['entPhySensorPrecision'] > 0) {
|
||||||
}
|
$divisor .= str_pad('', $entry['entPhySensorPrecision'], '0');
|
||||||
if ($entry['entPhySensorScale'] == 'kilo') {
|
|
||||||
$divisor = '1';
|
|
||||||
$multiplier = '1000';
|
|
||||||
}
|
|
||||||
if ($entry['entPhySensorScale'] == 'mega') {
|
|
||||||
$divisor = '1';
|
|
||||||
$multiplier = '1000000';
|
|
||||||
}
|
|
||||||
if ($entry['entPhySensorScale'] == 'giga') {
|
|
||||||
$divisor = '1';
|
|
||||||
$multiplier = '1000000000';
|
|
||||||
}
|
|
||||||
if ($entry['entPhySensorScale'] == 'yocto') {
|
|
||||||
$divisor = '1';
|
|
||||||
$multiplier = '1';
|
|
||||||
}
|
|
||||||
if (is_numeric($entry['entPhySensorPrecision']) && $entry['entPhySensorPrecision'] > '0') {
|
|
||||||
$divisor = $divisor . str_pad('', $entry['entPhySensorPrecision'], '0');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$current = ($current * $multiplier / $divisor);
|
$current = ($current * $multiplier / $divisor);
|
||||||
|
Reference in New Issue
Block a user