snmpwalk functions: dont include invalid data (#14438)

* snmpwalk functions dont include invalid data

* wip

* wip
This commit is contained in:
Jellyfrog
2022-10-11 09:03:08 -05:00
committed by GitHub
parent be1a2cec50
commit bc9228ca8d
9 changed files with 56 additions and 430 deletions
+4
View File
@@ -40,6 +40,10 @@ class Stellar extends OS implements
$combined_oid = sprintf('%s::%s', $device['hardware'], 'apClientWlanService');
$oid = snmp_translate($combined_oid, 'ALL', 'nokia/stellar', '-On');
if (empty($oid)) {
return $sensors;
}
foreach ($client_ws_data as $client_entry) {
$ssid[$client_entry['apClientWlanService']] += 1;
}
@@ -1,6 +1,9 @@
<?php
$temps = snmp_walk($device, '.1.3.6.1.4.1.45.1.6.3.7.1.1.5.5', '-Osqn');
if (empty($temps)) {
return;
}
foreach (explode("\n", $temps) as $i => $t) {
$t = explode(' ', $t);
+49 -11
View File
@@ -439,6 +439,10 @@ function snmpwalk_cache_cip($device, $oid, $array = [], $mib = 0)
$cmd = gen_snmpwalk_cmd($device, $oid, '-OsnQ', $mib);
$data = trim(external_exec($cmd));
if (empty($data)) {
return $array;
}
// echo("Caching: $oid\n");
foreach (explode("\n", $data) as $entry) {
[$this_oid, $this_value] = preg_split('/=/', $entry);
@@ -489,9 +493,14 @@ function snmp_cache_ifIndex($device)
return $array;
}//end snmp_cache_ifIndex()
function snmpwalk_cache_oid($device, $oid, $array, $mib = null, $mibdir = null, $snmpflags = '-OQUs')
function snmpwalk_cache_oid($device, $oid, $array = [], $mib = null, $mibdir = null, $snmpflags = '-OQUs')
{
$data = snmp_walk($device, $oid, $snmpflags, $mib, $mibdir);
if (empty($data)) {
return $array;
}
foreach (explode("\n", $data) as $entry) {
if (! Str::contains($entry, ' =')) {
if (! empty($entry) && isset($index, $oid)) {
@@ -513,9 +522,14 @@ function snmpwalk_cache_oid($device, $oid, $array, $mib = null, $mibdir = null,
return $array;
}//end snmpwalk_cache_oid()
function snmpwalk_cache_numerical_oid($device, $oid, $array, $mib = null, $mibdir = null, $snmpflags = '-OQUsn')
function snmpwalk_cache_numerical_oid($device, $oid, $array = [], $mib = null, $mibdir = null, $snmpflags = '-OQUsn')
{
$data = snmp_walk($device, $oid, $snmpflags, $mib, $mibdir);
if (empty($data)) {
return $array;
}
foreach (explode("\n", $data) as $entry) {
[$oid,$value] = explode('=', $entry, 2);
$oid = trim($oid);
@@ -529,7 +543,7 @@ function snmpwalk_cache_numerical_oid($device, $oid, $array, $mib = null, $mibdi
return $array;
}//end snmpwalk_cache_oid()
function snmpwalk_cache_long_oid($device, $oid, $noid, $array, $mib = null, $mibdir = null, $snmpflags = '-OQnU')
function snmpwalk_cache_long_oid($device, $oid, $noid, $array = [], $mib = null, $mibdir = null, $snmpflags = '-OQnU')
{
$data = snmp_walk($device, $oid, $snmpflags, $mib, $mibdir);
@@ -567,19 +581,19 @@ function snmpwalk_cache_long_oid($device, $oid, $noid, $array, $mib = null, $mib
* @param string $mibdir
* @return bool|array
*/
function snmpwalk_cache_oid_num($device, $oid, $array, $mib = null, $mibdir = null)
function snmpwalk_cache_oid_num($device, $oid, $array = [], $mib = null, $mibdir = null)
{
return snmpwalk_cache_oid($device, $oid, $array, $mib, $mibdir, $snmpflags = '-OQUn');
}//end snmpwalk_cache_oid_num()
function snmpwalk_cache_multi_oid($device, $oid, $array, $mib = null, $mibdir = null, $snmpflags = '-OQUs')
function snmpwalk_cache_multi_oid($device, $oid, $array = [], $mib = null, $mibdir = null, $snmpflags = '-OQUs')
{
global $cache;
if (! (is_array($cache['snmp'][$device['device_id']] ?? null) && array_key_exists($oid, $cache['snmp'][$device['device_id']]))) {
$data = snmp_walk($device, $oid, $snmpflags, $mib, $mibdir);
if ($data) {
if (! empty($data)) {
foreach (explode("\n", $data) as $entry) {
if (! Str::contains($entry, ' =')) {
if (! empty($entry) && isset($index, $r_oid)) {
@@ -611,10 +625,14 @@ function snmpwalk_cache_multi_oid($device, $oid, $array, $mib = null, $mibdir =
return $cache['snmp'][$device['device_id']][$oid];
}//end snmpwalk_cache_multi_oid()
function snmpwalk_cache_double_oid($device, $oid, $array, $mib = null, $mibdir = null)
function snmpwalk_cache_double_oid($device, $oid, $array = [], $mib = null, $mibdir = null)
{
$data = snmp_walk($device, $oid, '-OQUs', $mib, $mibdir);
if (empty($data)) {
return $array;
}
foreach (explode("\n", $data) as $entry) {
[$oid,$value] = explode('=', $entry, 2);
$oid = trim($oid);
@@ -629,10 +647,14 @@ function snmpwalk_cache_double_oid($device, $oid, $array, $mib = null, $mibdir =
return $array;
}//end snmpwalk_cache_double_oid()
function snmpwalk_cache_index($device, $oid, $array, $mib = null, $mibdir = null)
function snmpwalk_cache_index($device, $oid, $array = [], $mib = null, $mibdir = null)
{
$data = snmp_walk($device, $oid, '-OQUs', $mib, $mibdir);
if (empty($data)) {
return $array;
}
foreach (explode("\n", $data) as $entry) {
[$oid,$value] = explode('=', $entry, 2);
$oid = trim($oid);
@@ -646,10 +668,14 @@ function snmpwalk_cache_index($device, $oid, $array, $mib = null, $mibdir = null
return $array;
}//end snmpwalk_cache_double_oid()
function snmpwalk_cache_triple_oid($device, $oid, $array, $mib = null, $mibdir = null)
function snmpwalk_cache_triple_oid($device, $oid, $array = [], $mib = null, $mibdir = null)
{
$data = snmp_walk($device, $oid, '-OQUs', $mib, $mibdir);
if (empty($data)) {
return $array;
}
foreach (explode("\n", $data) as $entry) {
[$oid,$value] = explode('=', $entry, 2);
$oid = trim($oid);
@@ -690,6 +716,10 @@ function snmpwalk_group($device, $oid, $mib = '', $depth = 1, $array = [], $mibd
$cmd = gen_snmpwalk_cmd($device, $oid, $snmpFlags, $mib, $mibdir);
$data = rtrim(external_exec($cmd));
if (empty($data)) {
return $array;
}
$line = strtok($data, "\n");
while ($line !== false) {
if (Str::contains($line, 'at this OID') || Str::contains($line, 'this MIB View')) {
@@ -721,11 +751,15 @@ function snmpwalk_group($device, $oid, $mib = '', $depth = 1, $array = [], $mibd
return $array;
}
function snmpwalk_cache_twopart_oid($device, $oid, $array, $mib = 0, $mibdir = null, $snmpflags = '-OQUs')
function snmpwalk_cache_twopart_oid($device, $oid, $array = [], $mib = 0, $mibdir = null, $snmpflags = '-OQUs')
{
$cmd = gen_snmpwalk_cmd($device, $oid, $snmpflags, $mib, $mibdir);
$data = trim(external_exec($cmd));
if (empty($data)) {
return $array;
}
foreach (explode("\n", $data) as $entry) {
if (! Str::contains($entry, ' =')) {
if (! empty($entry) && isset($first, $second, $oid)) {
@@ -749,11 +783,15 @@ function snmpwalk_cache_twopart_oid($device, $oid, $array, $mib = 0, $mibdir = n
return $array;
}//end snmpwalk_cache_twopart_oid()
function snmpwalk_cache_threepart_oid($device, $oid, $array, $mib = 0)
function snmpwalk_cache_threepart_oid($device, $oid, $array = [], $mib = 0)
{
$cmd = gen_snmpwalk_cmd($device, $oid, '-OQUs', $mib);
$data = trim(external_exec($cmd));
if (empty($data)) {
return $array;
}
foreach (explode("\n", $data) as $entry) {
[$oid,$value] = explode('=', $entry, 2);
$oid = trim($oid);
-126
View File
@@ -20930,69 +20930,6 @@
"entPhysicalIndex": null,
"entPhysicalIndex_measured": null,
"sensor_oids": "[\".1.3.6.1.4.1.14823.2.2.1.1.3.2.0\"]"
},
{
"sensor_deleted": 0,
"sensor_class": "utilization",
"sensor_index": "",
"sensor_type": "arubaos-iap",
"sensor_descr": "Radio ",
"sensor_divisor": 1,
"sensor_multiplier": 1,
"sensor_aggregator": "sum",
"sensor_current": 0,
"sensor_prev": null,
"sensor_limit": null,
"sensor_limit_warn": null,
"sensor_limit_low": null,
"sensor_limit_low_warn": null,
"sensor_alert": 1,
"sensor_custom": "No",
"entPhysicalIndex": null,
"entPhysicalIndex_measured": null,
"sensor_oids": "[\".\"]"
},
{
"sensor_deleted": 0,
"sensor_class": "power",
"sensor_index": "",
"sensor_type": "arubaos-iap",
"sensor_descr": "Radio : Tx Power",
"sensor_divisor": 1,
"sensor_multiplier": 1,
"sensor_aggregator": "sum",
"sensor_current": 0,
"sensor_prev": null,
"sensor_limit": null,
"sensor_limit_warn": null,
"sensor_limit_low": null,
"sensor_limit_low_warn": null,
"sensor_alert": 1,
"sensor_custom": "No",
"entPhysicalIndex": null,
"entPhysicalIndex_measured": null,
"sensor_oids": "[\".\"]"
},
{
"sensor_deleted": 0,
"sensor_class": "noise-floor",
"sensor_index": "",
"sensor_type": "arubaos-iap",
"sensor_descr": "Radio ",
"sensor_divisor": 1,
"sensor_multiplier": 1,
"sensor_aggregator": "sum",
"sensor_current": 0,
"sensor_prev": null,
"sensor_limit": null,
"sensor_limit_warn": null,
"sensor_limit_low": null,
"sensor_limit_low_warn": null,
"sensor_alert": 1,
"sensor_custom": "No",
"entPhysicalIndex": null,
"entPhysicalIndex_measured": null,
"sensor_oids": "[\".\"]"
}
]
},
@@ -21039,69 +20976,6 @@
"entPhysicalIndex": null,
"entPhysicalIndex_measured": null,
"sensor_oids": "[\".1.3.6.1.4.1.14823.2.2.1.1.3.2.0\"]"
},
{
"sensor_deleted": 0,
"sensor_class": "utilization",
"sensor_index": "",
"sensor_type": "arubaos-iap",
"sensor_descr": "Radio ",
"sensor_divisor": 1,
"sensor_multiplier": 1,
"sensor_aggregator": "sum",
"sensor_current": null,
"sensor_prev": 0,
"sensor_limit": null,
"sensor_limit_warn": null,
"sensor_limit_low": null,
"sensor_limit_low_warn": null,
"sensor_alert": 1,
"sensor_custom": "No",
"entPhysicalIndex": null,
"entPhysicalIndex_measured": null,
"sensor_oids": "[\".\"]"
},
{
"sensor_deleted": 0,
"sensor_class": "power",
"sensor_index": "",
"sensor_type": "arubaos-iap",
"sensor_descr": "Radio : Tx Power",
"sensor_divisor": 1,
"sensor_multiplier": 1,
"sensor_aggregator": "sum",
"sensor_current": null,
"sensor_prev": 0,
"sensor_limit": null,
"sensor_limit_warn": null,
"sensor_limit_low": null,
"sensor_limit_low_warn": null,
"sensor_alert": 1,
"sensor_custom": "No",
"entPhysicalIndex": null,
"entPhysicalIndex_measured": null,
"sensor_oids": "[\".\"]"
},
{
"sensor_deleted": 0,
"sensor_class": "noise-floor",
"sensor_index": "",
"sensor_type": "arubaos-iap",
"sensor_descr": "Radio ",
"sensor_divisor": 1,
"sensor_multiplier": 1,
"sensor_aggregator": "sum",
"sensor_current": null,
"sensor_prev": 0,
"sensor_limit": null,
"sensor_limit_warn": null,
"sensor_limit_low": null,
"sensor_limit_low_warn": null,
"sensor_alert": 1,
"sensor_custom": "No",
"entPhysicalIndex": null,
"entPhysicalIndex_measured": null,
"sensor_oids": "[\".\"]"
}
]
}
-70
View File
@@ -19,75 +19,5 @@
]
},
"poller": "matches discovery"
},
"wireless": {
"discovery": {
"wireless_sensors": [
{
"sensor_deleted": 0,
"sensor_class": "utilization",
"sensor_index": "",
"sensor_type": "arubaos-iap",
"sensor_descr": "Radio ",
"sensor_divisor": 1,
"sensor_multiplier": 1,
"sensor_aggregator": "sum",
"sensor_current": 0,
"sensor_prev": null,
"sensor_limit": null,
"sensor_limit_warn": null,
"sensor_limit_low": null,
"sensor_limit_low_warn": null,
"sensor_alert": 1,
"sensor_custom": "No",
"entPhysicalIndex": null,
"entPhysicalIndex_measured": null,
"sensor_oids": "[\".\"]"
},
{
"sensor_deleted": 0,
"sensor_class": "power",
"sensor_index": "",
"sensor_type": "arubaos-iap",
"sensor_descr": "Radio : Tx Power",
"sensor_divisor": 1,
"sensor_multiplier": 1,
"sensor_aggregator": "sum",
"sensor_current": 0,
"sensor_prev": null,
"sensor_limit": null,
"sensor_limit_warn": null,
"sensor_limit_low": null,
"sensor_limit_low_warn": null,
"sensor_alert": 1,
"sensor_custom": "No",
"entPhysicalIndex": null,
"entPhysicalIndex_measured": null,
"sensor_oids": "[\".\"]"
},
{
"sensor_deleted": 0,
"sensor_class": "noise-floor",
"sensor_index": "",
"sensor_type": "arubaos-iap",
"sensor_descr": "Radio ",
"sensor_divisor": 1,
"sensor_multiplier": 1,
"sensor_aggregator": "sum",
"sensor_current": 0,
"sensor_prev": null,
"sensor_limit": null,
"sensor_limit_warn": null,
"sensor_limit_low": null,
"sensor_limit_low_warn": null,
"sensor_alert": 1,
"sensor_custom": "No",
"entPhysicalIndex": null,
"entPhysicalIndex_measured": null,
"sensor_oids": "[\".\"]"
}
]
},
"poller": "matches discovery"
}
}
-70
View File
@@ -152,75 +152,5 @@
]
},
"poller": "matches discovery"
},
"wireless": {
"discovery": {
"wireless_sensors": [
{
"sensor_deleted": 0,
"sensor_class": "utilization",
"sensor_index": "",
"sensor_type": "arubaos-iap",
"sensor_descr": "Radio ",
"sensor_divisor": 1,
"sensor_multiplier": 1,
"sensor_aggregator": "sum",
"sensor_current": 0,
"sensor_prev": null,
"sensor_limit": null,
"sensor_limit_warn": null,
"sensor_limit_low": null,
"sensor_limit_low_warn": null,
"sensor_alert": 1,
"sensor_custom": "No",
"entPhysicalIndex": null,
"entPhysicalIndex_measured": null,
"sensor_oids": "[\".\"]"
},
{
"sensor_deleted": 0,
"sensor_class": "power",
"sensor_index": "",
"sensor_type": "arubaos-iap",
"sensor_descr": "Radio : Tx Power",
"sensor_divisor": 1,
"sensor_multiplier": 1,
"sensor_aggregator": "sum",
"sensor_current": 0,
"sensor_prev": null,
"sensor_limit": null,
"sensor_limit_warn": null,
"sensor_limit_low": null,
"sensor_limit_low_warn": null,
"sensor_alert": 1,
"sensor_custom": "No",
"entPhysicalIndex": null,
"entPhysicalIndex_measured": null,
"sensor_oids": "[\".\"]"
},
{
"sensor_deleted": 0,
"sensor_class": "noise-floor",
"sensor_index": "",
"sensor_type": "arubaos-iap",
"sensor_descr": "Radio ",
"sensor_divisor": 1,
"sensor_multiplier": 1,
"sensor_aggregator": "sum",
"sensor_current": 0,
"sensor_prev": null,
"sensor_limit": null,
"sensor_limit_warn": null,
"sensor_limit_low": null,
"sensor_limit_low_warn": null,
"sensor_alert": 1,
"sensor_custom": "No",
"entPhysicalIndex": null,
"entPhysicalIndex_measured": null,
"sensor_oids": "[\".\"]"
}
]
},
"poller": "matches discovery"
}
}
-70
View File
@@ -19,75 +19,5 @@
]
},
"poller": "matches discovery"
},
"wireless": {
"discovery": {
"wireless_sensors": [
{
"sensor_deleted": 0,
"sensor_class": "utilization",
"sensor_index": "",
"sensor_type": "arubaos-iap",
"sensor_descr": "Radio ",
"sensor_divisor": 1,
"sensor_multiplier": 1,
"sensor_aggregator": "sum",
"sensor_current": 0,
"sensor_prev": null,
"sensor_limit": null,
"sensor_limit_warn": null,
"sensor_limit_low": null,
"sensor_limit_low_warn": null,
"sensor_alert": 1,
"sensor_custom": "No",
"entPhysicalIndex": null,
"entPhysicalIndex_measured": null,
"sensor_oids": "[\".\"]"
},
{
"sensor_deleted": 0,
"sensor_class": "power",
"sensor_index": "",
"sensor_type": "arubaos-iap",
"sensor_descr": "Radio : Tx Power",
"sensor_divisor": 1,
"sensor_multiplier": 1,
"sensor_aggregator": "sum",
"sensor_current": 0,
"sensor_prev": null,
"sensor_limit": null,
"sensor_limit_warn": null,
"sensor_limit_low": null,
"sensor_limit_low_warn": null,
"sensor_alert": 1,
"sensor_custom": "No",
"entPhysicalIndex": null,
"entPhysicalIndex_measured": null,
"sensor_oids": "[\".\"]"
},
{
"sensor_deleted": 0,
"sensor_class": "noise-floor",
"sensor_index": "",
"sensor_type": "arubaos-iap",
"sensor_descr": "Radio ",
"sensor_divisor": 1,
"sensor_multiplier": 1,
"sensor_aggregator": "sum",
"sensor_current": 0,
"sensor_prev": null,
"sensor_limit": null,
"sensor_limit_warn": null,
"sensor_limit_low": null,
"sensor_limit_low_warn": null,
"sensor_alert": 1,
"sensor_custom": "No",
"entPhysicalIndex": null,
"entPhysicalIndex_measured": null,
"sensor_oids": "[\".\"]"
}
]
},
"poller": "matches discovery"
}
}
-31
View File
@@ -48,36 +48,5 @@
]
},
"poller": "matches discovery"
},
"sensors": {
"discovery": {
"sensors": [
{
"sensor_deleted": 0,
"sensor_class": "temperature",
"poller_type": "snmp",
"sensor_oid": "",
"sensor_index": "01",
"sensor_type": "avaya-ers",
"sensor_descr": "Unit 1 temperature",
"group": null,
"sensor_divisor": 2,
"sensor_multiplier": 1,
"sensor_current": 0,
"sensor_limit": 20,
"sensor_limit_warn": null,
"sensor_limit_low": -10,
"sensor_limit_low_warn": null,
"sensor_alert": 1,
"sensor_custom": "No",
"entPhysicalIndex": null,
"entPhysicalIndex_measured": null,
"sensor_prev": null,
"user_func": null,
"state_name": null
}
]
},
"poller": "matches discovery"
}
}
-52
View File
@@ -14063,57 +14063,5 @@
}
]
}
},
"wireless": {
"discovery": {
"wireless_sensors": [
{
"sensor_deleted": 0,
"sensor_class": "clients",
"sensor_index": "total-clients",
"sensor_type": "stellar",
"sensor_descr": "Total Clients",
"sensor_divisor": 1,
"sensor_multiplier": 1,
"sensor_aggregator": "sum",
"sensor_current": 0,
"sensor_prev": null,
"sensor_limit": null,
"sensor_limit_warn": null,
"sensor_limit_low": null,
"sensor_limit_low_warn": null,
"sensor_alert": 1,
"sensor_custom": "No",
"entPhysicalIndex": null,
"entPhysicalIndex_measured": null,
"sensor_oids": "[\".\"]"
}
]
},
"poller": {
"wireless_sensors": [
{
"sensor_deleted": 0,
"sensor_class": "clients",
"sensor_index": "total-clients",
"sensor_type": "stellar",
"sensor_descr": "Total Clients",
"sensor_divisor": 1,
"sensor_multiplier": 1,
"sensor_aggregator": "sum",
"sensor_current": 2,
"sensor_prev": 0,
"sensor_limit": null,
"sensor_limit_warn": null,
"sensor_limit_low": null,
"sensor_limit_low_warn": null,
"sensor_alert": 1,
"sensor_custom": "No",
"entPhysicalIndex": null,
"entPhysicalIndex_measured": null,
"sensor_oids": "[\".\"]"
}
]
}
}
}