mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
SnmpQuery updates and more tests (#13359)
* SnmpQuery updates and more tests improvements to translate handling * fix method description * fix whitespace
This commit is contained in:
@@ -217,14 +217,19 @@ class SnmpQuery
|
||||
|
||||
/**
|
||||
* Translate an OID.
|
||||
* Specify -On option to output numeric OID.
|
||||
* call numeric() on the query to output numeric OID
|
||||
*
|
||||
* @param array|string $oid
|
||||
* @param string $oid
|
||||
* @return \LibreNMS\Data\Source\SnmpResponse
|
||||
*/
|
||||
public function translate($oid): SnmpResponse
|
||||
public function translate(string $oid, ?string $mib = null): SnmpResponse
|
||||
{
|
||||
return $this->exec('snmptranslate', $this->parseOid($oid));
|
||||
if ($mib) {
|
||||
$this->options = array_merge($this->options, ['-m', $mib]);
|
||||
}
|
||||
|
||||
return $this->exec('snmptranslate', [$oid]);
|
||||
}
|
||||
|
||||
private function buildCli(string $command, array $oids): array
|
||||
|
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
/*
|
||||
/**
|
||||
* SnmpResponse.php
|
||||
*
|
||||
* Responsible for parsing net-snmp output into usable PHP data structures.
|
||||
@@ -15,10 +15,10 @@
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @link https://www.librenms.org
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @link http://librenms.org
|
||||
* @copyright 2021 Tony Murray
|
||||
* @author Tony Murray <murraytony@gmail.com>
|
||||
*/
|
||||
@@ -31,7 +31,7 @@ use Log;
|
||||
|
||||
class SnmpResponse
|
||||
{
|
||||
const DELIMITER = ' = ';
|
||||
protected const DELIMITER = ' = ';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
@@ -117,7 +117,11 @@ class SnmpResponse
|
||||
continue;
|
||||
}
|
||||
|
||||
[$oid, $value] = explode(self::DELIMITER, $line, 2);
|
||||
$parts = explode(self::DELIMITER, $line, 2);
|
||||
if (count($parts) == 1) {
|
||||
array_unshift($parts, '');
|
||||
}
|
||||
[$oid, $value] = $parts;
|
||||
|
||||
$line = strtok(PHP_EOL); // get the next line and concatenate multi-line values
|
||||
while ($line !== false && ! Str::contains($line, self::DELIMITER)) {
|
||||
@@ -125,7 +129,7 @@ class SnmpResponse
|
||||
$line = strtok(PHP_EOL);
|
||||
}
|
||||
|
||||
$values[$oid] = $value;
|
||||
$values[$oid] = trim($value, "\\\" \n\r");
|
||||
}
|
||||
|
||||
return $values;
|
||||
@@ -147,7 +151,7 @@ class SnmpResponse
|
||||
$tmp = $value; // assign the value as the leaf
|
||||
}
|
||||
|
||||
return $array;
|
||||
return Arr::wrap($array); // if no parts, wrap the value
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user