Fix bad snmp context option (#13497)

* Fix bad snmp context option
Just port queries to SnmpQuery and remove bad code to prevent new usages

* Allow unordered

* add stub on Mock
This commit is contained in:
Tony Murray
2021-11-12 12:40:37 -06:00
committed by GitHub
parent 6b41c29f5f
commit 666638eeaa
7 changed files with 50 additions and 30 deletions

View File

@@ -130,10 +130,14 @@ class NetSnmpQuery implements SnmpQueryInterface
/**
* Set a context for the snmp query
* This is most commonly used to fetch alternate sets of data, such as different VRFs
*
* @param string $v2 Version 2/3 context name
* @param string|null $v3 Version 3 context name if different from v2 context name
* @return \LibreNMS\Data\Source\SnmpQueryInterface
*/
public function context(string $context): SnmpQueryInterface
public function context(string $v2, string $v3 = null): SnmpQueryInterface
{
$this->context = $context;
$this->context = $this->device->snmpver === 'v3' && $v3 !== null ? $v3 : $v2;
return $this;
}
@@ -149,6 +153,17 @@ class NetSnmpQuery implements SnmpQueryInterface
return $this;
}
/**
* Do not error on out of order indexes.
* Use with caution as we could get stuck in an infinite loop.
*/
public function allowUnordered(): SnmpQueryInterface
{
$this->options = array_merge($this->options, ['-Cc']);
return $this;
}
/**
* Output all OIDs numerically
*/

View File

@@ -58,6 +58,12 @@ interface SnmpQueryInterface
*/
public function mibDir(?string $dir): SnmpQueryInterface;
/**
* Do not error on out of order indexes.
* Use with caution as we could get stuck in an infinite loop.
*/
public function allowUnordered(): SnmpQueryInterface;
/**
* Output all OIDs numerically
*/