Skip to content

Commit

Permalink
Bug - Nasty user_func vs divisor-multiplier issue (librenms#10122)
Browse files Browse the repository at this point in the history
* Nasty user_func vs divisor-multiplier issue

* tests
  • Loading branch information
PipoCanaja authored and Spencer Butler committed May 21, 2019
1 parent c029757 commit 20188e2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 541 deletions.
9 changes: 5 additions & 4 deletions includes/discovery/functions.inc.php
Expand Up @@ -1098,10 +1098,6 @@ function discovery_process(&$valid, $device, $sensor_type, $pre_cache)

$sensor_name = $device['os'];

if (isset($user_function) && function_exists($user_function)) {
$value = $user_function($value);
}

if ($sensor_type === 'state') {
$sensor_name = $data['state_name'] ?: $data['oid'];
create_state_index($sensor_name, $data['states']);
Expand All @@ -1110,6 +1106,11 @@ function discovery_process(&$valid, $device, $sensor_type, $pre_cache)
$value = ($value / $divisor) * $multiplier;
}

//user_func must be applied after divisor/multiplier
if (isset($user_function) && function_exists($user_function)) {
$value = $user_function($value);
}

$uindex = str_replace('{{ $index }}', $index, isset($data['index']) ? $data['index'] : $index);
discover_sensor($valid['sensor'], $sensor_type, $device, $oid, $uindex, $sensor_name, $descr, $divisor, $multiplier, $low_limit, $low_warn_limit, $warn_limit, $high_limit, $value, 'snmp', $entPhysicalIndex, $entPhysicalIndex_measured, $user_function, $group);

Expand Down

0 comments on commit 20188e2

Please sign in to comment.