APC: Add support for Battery Recommended Days Remaining (#14653)

* APC: Add support for Battery Recommended Days Remaining

* Extract number from string later during polling
Odd that this is different from the discovery process

* wip

* wip

* Apply fixes from StyleCI

* wip

* wip

* Apply fixes from StyleCI

---------

Co-authored-by: Tony Murray <murraytony@gmail.com>
This commit is contained in:
Jellyfrog
2023-03-10 14:50:56 +01:00
committed by GitHub
parent 58acfe8f92
commit f111ac22fe
14 changed files with 201 additions and 34 deletions

View File

@@ -24,6 +24,7 @@ use LibreNMS\Exceptions\InvalidIpException;
use LibreNMS\OS;
use LibreNMS\Util\IP;
use LibreNMS\Util\IPv6;
use LibreNMS\Util\UserFuncHelper;
function discover_new_device($hostname, $device = [], $method = '', $interface = '')
{
@@ -943,8 +944,12 @@ function discovery_process(&$valid, $os, $sensor_class, $pre_cache)
if (is_numeric($$limit)) {
$$limit = ($$limit / $divisor) * $multiplier;
}
if (is_numeric($$limit) && isset($user_function) && is_callable($user_function)) {
$$limit = $user_function($$limit);
if (is_numeric($$limit) && isset($user_function)) {
if (is_callable($user_function)) {
$$limit = $user_function($$limit);
} else {
$$limit = (new UserFuncHelper($$limit))->{$user_function}();
}
}
}
}
@@ -964,8 +969,12 @@ function discovery_process(&$valid, $os, $sensor_class, $pre_cache)
$entPhysicalIndex_measured = isset($data['entPhysicalIndex_measured']) ? $data['entPhysicalIndex_measured'] : null;
//user_func must be applied after divisor/multiplier
if (isset($user_function) && is_callable($user_function)) {
$value = $user_function($value);
if (isset($user_function)) {
if (is_callable($user_function)) {
$value = $user_function($value);
} else {
$value = (new UserFuncHelper($value, $snmp_data[$data['value']], $data))->{$user_function}();
}
}
$uindex = $index;