mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Fix Temperature Sensor for AirOS 8.7.4+ (#13655)
* Fix Temperature Sensor for AirOS 8 * Update airos_airos8.json * Update airos.json * Add new skip_values feature to deal with Ubiquiti nonsense. Tweak test data to test the change fix not_regex Co-authored-by: Tony Murray <murraytony@gmail.com>
This commit is contained in:
@@ -325,12 +325,13 @@ class YamlDiscovery
|
|||||||
* Check to see if we should skip this discovery item
|
* Check to see if we should skip this discovery item
|
||||||
*
|
*
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
|
* @param int|string $index
|
||||||
* @param array $yaml_item_data The data key from this item
|
* @param array $yaml_item_data The data key from this item
|
||||||
* @param array $group_options The options key from this group of items
|
* @param array $group_options The options key from this group of items
|
||||||
* @param array $pre_cache The pre-cache data array
|
* @param array $pre_cache The pre-cache data array
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public static function canSkipItem($value, $index, $yaml_item_data, $group_options, $pre_cache = [])
|
public static function canSkipItem($value, $index, array $yaml_item_data, array $group_options, array $pre_cache = []): bool
|
||||||
{
|
{
|
||||||
$skip_values = array_replace((array) ($group_options['skip_values'] ?? []), (array) ($yaml_item_data['skip_values'] ?? []));
|
$skip_values = array_replace((array) ($group_options['skip_values'] ?? []), (array) ($yaml_item_data['skip_values'] ?? []));
|
||||||
|
|
||||||
@@ -338,11 +339,19 @@ class YamlDiscovery
|
|||||||
if (is_array($skip_value) && $pre_cache) {
|
if (is_array($skip_value) && $pre_cache) {
|
||||||
// Dynamic skipping of data
|
// Dynamic skipping of data
|
||||||
$op = $skip_value['op'] ?? '!=';
|
$op = $skip_value['op'] ?? '!=';
|
||||||
$tmp_value = static::getValueFromData($skip_value['oid'], $index, $yaml_item_data, $pre_cache);
|
|
||||||
if (Str::contains($skip_value['oid'], '.')) {
|
if (isset($skip_value['device'])) {
|
||||||
[$skip_value['oid'], $targeted_index] = explode('.', $skip_value['oid'], 2);
|
// field from device model
|
||||||
$tmp_value = static::getValueFromData($skip_value['oid'], $targeted_index, $yaml_item_data, $pre_cache);
|
$tmp_value = \DeviceCache::getPrimary()[$skip_value['device']] ?? null;
|
||||||
|
} else {
|
||||||
|
// oid previously fetched from the device
|
||||||
|
$tmp_value = static::getValueFromData($skip_value['oid'], $index, $yaml_item_data, $pre_cache);
|
||||||
|
if (Str::contains($skip_value['oid'], '.')) {
|
||||||
|
[$skip_value['oid'], $targeted_index] = explode('.', $skip_value['oid'], 2);
|
||||||
|
$tmp_value = static::getValueFromData($skip_value['oid'], $targeted_index, $yaml_item_data, $pre_cache);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (compare_var($tmp_value, $skip_value['value'], $op)) {
|
if (compare_var($tmp_value, $skip_value['value'], $op)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -149,6 +149,7 @@ the variable name. Example `{{ $ifName:2 }}`
|
|||||||
> `skip_values` can also compare items within the OID table against
|
> `skip_values` can also compare items within the OID table against
|
||||||
> values. The index of the sensor is used to retrieve the value
|
> values. The index of the sensor is used to retrieve the value
|
||||||
> from the OID, unless a target index is appended to the OID.
|
> from the OID, unless a target index is appended to the OID.
|
||||||
|
> Additionally, you may check fields from the device.
|
||||||
> Comparisons behave on a logical OR basis when chained, so only
|
> Comparisons behave on a logical OR basis when chained, so only
|
||||||
> one of them needs to be matched for that particular sensor
|
> one of them needs to be matched for that particular sensor
|
||||||
> to be skipped during discovery. An example of this is below:
|
> to be skipped during discovery. An example of this is below:
|
||||||
@@ -163,6 +164,10 @@ the variable name. Example `{{ $ifName:2 }}`
|
|||||||
oid: sensConfig.0
|
oid: sensConfig.0
|
||||||
op: '!='
|
op: '!='
|
||||||
value: 1
|
value: 1
|
||||||
|
-
|
||||||
|
device: hardware
|
||||||
|
op: 'contains'
|
||||||
|
value: 'rev2'
|
||||||
```
|
```
|
||||||
|
|
||||||
`op` can be any of the following operators :
|
`op` can be any of the following operators :
|
||||||
|
@@ -30,4 +30,19 @@ modules:
|
|||||||
divisor: 1
|
divisor: 1
|
||||||
num_oid: '.1.3.6.1.4.1.41112.1.4.8.4.{{ $index }}'
|
num_oid: '.1.3.6.1.4.1.41112.1.4.8.4.{{ $index }}'
|
||||||
descr: Temperature
|
descr: Temperature
|
||||||
|
skip_values:
|
||||||
|
-
|
||||||
|
device: version
|
||||||
|
op: 'regex'
|
||||||
|
value: '/^(8\.7\.[4-9]|8\.8|9|\d{2,})\./'
|
||||||
|
-
|
||||||
|
oid: ubntHostTemperature
|
||||||
|
divisor: 10000000
|
||||||
|
num_oid: '.1.3.6.1.4.1.41112.1.4.8.4.{{ $index }}'
|
||||||
|
descr: Temperature
|
||||||
|
skip_values:
|
||||||
|
-
|
||||||
|
device: version
|
||||||
|
op: 'not_regex'
|
||||||
|
value: '/^(8\.7\.[4-9]|8\.8|9|\d{2,})\./'
|
||||||
|
|
||||||
|
@@ -180,7 +180,7 @@ function compare_var($a, $b, $comparison = '=')
|
|||||||
return ! Str::endsWith($a, $b);
|
return ! Str::endsWith($a, $b);
|
||||||
case 'regex':
|
case 'regex':
|
||||||
return (bool) preg_match($b, $a);
|
return (bool) preg_match($b, $a);
|
||||||
case 'not regex':
|
case 'not_regex':
|
||||||
return ! ((bool) preg_match($b, $a));
|
return ! ((bool) preg_match($b, $a));
|
||||||
case 'in_array':
|
case 'in_array':
|
||||||
return in_array($a, $b);
|
return in_array($a, $b);
|
||||||
|
@@ -487,6 +487,16 @@
|
|||||||
"oid": {
|
"oid": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"device": {
|
||||||
|
"enum": [
|
||||||
|
"sysName",
|
||||||
|
"sysObjectID",
|
||||||
|
"sysDescr",
|
||||||
|
"version",
|
||||||
|
"hardware",
|
||||||
|
"features"
|
||||||
|
]
|
||||||
|
},
|
||||||
"op": {
|
"op": {
|
||||||
"$ref": "#/definitions/comparison"
|
"$ref": "#/definitions/comparison"
|
||||||
},
|
},
|
||||||
@@ -499,10 +509,11 @@
|
|||||||
},
|
},
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
"required": [
|
"required": [
|
||||||
"oid",
|
|
||||||
"op",
|
"op",
|
||||||
"value"
|
"value"
|
||||||
]
|
],
|
||||||
|
"minProperties": 3,
|
||||||
|
"maxProperties": 3
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@@ -2590,11 +2590,6 @@ parameters:
|
|||||||
count: 1
|
count: 1
|
||||||
path: LibreNMS/Device/WirelessSensor.php
|
path: LibreNMS/Device/WirelessSensor.php
|
||||||
|
|
||||||
-
|
|
||||||
message: "#^Method LibreNMS\\\\Device\\\\YamlDiscovery\\:\\:canSkipItem\\(\\) has parameter \\$index with no type specified\\.$#"
|
|
||||||
count: 1
|
|
||||||
path: LibreNMS/Device/YamlDiscovery.php
|
|
||||||
|
|
||||||
-
|
-
|
||||||
message: "#^Method LibreNMS\\\\Device\\\\YamlDiscovery\\:\\:oidIsNumeric\\(\\) has no return type specified\\.$#"
|
message: "#^Method LibreNMS\\\\Device\\\\YamlDiscovery\\:\\:oidIsNumeric\\(\\) has no return type specified\\.$#"
|
||||||
count: 1
|
count: 1
|
||||||
|
@@ -1,4 +1,25 @@
|
|||||||
{
|
{
|
||||||
|
"os": {
|
||||||
|
"discovery": {
|
||||||
|
"devices": [
|
||||||
|
{
|
||||||
|
"sysName": "<private>",
|
||||||
|
"sysObjectID": ".1.3.6.1.4.1.10002.1",
|
||||||
|
"sysDescr": "Linux 2.6.32.68 #1 Fri Dec 16 15:44:21 EET 2016 mips",
|
||||||
|
"sysContact": "<private>",
|
||||||
|
"version": "8.5.1.37185.180307.0931",
|
||||||
|
"hardware": "Rocket Prism 5AC Gen2",
|
||||||
|
"features": null,
|
||||||
|
"os": "airos",
|
||||||
|
"type": "wireless",
|
||||||
|
"serial": null,
|
||||||
|
"icon": "ubiquiti.svg",
|
||||||
|
"location": "<private>"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"poller": "matches discovery"
|
||||||
|
},
|
||||||
"wireless": {
|
"wireless": {
|
||||||
"discovery": {
|
"discovery": {
|
||||||
"wireless_sensors": [
|
"wireless_sensors": [
|
||||||
@@ -699,26 +720,5 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"poller": "matches discovery"
|
"poller": "matches discovery"
|
||||||
},
|
|
||||||
"os": {
|
|
||||||
"discovery": {
|
|
||||||
"devices": [
|
|
||||||
{
|
|
||||||
"sysName": "<private>",
|
|
||||||
"sysObjectID": ".1.3.6.1.4.1.10002.1",
|
|
||||||
"sysDescr": "Linux 2.6.32.68 #1 Fri Dec 16 15:44:21 EET 2016 mips",
|
|
||||||
"sysContact": "<private>",
|
|
||||||
"version": "8.5.1.37185.180307.0931",
|
|
||||||
"hardware": "Rocket Prism 5AC Gen2",
|
|
||||||
"features": null,
|
|
||||||
"os": "airos",
|
|
||||||
"type": "wireless",
|
|
||||||
"serial": null,
|
|
||||||
"icon": "ubiquiti.svg",
|
|
||||||
"location": "<private>"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"poller": "matches discovery"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -7,7 +7,7 @@
|
|||||||
"sysObjectID": ".1.3.6.1.4.1.10002.1",
|
"sysObjectID": ".1.3.6.1.4.1.10002.1",
|
||||||
"sysDescr": "Linux 2.6.32.68 #1 Thu Aug 22 16:38:44 EEST 2019 mips",
|
"sysDescr": "Linux 2.6.32.68 #1 Thu Aug 22 16:38:44 EEST 2019 mips",
|
||||||
"sysContact": "<private>",
|
"sysContact": "<private>",
|
||||||
"version": "8.6.2.41239.190822.1633",
|
"version": "8.7.4.45112.210415.1103",
|
||||||
"hardware": "LiteBeam 5AC Gen2",
|
"hardware": "LiteBeam 5AC Gen2",
|
||||||
"features": null,
|
"features": null,
|
||||||
"os": "airos",
|
"os": "airos",
|
||||||
@@ -1974,12 +1974,12 @@
|
|||||||
"sensor_type": "airos",
|
"sensor_type": "airos",
|
||||||
"sensor_descr": "Temperature",
|
"sensor_descr": "Temperature",
|
||||||
"group": null,
|
"group": null,
|
||||||
"sensor_divisor": 1,
|
"sensor_divisor": 10000000,
|
||||||
"sensor_multiplier": 1,
|
"sensor_multiplier": 1,
|
||||||
"sensor_current": 0,
|
"sensor_current": 16,
|
||||||
"sensor_limit": 20,
|
"sensor_limit": 36,
|
||||||
"sensor_limit_warn": null,
|
"sensor_limit_warn": null,
|
||||||
"sensor_limit_low": -10,
|
"sensor_limit_low": 6,
|
||||||
"sensor_limit_low_warn": null,
|
"sensor_limit_low_warn": null,
|
||||||
"sensor_alert": 1,
|
"sensor_alert": 1,
|
||||||
"sensor_custom": "No",
|
"sensor_custom": "No",
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
1.2.840.10036.3.1.2.1.3.7|4|LiteBeam 5AC Gen2
|
1.2.840.10036.3.1.2.1.3.7|4|LiteBeam 5AC Gen2
|
||||||
1.2.840.10036.3.1.2.1.3.9|4|LiteBeam 5AC Gen2
|
1.2.840.10036.3.1.2.1.3.9|4|LiteBeam 5AC Gen2
|
||||||
1.2.840.10036.3.1.2.1.4.7|4|WA.ar934x.v8.6.2.41239.190822.1633
|
1.2.840.10036.3.1.2.1.4.7|4|WA.ar934x.v8.7.4.45112.210415.1103
|
||||||
1.3.6.1.2.1.1.1.0|4|Linux 2.6.32.68 #1 Thu Aug 22 16:38:44 EEST 2019 mips
|
1.3.6.1.2.1.1.1.0|4|Linux 2.6.32.68 #1 Thu Aug 22 16:38:44 EEST 2019 mips
|
||||||
1.3.6.1.2.1.1.2.0|6|1.3.6.1.4.1.10002.1
|
1.3.6.1.2.1.1.2.0|6|1.3.6.1.4.1.10002.1
|
||||||
1.3.6.1.2.1.1.3.0|67|964450100
|
1.3.6.1.2.1.1.3.0|67|964450100
|
||||||
@@ -251,5 +251,5 @@
|
|||||||
1.3.6.1.4.1.41112.1.4.6.1.4.1|2|0
|
1.3.6.1.4.1.41112.1.4.6.1.4.1|2|0
|
||||||
1.3.6.1.4.1.41112.1.4.6.1.7.1|2|699
|
1.3.6.1.4.1.41112.1.4.6.1.7.1|2|699
|
||||||
1.3.6.1.4.1.41112.1.4.8.3.0|2|606
|
1.3.6.1.4.1.41112.1.4.8.3.0|2|606
|
||||||
1.3.6.1.4.1.41112.1.4.8.4.0|2|0
|
1.3.6.1.4.1.41112.1.4.8.4.0|2|160000000
|
||||||
1.3.6.1.4.1.41112.1.4.9.2.0|2|0
|
1.3.6.1.4.1.41112.1.4.9.2.0|2|0
|
||||||
|
Reference in New Issue
Block a user