mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Escape net-snmp unformatted strings, try 2 (#13584)
* Escape net-snmp unformatted strings, try 2 * Add some tests
This commit is contained in:
@@ -132,7 +132,7 @@ class SnmpResponse
|
||||
|
||||
if (Str::startsWith($value, '"') && Str::endsWith($value, '"')) {
|
||||
// unformatted string from net-snmp, remove extra escapes
|
||||
$values[$oid] = stripslashes(trim($value, "\\\" \n\r"));
|
||||
$values[$oid] = trim(stripslashes($value), "\" \n\r");
|
||||
} else {
|
||||
$values[$oid] = trim($value);
|
||||
}
|
||||
|
@@ -46,7 +46,7 @@ class SnmpFetch extends LnmsCommand
|
||||
$spec = $this->argument('device spec');
|
||||
$device_ids = Device::query()->when($spec !== 'all', function (Builder $query) use ($spec) {
|
||||
return $query->where('device_id', $spec)
|
||||
->orWhere('hostname', 'regexp', $spec);
|
||||
->orWhere('hostname', 'regexp', "^$spec$");
|
||||
})->pluck('device_id');
|
||||
|
||||
if ($device_ids->isEmpty()) {
|
||||
|
@@ -47,6 +47,13 @@ class SnmpResponseTest extends TestCase
|
||||
$this->assertEquals(['' => 'IF-MIB::ifDescr'], $response->values());
|
||||
$this->assertEquals('IF-MIB::ifDescr', $response->value());
|
||||
$this->assertEquals(['IF-MIB::ifDescr'], $response->table());
|
||||
|
||||
// unescaped strings
|
||||
$response = new SnmpResponse("Q-BRIDGE-MIB::dot1qVlanStaticName[1] = \"default\"\nQ-BRIDGE-MIB::dot1qVlanStaticName[9] = \"\\\\Surrounded\\\\\"");
|
||||
$this->assertTrue($response->isValid());
|
||||
$this->assertEquals('default', $response->value());
|
||||
$this->assertEquals(['Q-BRIDGE-MIB::dot1qVlanStaticName[1]' => 'default', 'Q-BRIDGE-MIB::dot1qVlanStaticName[9]' => '\\Surrounded\\'], $response->values());
|
||||
$this->assertEquals(['Q-BRIDGE-MIB::dot1qVlanStaticName' => [1 => 'default', 9 => '\\Surrounded\\']], $response->table());
|
||||
}
|
||||
|
||||
public function testMultiLine(): void
|
||||
|
Reference in New Issue
Block a user