From c78f92a4c24cb7ee44de6ca9a0bbc64113b30e87 Mon Sep 17 00:00:00 2001 From: Alan Gregory Date: Wed, 21 Nov 2018 17:25:39 -0200 Subject: [PATCH] snmp_max_oid per Os support and snmpv1 multi_oid fix (#9343) * Added snmp_max_oid config at Os level. * Added check for snmpv1 on multi_oid requests. * Check device_oid_limit on multi get * Use array_chunk * Update snmp.inc.php * remove dump, unused variable and extra plodes * per device settings should take priority over OS * Update Settings.md * don't discard the data :P --- doc/Developing/os/Settings.md | 25 ++++++++++++++++--------- includes/functions.php | 23 +++++++++++++---------- includes/snmp.inc.php | 18 +++++++++++++----- misc/os_schema.json | 3 +++ 4 files changed, 45 insertions(+), 24 deletions(-) diff --git a/doc/Developing/os/Settings.md b/doc/Developing/os/Settings.md index 5bc37d49f1..c2dda3223f 100644 --- a/doc/Developing/os/Settings.md +++ b/doc/Developing/os/Settings.md @@ -47,14 +47,6 @@ ifalias: true ifindex: true ``` -### Disable snmpbulkwalk -Some devices have buggy snmp implementations and don't respond well to the more efficient snmpbulkwalk. -To disable snmpbulkwalk and only use snmpwalk for an os set the following. - -```yaml -nobulk: true -``` - ### Poller and Discovery Modules The various discovery and poller modules can be enabled or disabled per OS. The defaults are usually reasonable, so likely you won't want to change more than a few. These modules can be enabled or disabled per-device in the webui and per os or globally in config.php. @@ -67,11 +59,26 @@ discovery_modules: arp-table: false ``` +### SNMP Settings + +#### Disable snmpbulkwalk +Some devices have buggy snmp implementations and don't respond well to the more efficient snmpbulkwalk. +To disable snmpbulkwalk and only use snmpwalk for an os set the following. + +```yaml +nobulk: true +``` + +#### Limit the oids per snmpget +```yaml +snmp_max_oid: 8 +``` + ### Storage Settings See also: [Global Storage Config](../../Support/Configuration.md#storage-configuration) ```yaml -ignore_mount array: # exact match +ignore_mount_array: # exact match - /var/run ignore_mount_string: # substring - run diff --git a/includes/functions.php b/includes/functions.php index da5819a0c1..9f4cc70d8c 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -2497,17 +2497,20 @@ function db_schema_is_current() */ function get_device_oid_limit($device) { - global $config; - - $max_oid = $device['snmp_max_oid']; - - if (isset($max_oid) && $max_oid > 0) { - return $max_oid; - } elseif (isset($config['snmp']['max_oid']) && $config['snmp']['max_oid'] > 0) { - return $config['snmp']['max_oid']; - } else { - return 10; + // device takes priority + if ($device['snmp_max_oid'] > 0) { + return $device['snmp_max_oid']; } + + // then os + $os_max = Config::getOsSetting($device['os'], 'snmp_max_oid', 0); + if ($os_max > 0) { + return $os_max; + } + + // then global + $global_max = Config::get('snmp.max_oid', 10); + return $global_max > 0 ? $global_max : 10; } /** diff --git a/includes/snmp.inc.php b/includes/snmp.inc.php index 6b854015c2..6430455f01 100644 --- a/includes/snmp.inc.php +++ b/includes/snmp.inc.php @@ -221,17 +221,25 @@ function snmp_get_multi($device, $oids, $options = '-OQUs', $mib = null, $mibdir function snmp_get_multi_oid($device, $oids, $options = '-OUQn', $mib = null, $mibdir = null) { $time_start = microtime(true); + $oid_limit = get_device_oid_limit($device); - if (is_array($oids)) { - $oids = implode(' ', $oids); + if (!is_array($oids)) { + $oids = explode(" ", $oids); } - $cmd = gen_snmpget_cmd($device, $oids, $options, $mib, $mibdir); - $data = trim(external_exec($cmd)); + $data = []; + foreach (array_chunk($oids, $oid_limit) as $chunk) { + $partial_oids = implode(' ', $chunk); + $cmd = gen_snmpget_cmd($device, $partial_oids, $options, $mib, $mibdir); + $result = trim(external_exec($cmd)); + if ($result) { + $data = array_merge($data, explode("\n", $result)); + } + } $array = array(); $oid = ''; - foreach (explode("\n", $data) as $entry) { + foreach ($data as $entry) { if (str_contains($entry, '=')) { list($oid,$value) = explode('=', $entry, 2); $oid = trim($oid); diff --git a/misc/os_schema.json b/misc/os_schema.json index 258cf23b85..10b9a18209 100644 --- a/misc/os_schema.json +++ b/misc/os_schema.json @@ -339,6 +339,9 @@ "nobulk": { "type": "boolean" }, + "snmp_max_oid": { + "type": "string" + }, "ifXmcbc": { "type": "boolean" },