mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
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:
@@ -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
|
||||
*/
|
||||
|
@@ -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
|
||||
*/
|
||||
|
Reference in New Issue
Block a user