diff --git a/LibreNMS/Util/Compare.php b/LibreNMS/Util/Compare.php index 280ec36dcdd9b67c65b70b6d87fbc7ef33060cc1..9afbdaa86aa67f8261599fa0f8be310d151c541f 100644 --- a/LibreNMS/Util/Compare.php +++ b/LibreNMS/Util/Compare.php @@ -63,15 +63,15 @@ class Compare '>' => $a > $b, '<' => $a < $b, 'contains' => Str::contains($a, $b), - 'not_contains' => !Str::contains($a, $b), + 'not_contains' => ! Str::contains($a, $b), 'starts' => Str::startsWith($a, $b), - 'not_starts' => !Str::startsWith($a, $b), + 'not_starts' => ! Str::startsWith($a, $b), 'ends' => Str::endsWith($a, $b), - 'not_ends' => !Str::endsWith($a, $b), + 'not_ends' => ! Str::endsWith($a, $b), 'regex' => Str::isMatch($b, $a), - 'not_regex' => !Str::isMatch($b, $a), + 'not_regex' => ! Str::isMatch($b, $a), 'in_array' => in_array($a, $b), - 'not_in_array' => !in_array($a, $b), + 'not_in_array' => ! in_array($a, $b), 'exists' => isset($a) == $b, default => false, }; diff --git a/app/Actions/Device/ValidateDeviceAndCreate.php b/app/Actions/Device/ValidateDeviceAndCreate.php index d6afd12b7463641978b57b68ba4f0f1b4ab461c0..9a05b00da00853f8dddfa3d5918b489e1070e626 100644 --- a/app/Actions/Device/ValidateDeviceAndCreate.php +++ b/app/Actions/Device/ValidateDeviceAndCreate.php @@ -35,7 +35,7 @@ class ValidateDeviceAndCreate private Device $device, private bool $force = false, private bool $pingFallback = false - ){ + ) { } public function execute(): bool diff --git a/app/Actions/Device/ValidateNewDevice.php b/app/Actions/Device/ValidateNewDevice.php index 672536b07a2a5fb2c1b51959ff1abb78c7d2d7a7..19eae473e99898fe0d4879bd3a6cd9b98b174187 100644 --- a/app/Actions/Device/ValidateNewDevice.php +++ b/app/Actions/Device/ValidateNewDevice.php @@ -22,7 +22,7 @@ class ValidateNewDevice private ConnectivityHelper $connectivity; public function __construct( - private Device $device = new Device, + private Device $device = new Device, private DeviceDiscoveryData $data = new DeviceDiscoveryData, ?ConnectivityHelper $connectivity = null, ) { diff --git a/app/Console/Commands/MakeOsDetection.php b/app/Console/Commands/MakeOsDetection.php index d7cadfa07ae71b678d143b727c3cec3807521e45..79882570afc499b89680106854ae99c61b87a126 100644 --- a/app/Console/Commands/MakeOsDetection.php +++ b/app/Console/Commands/MakeOsDetection.php @@ -18,6 +18,7 @@ use LibreNMS\Util\Validate; use SnmpQuery; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Yaml\Yaml; + use function Laravel\Prompts\confirm; use function Laravel\Prompts\info; use function Laravel\Prompts\select; @@ -122,7 +123,7 @@ class MakeOsDetection extends LnmsCommand private function saveState(): void { if ($this->cacheEnabled) { - Cache::put($this->cacheKey, [$this->detection, $this->state] , now()->addDay()); + Cache::put($this->cacheKey, [$this->detection, $this->state], now()->addDay()); } } @@ -181,17 +182,17 @@ class MakeOsDetection extends LnmsCommand ); $this->askValue( 'text', - fn ($default) => text('Enter display text', default: $default), + fn ($default) => text('Enter display text', default: $default), $this->derive('text', $device), ); $this->askValue( 'type', - fn ($default) => text('Enter device type', default: $default), + fn ($default) => text('Enter device type', default: $default), $this->derive('type', $device), ); $this->askValue( 'icon', - fn ($default) => text('Enter icon name', default: $default), + fn ($default) => text('Enter icon name', default: $default), $this->derive('icon', $device), ); } @@ -207,9 +208,9 @@ class MakeOsDetection extends LnmsCommand ], $default)); match ($this->state['method']) { - 'sysDescr' => $this->buildSysDescrDiscovery($device->sysDescr), - 'snmpget' => $this->buildSnmpGetDiscovery($device), - default => $this->buildSysObjectIdDiscovery($device->sysObjectID), + 'sysDescr' => $this->buildSysDescrDiscovery($device->sysDescr), + 'snmpget' => $this->buildSnmpGetDiscovery($device), + default => $this->buildSysObjectIdDiscovery($device->sysObjectID), }; } @@ -218,7 +219,7 @@ class MakeOsDetection extends LnmsCommand Arr::forget($this->detection, ['discovery.0.sysDescr', 'discovery.0.sysDescr_regex', 'discovery.0.snmpget']); info("sysObjectID: $sysObjectID"); - $match_type = $this->askValue('match', fn($default) => select( + $match_type = $this->askValue('match', fn ($default) => select( label: 'Select match type', options: [ 'starts' => 'starts with', @@ -235,7 +236,7 @@ class MakeOsDetection extends LnmsCommand Arr::forget($this->detection, 'discovery.0.sysObjectID_regex'); } - $this->askValue($field, fn($default) => text( + $this->askValue($field, fn ($default) => text( label: 'Enter sysObjectID prefix', default: $default, required: true, @@ -255,7 +256,7 @@ class MakeOsDetection extends LnmsCommand info("sysDescr: $sysDescr"); - $match_type = $this->askValue('match', fn($default) => select( + $match_type = $this->askValue('match', fn ($default) => select( label: 'Select match type', options: [ 'contains' => 'contains', @@ -272,7 +273,7 @@ class MakeOsDetection extends LnmsCommand Arr::forget($this->detection, 'discovery.0.sysDescr_regex'); } - $this->askValue($field, fn($default) => text( + $this->askValue($field, fn ($default) => text( label: 'Enter sysDescr substring match or regex', default: $default, required: true, @@ -312,7 +313,7 @@ class MakeOsDetection extends LnmsCommand info("Fetched value: $fetched_value"); - $op = $this->askValue('discovery.0.snmpget.0.op', fn($default) => select( + $op = $this->askValue('discovery.0.snmpget.0.op', fn ($default) => select( label: 'Select operator', options: [ '=' => 'equals', @@ -338,7 +339,7 @@ class MakeOsDetection extends LnmsCommand default: $default, scroll: 3, )); - $this->askValue('discovery.0.snmpget.0.value', fn($fetched) => text( + $this->askValue('discovery.0.snmpget.0.value', fn ($fetched) => text( label: 'Enter match string', default: $fetched, required: true, @@ -367,7 +368,7 @@ class MakeOsDetection extends LnmsCommand ]; $data = $this->detection; - uksort($data, function($a, $b) use ($order) { + uksort($data, function ($a, $b) use ($order) { $aPriority = $order[$a] ?? PHP_INT_MAX; $bPriority = $order[$b] ?? PHP_INT_MAX; @@ -402,7 +403,7 @@ class MakeOsDetection extends LnmsCommand // ---------------------- Helpers -------------------------------- private function derive(string $key, Device $device): ?string { - return match($key) { + return match ($key) { 'os' => strtolower(str_replace(' ', '-', substr($device->sysDescr, 0, 10))), 'text' => ucfirst(explode(' ', $device->sysDescr, 2)[0]), 'type' => str_contains($device->sysDescr, 'Switch') ? 'switch' : 'network', @@ -419,6 +420,7 @@ class MakeOsDetection extends LnmsCommand if (count($parts) >= 9) { $pen = $parts[7]; $family = $parts[8]; + return count($parts) > 9 ? ".1.3.6.1.4.1.$pen.$family." : ".1.3.6.1.4.1.$pen.$family"; } } @@ -438,7 +440,7 @@ class MakeOsDetection extends LnmsCommand private function printNextSteps(string $os): void { - $this->line("Next steps:"); + $this->line('Next steps:'); $this->line(" - Edit resources/definitions/os_detection/$os.yaml to adjust details"); $this->line(" - Run: ./lnms dev:os-test --os=$os"); } diff --git a/app/Dto/Device/DeviceDiscoveryData.php b/app/Dto/Device/DeviceDiscoveryData.php index 0bdbddc1e774b56f2ace897084b528866d6ef4a7..3406cbc25a5178ecf5784b6ca20ba980a860929a 100644 --- a/app/Dto/Device/DeviceDiscoveryData.php +++ b/app/Dto/Device/DeviceDiscoveryData.php @@ -7,5 +7,6 @@ readonly class DeviceDiscoveryData public function __construct( public bool $force = false, public bool $pingFallback = false, - ) {} + ) { + } }