diff --git a/LibreNMS/Data/Source/NetSnmpQuery.php b/LibreNMS/Data/Source/NetSnmpQuery.php index 7f7eb71352..d170fce297 100644 --- a/LibreNMS/Data/Source/NetSnmpQuery.php +++ b/LibreNMS/Data/Source/NetSnmpQuery.php @@ -250,11 +250,7 @@ class NetSnmpQuery implements SnmpQueryInterface */ public function get($oid): SnmpResponse { - if (empty($oid)) { - return new SnmpResponse(''); - } - - return $this->exec('snmpget', $this->parseOid($oid)); + return $this->execMultiple('snmpget', $this->limitOids($this->parseOid($oid))); } /** @@ -278,7 +274,7 @@ class NetSnmpQuery implements SnmpQueryInterface */ public function next($oid): SnmpResponse { - return $this->exec('snmpgetnext', $this->parseOid($oid)); + return $this->execMultiple('snmpgetnext', $this->limitOids($this->parseOid($oid))); } /** @@ -374,7 +370,7 @@ class NetSnmpQuery implements SnmpQueryInterface $response = new SnmpResponse(''); foreach ($oids as $oid) { - $response = $response->append($this->exec($command, [$oid])); + $response = $response->append($this->exec($command, Arr::wrap($oid))); // if abort on failure is set, return after first failure if ($this->abort && ! $response->isValid()) { @@ -500,10 +496,20 @@ class NetSnmpQuery implements SnmpQueryInterface Log::debug($error); } - /** - * @param array|string $oid - */ - private function parseOid($oid): array + private function limitOids(array $oids): array + { + // get max oids per query device attrib > os setting > global setting + $configured_max = $this->device->getAttrib('snmp_max_oid') ?: Config::getOsSetting($this->device->os, 'snmp_max_oid', Config::get('snmp.max_oid', 10)); + $max_oids = max($configured_max, 1); // 0 or less would break things. + + if (count($oids) > $max_oids) { + return array_chunk($oids, $max_oids); + } + + return $oids; + } + + private function parseOid(array|string $oid): array { return is_string($oid) ? explode(' ', $oid) : $oid; } diff --git a/includes/definitions/hpe-mapdu.yaml b/includes/definitions/hpe-mapdu.yaml index 34bb067b86..2a3b4241fa 100644 --- a/includes/definitions/hpe-mapdu.yaml +++ b/includes/definitions/hpe-mapdu.yaml @@ -5,9 +5,9 @@ icon: hpe group: hpe mib_dir: hp over: - - {graph: device_power, text: Power} + - {graph: device_power, text: Power} - {graph: device_current, text: Current} -snmp_max_oid: '8' +snmp_max_oid: 8 discovery: - sysObjectID: diff --git a/includes/definitions/tait-tnadmin.yaml b/includes/definitions/tait-tnadmin.yaml index 611ed57672..270e295620 100644 --- a/includes/definitions/tait-tnadmin.yaml +++ b/includes/definitions/tait-tnadmin.yaml @@ -3,7 +3,7 @@ text: 'Tait TN Admin OS' type: network icon: tait mib_dir: tait -snmp_max_oid: '1' +snmp_max_oid: 1 over: - { graph: device_temperature, text: 'Temperature' } discovery: diff --git a/misc/config_definitions.json b/misc/config_definitions.json index f27c563d96..e3cd744178 100644 --- a/misc/config_definitions.json +++ b/misc/config_definitions.json @@ -5280,6 +5280,13 @@ "type": "integer", "units": "seconds" }, + "snmp.max_oid": { + "group": "poller", + "section": "snmp", + "order": 5, + "type": "integer", + "default": 10 + }, "snmp.max_repeaters": { "group": "poller", "section": "snmp", diff --git a/misc/os_schema.json b/misc/os_schema.json index 0341dd7796..6fcebd968d 100644 --- a/misc/os_schema.json +++ b/misc/os_schema.json @@ -391,7 +391,8 @@ "type": "boolean" }, "snmp_max_oid": { - "type": "string" + "type": "integer", + "minimum": 1 }, "ifXmcbc": { "type": "boolean" diff --git a/resources/lang/en/settings.php b/resources/lang/en/settings.php index 2c077843a6..6750e1e568 100644 --- a/resources/lang/en/settings.php +++ b/resources/lang/en/settings.php @@ -1413,6 +1413,10 @@ return [ 'description' => 'Communities (priority)', 'help' => 'Enter community strings for v1 and v2c and order them as you want them to be tried', ], + 'max_oid' => [ + 'description' => 'Max OIDs', + 'help' => 'Maximum OIDs per query. Can be overriden at OS and device levels.', + ], 'max_repeaters' => [ 'description' => 'Max Repeaters', 'help' => 'Set repeaters to use for SNMP bulk requests',