From c0d7ad44b046c85532d7ce610d3e981875e0ce98 Mon Sep 17 00:00:00 2001 From: Neil Lathwood Date: Fri, 7 Oct 2016 09:26:10 +0100 Subject: [PATCH] Revert "refactor: snmp cleanup" (#4746) --- includes/common.php | 24 -- .../discovery/sensors/states/ibm-amm.inc.php | 3 +- includes/polling/aruba-controller.inc.php | 20 +- .../polling/cisco-voice/cisco-iosdsp.inc.php | 4 +- .../polling/cisco-voice/cisco-iosmtp.inc.php | 5 +- .../polling/cisco-voice/cisco-iospri.inc.php | 5 +- .../cisco-voice/cisco-iosxcode.inc.php | 5 +- includes/polling/test.inc.php | 5 + includes/snmp.inc.php | 242 +++++++++++++----- 9 files changed, 199 insertions(+), 114 deletions(-) create mode 100644 includes/polling/test.inc.php diff --git a/includes/common.php b/includes/common.php index b7f8a58dee..b7229f43cb 100644 --- a/includes/common.php +++ b/includes/common.php @@ -1461,30 +1461,6 @@ function starts_with($haystack, $needles, $case_insensitive = false) return false; } -/** - * Search backwards for the $needle, returning $count found occurrence - * - * @param string $haystack - * @param string $needle - * @param int $count - * @return bool|int - */ -function strrpos_count($haystack, $needle, $count = 1) -{ - if ($count <= 0) { - return false; - } - - $len = strlen($haystack); - $pos = $len; - - for ($i = 0; $i < $count && $pos; $i++) { - $pos = strrpos($haystack, $needle, $pos - $len - 1); - } - - return $pos; -} - function get_auth_ad_user_filter($username) { global $config; diff --git a/includes/discovery/sensors/states/ibm-amm.inc.php b/includes/discovery/sensors/states/ibm-amm.inc.php index 43282c2fd1..37f851ce22 100644 --- a/includes/discovery/sensors/states/ibm-amm.inc.php +++ b/includes/discovery/sensors/states/ibm-amm.inc.php @@ -126,7 +126,8 @@ if ($device['os'] == 'ibm-amm') { * notAvailable(3), * critical(4) */ - foreach ($data as $oid => $state) { + foreach ($data as $oid => $array) { + $state = current($array); // get the first (and only) item from the array $descr = $state_descr . $index; if (is_numeric($state) && $state != 3) { diff --git a/includes/polling/aruba-controller.inc.php b/includes/polling/aruba-controller.inc.php index 988f791944..32462d45a2 100644 --- a/includes/polling/aruba-controller.inc.php +++ b/includes/polling/aruba-controller.inc.php @@ -81,16 +81,16 @@ if ($device['type'] == 'wireless' && $device['os'] == 'arubaos') { foreach ($aruba_apnames as $key => $value) { $radioid = str_replace('1.3.6.1.4.1.14823.2.2.1.5.2.1.5.1.16.', '', $key); - $name = $value; - $type = $aruba_apstats["1.3.6.1.4.1.14823.2.2.1.5.2.1.5.1.2.$radioid"]; - $channel = ($aruba_apstats["1.3.6.1.4.1.14823.2.2.1.5.2.1.5.1.3.$radioid"] + 0); - $txpow = ($aruba_apstats["1.3.6.1.4.1.14823.2.2.1.5.2.1.5.1.4.$radioid"] + 0); - $radioutil = ($aruba_apstats["1.3.6.1.4.1.14823.2.2.1.5.2.1.5.1.6.$radioid"] + 0); - $numasoclients = ($aruba_apstats["1.3.6.1.4.1.14823.2.2.1.5.2.1.5.1.7.$radioid"] + 0); - $nummonclients = ($aruba_apstats["1.3.6.1.4.1.14823.2.2.1.5.2.1.5.1.8.$radioid"] + 0); - $numactbssid = ($aruba_apstats["1.3.6.1.4.1.14823.2.2.1.5.2.1.5.1.9.$radioid"] + 0); - $nummonbssid = ($aruba_apstats["1.3.6.1.4.1.14823.2.2.1.5.2.1.5.1.10.$radioid"] + 0); - $interference = ($aruba_apstats["1.3.6.1.4.1.14823.2.2.1.5.3.1.6.1.11.$radioid"] + 0); + $name = $value['']; + $type = $aruba_apstats["1.3.6.1.4.1.14823.2.2.1.5.2.1.5.1.2.$radioid"]['']; + $channel = ($aruba_apstats["1.3.6.1.4.1.14823.2.2.1.5.2.1.5.1.3.$radioid"][''] + 0); + $txpow = ($aruba_apstats["1.3.6.1.4.1.14823.2.2.1.5.2.1.5.1.4.$radioid"][''] + 0); + $radioutil = ($aruba_apstats["1.3.6.1.4.1.14823.2.2.1.5.2.1.5.1.6.$radioid"][''] + 0); + $numasoclients = ($aruba_apstats["1.3.6.1.4.1.14823.2.2.1.5.2.1.5.1.7.$radioid"][''] + 0); + $nummonclients = ($aruba_apstats["1.3.6.1.4.1.14823.2.2.1.5.2.1.5.1.8.$radioid"][''] + 0); + $numactbssid = ($aruba_apstats["1.3.6.1.4.1.14823.2.2.1.5.2.1.5.1.9.$radioid"][''] + 0); + $nummonbssid = ($aruba_apstats["1.3.6.1.4.1.14823.2.2.1.5.2.1.5.1.10.$radioid"][''] + 0); + $interference = ($aruba_apstats["1.3.6.1.4.1.14823.2.2.1.5.3.1.6.1.11.$radioid"][''] + 0); $radionum = substr($radioid, (strlen($radioid) - 1), 1); diff --git a/includes/polling/cisco-voice/cisco-iosdsp.inc.php b/includes/polling/cisco-voice/cisco-iosdsp.inc.php index f1d40e2166..ea17b18ebb 100644 --- a/includes/polling/cisco-voice/cisco-iosdsp.inc.php +++ b/includes/polling/cisco-voice/cisco-iosdsp.inc.php @@ -15,14 +15,14 @@ if ($device['os_group'] == "cisco") { // Total $total = 0; foreach (snmpwalk_cache_oid_num($device, "1.3.6.1.4.1.9.9.86.1.2.1.1.6", null) as $key => $value) { - $total += $value; + $total += $value['']; } if (isset($total) && ($total != "") && ($total != 0)) { // Active $active = 0; foreach (snmpwalk_cache_oid_num($device, "1.3.6.1.4.1.9.9.86.1.2.1.1.7", null) as $key => $value) { - $active += $value; + $active += $value['']; } $rrd_def = array( diff --git a/includes/polling/cisco-voice/cisco-iosmtp.inc.php b/includes/polling/cisco-voice/cisco-iosmtp.inc.php index 2b9f7e1999..3884da6508 100644 --- a/includes/polling/cisco-voice/cisco-iosmtp.inc.php +++ b/includes/polling/cisco-voice/cisco-iosmtp.inc.php @@ -14,13 +14,12 @@ if ($device['os_group'] == "cisco") { // Total $total = snmpwalk_cache_oid_num($device, "1.3.6.1.4.1.9.9.86.1.6.4.1.3", null); - $total = $total['1.3.6.1.4.1.9.9.86.1.6.4.1.3']; - // FIXME why isn't this using an snmpget? + $total = $total['1.3.6.1.4.1.9.9.86.1.6.4.1.3']['']; if (isset($total) && ($total != "") && ($total != 0)) { // Available $available = snmpwalk_cache_oid_num($device, "1.3.6.1.4.1.9.9.86.1.6.4.1.4", null); - $available = $available['1.3.6.1.4.1.9.9.86.1.6.4.1.4']; + $available = $available['1.3.6.1.4.1.9.9.86.1.6.4.1.4']['']; // Active $active = $total - $available; diff --git a/includes/polling/cisco-voice/cisco-iospri.inc.php b/includes/polling/cisco-voice/cisco-iospri.inc.php index 50772094a1..24fede3b6d 100644 --- a/includes/polling/cisco-voice/cisco-iospri.inc.php +++ b/includes/polling/cisco-voice/cisco-iospri.inc.php @@ -18,15 +18,14 @@ if ($device['os_group'] == "cisco") { $total = 0; foreach (snmpwalk_cache_oid_num($device, "1.3.6.1.2.1.2.2.1.3", null) as $key => $value) { // 81 is the ifType for DS0's - if ($value == "81") { + if ($value[''] == "81") { $total++; } } // Active $active = snmpwalk_cache_oid_num($device, "1.3.6.1.4.1.9.10.19.1.1.4.0", null); - $active = $active['1.3.6.1.4.1.9.10.19.1.1.4.0']; - // FIXME why isn't this using snmpget? + $active = $active['1.3.6.1.4.1.9.10.19.1.1.4.0']['']; if (isset($active) && ($active != "") && ($total != 0)) { $rrd_def = array( diff --git a/includes/polling/cisco-voice/cisco-iosxcode.inc.php b/includes/polling/cisco-voice/cisco-iosxcode.inc.php index 5d2478a107..bc83ce7a37 100644 --- a/includes/polling/cisco-voice/cisco-iosxcode.inc.php +++ b/includes/polling/cisco-voice/cisco-iosxcode.inc.php @@ -14,13 +14,12 @@ if ($device['os_group'] == "cisco") { // Total $total = snmpwalk_cache_oid_num($device, "1.3.6.1.4.1.9.9.86.1.7.1.0", null); - $total = $total['1.3.6.1.4.1.9.9.86.1.7.1.0']; - // FIXME why isn't this using snmpget? + $total = $total['1.3.6.1.4.1.9.9.86.1.7.1.0']['']; if (isset($total) && ($total != "") && ($total != 0)) { // Available $available = snmpwalk_cache_oid_num($device, "1.3.6.1.4.1.9.9.86.1.7.2.0", null); - $available = $available['1.3.6.1.4.1.9.9.86.1.7.2.0']; + $available = $available['1.3.6.1.4.1.9.9.86.1.7.2.0']['']; // Active $active = $total - $available; diff --git a/includes/polling/test.inc.php b/includes/polling/test.inc.php new file mode 100644 index 0000000000..3cfa2b173b --- /dev/null +++ b/includes/polling/test.inc.php @@ -0,0 +1,5 @@ +