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:
@@ -128,7 +128,7 @@ function gen_snmpget_cmd($device, $oids, $options = null, $mib = null, $mibdir =
|
||||
* @param string $mibdir a mib directory to search for mibs, usually prepended with +
|
||||
* @return array the fully assembled command, ready to run
|
||||
*/
|
||||
function gen_snmpwalk_cmd($device, $oids, $options = null, $mib = null, $mibdir = null, $strIndexing = null)
|
||||
function gen_snmpwalk_cmd($device, $oids, $options = null, $mib = null, $mibdir = null)
|
||||
{
|
||||
if ($device['snmpver'] == 'v1' || (isset($device['os']) && Config::getOsSetting($device['os'], 'snmp_bulk', true) == false)) {
|
||||
$snmpcmd = [Config::get('snmpwalk')];
|
||||
@@ -140,7 +140,7 @@ function gen_snmpwalk_cmd($device, $oids, $options = null, $mib = null, $mibdir
|
||||
}
|
||||
}
|
||||
|
||||
return gen_snmp_cmd($snmpcmd, $device, $oids, $options, $mib, $mibdir, $strIndexing);
|
||||
return gen_snmp_cmd($snmpcmd, $device, $oids, $options, $mib, $mibdir);
|
||||
} //end gen_snmpwalk_cmd()
|
||||
|
||||
/**
|
||||
@@ -154,13 +154,13 @@ function gen_snmpwalk_cmd($device, $oids, $options = null, $mib = null, $mibdir
|
||||
* @param string $mibdir a mib directory to search for mibs, usually prepended with +
|
||||
* @return array the fully assembled command, ready to run
|
||||
*/
|
||||
function gen_snmp_cmd($cmd, $device, $oids, $options = null, $mib = null, $mibdir = null, $strIndexing = null)
|
||||
function gen_snmp_cmd($cmd, $device, $oids, $options = null, $mib = null, $mibdir = null)
|
||||
{
|
||||
if (! isset($device['transport'])) {
|
||||
$device['transport'] = 'udp';
|
||||
}
|
||||
|
||||
$cmd = snmp_gen_auth($device, $cmd, $strIndexing);
|
||||
$cmd = snmp_gen_auth($device, $cmd);
|
||||
$cmd = $options ? array_merge($cmd, (array) $options) : $cmd;
|
||||
if ($mib) {
|
||||
array_push($cmd, '-m', $mib);
|
||||
@@ -653,10 +653,9 @@ function snmpwalk_cache_triple_oid($device, $oid, $array, $mib = null, $mibdir =
|
||||
* @param mixed $snmpFlags flags to use for the snmp command
|
||||
* @return array grouped array of data
|
||||
*/
|
||||
function snmpwalk_group($device, $oid, $mib = '', $depth = 1, $array = [], $mibdir = null, $strIndexing = null, $snmpFlags = '-OQUsetX')
|
||||
function snmpwalk_group($device, $oid, $mib = '', $depth = 1, $array = [], $mibdir = null, $snmpFlags = '-OQUsetX')
|
||||
{
|
||||
d_echo("communityStringIndexing $strIndexing\n");
|
||||
$cmd = gen_snmpwalk_cmd($device, $oid, $snmpFlags, $mib, $mibdir, $strIndexing);
|
||||
$cmd = gen_snmpwalk_cmd($device, $oid, $snmpFlags, $mib, $mibdir);
|
||||
$data = rtrim(external_exec($cmd));
|
||||
|
||||
$line = strtok($data, "\n");
|
||||
@@ -740,7 +739,7 @@ function snmpwalk_cache_threepart_oid($device, $oid, $array, $mib = 0)
|
||||
* @param array $cmd
|
||||
* @return array
|
||||
*/
|
||||
function snmp_gen_auth(&$device, $cmd = [], $strIndexing = null)
|
||||
function snmp_gen_auth(&$device, $cmd = [])
|
||||
{
|
||||
if ($device['snmpver'] === 'v3') {
|
||||
array_push($cmd, '-v3', '-l', $device['authlevel']);
|
||||
@@ -764,7 +763,7 @@ function snmp_gen_auth(&$device, $cmd = [], $strIndexing = null)
|
||||
d_echo('DEBUG: ' . $device['snmpver'] . " : Unsupported SNMPv3 AuthLevel (wtf have you done ?)\n");
|
||||
}
|
||||
} elseif ($device['snmpver'] === 'v2c' || $device['snmpver'] === 'v1') {
|
||||
array_push($cmd, '-' . $device['snmpver'], '-c', $device['community'] . ($strIndexing != null ? '@' . $strIndexing : null));
|
||||
array_push($cmd, '-' . $device['snmpver'], '-c', $device['community']);
|
||||
} else {
|
||||
d_echo('DEBUG: ' . $device['snmpver'] . " : Unsupported SNMP Version (shouldn't be possible to get here)\n");
|
||||
}
|
||||
|
Reference in New Issue
Block a user