Dynamic_discovery_get_value in can_skip_sensor to use all oids in skip_values (#9495)

* Use of dynamic_discovery_get_value in can_skip_sensor in order to use all available oids in skip_values

* Use LibreNMS\Device\YamlDiscovery code instead of keeping duplicated function can_skip_sensor

* Fix Travis errors
This commit is contained in:
PipoCanaja 2018-12-05 19:40:29 +01:00 committed by Tony Murray
parent b39984994b
commit 0b3f1daed9
2 changed files with 6 additions and 49 deletions

View File

@ -90,7 +90,7 @@ class YamlDiscovery
}
}
if (static::canSkipItem($current_data['value'], $current_data, $group_options, $snmp_data)) {
if (static::canSkipItem($current_data['value'], $index, $current_data, $group_options, $snmp_data)) {
continue;
}
@ -227,15 +227,15 @@ class YamlDiscovery
* @param array $item_snmp_data The pre-cache data array
* @return bool
*/
private static function canSkipItem($value, $yaml_item_data, $group_options, $item_snmp_data = array())
public static function canSkipItem($value, $index, $yaml_item_data, $group_options, $pre_cache = array())
{
$skip_values = array_replace((array)$group_options['skip_values'], (array)$yaml_item_data['skip_values']);
foreach ($skip_values as $skip_value) {
if (is_array($skip_value) && $item_snmp_data) {
if (is_array($skip_value) && $pre_cache) {
// Dynamic skipping of data
$op = isset($skip_value['op']) ? $skip_value['op'] : '!=';
$tmp_value = $item_snmp_data[$skip_value['oid']];
$tmp_value = static::getValueFromData($skip_value['oid'], $index, $yaml_item_data, $pre_cache);
if (compare_var($tmp_value, $skip_value['value'], $op)) {
return true;
}

View File

@ -18,6 +18,7 @@ use LibreNMS\Exceptions\InvalidIpException;
use LibreNMS\OS;
use LibreNMS\Util\IP;
use LibreNMS\Util\IPv6;
use LibreNMS\Device\YamlDiscovery;
function discover_new_device($hostname, $device = '', $method = '', $interface = '')
{
@ -931,50 +932,6 @@ function ignore_storage($os, $descr)
return false;
}
/**
* @param $value
* @param $data
* @param $group
* @param null $index
* @param array $pre_cache
* @return bool
*/
function can_skip_sensor($value, $data, $group, $pre_cache = array())
{
$skip_values = array_replace((array)$group['skip_values'], (array)$data['skip_values']);
foreach ($skip_values as $skip_value) {
if (is_array($skip_value) && $pre_cache) {
// Dynamic skipping of data
$op = isset($skip_value['op']) ? $skip_value['op'] : '!=';
$tmp_value = $pre_cache[$skip_value['oid']];
if (compare_var($tmp_value, $skip_value['value'], $op) == true) {
return true;
}
}
if ($value == $skip_value) {
return true;
}
}
$skip_value_lt = array_replace((array)$group['skip_value_lt'], (array)$data['skip_value_lt']);
foreach ($skip_value_lt as $skip_value) {
if ($value < $skip_value) {
return true;
}
}
$skip_value_gt = array_replace((array)$group['skip_value_gt'], (array)$data['skip_value_gt']);
foreach ($skip_value_gt as $skip_value) {
if ($value > $skip_value) {
return true;
}
}
return false;
}
/**
* @param $valid
* @param $device
@ -1033,7 +990,7 @@ function discovery_process(&$valid, $device, $sensor_type, $pre_cache)
d_echo("Final sensor value: $value\n");
if (can_skip_sensor($value, $data, $sensor_options, $raw_data[$index]) === false && is_numeric($value)) {
if (YamlDiscovery::canSkipItem($value, $index, $data, $sensor_options, $pre_cache) === false && is_numeric($value)) {
$oid = str_replace('{{ $index }}', $index, $data['num_oid']);
// process the description