diff --git a/LibreNMS/Util/Compare.php b/LibreNMS/Util/Compare.php index 280ec36dcdd9..9afbdaa86aa6 100644 --- a/LibreNMS/Util/Compare.php +++ b/LibreNMS/Util/Compare.php @@ -63,15 +63,15 @@ public static function values($a, $b, $comparison = '=') '>' => $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 d6afd12b7463..9a05b00da008 100644 --- a/app/Actions/Device/ValidateDeviceAndCreate.php +++ b/app/Actions/Device/ValidateDeviceAndCreate.php @@ -35,7 +35,7 @@ public function __construct( 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 672536b07a2a..19eae473e998 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 d7cadfa07ae7..79882570afc4 100644 --- a/app/Console/Commands/MakeOsDetection.php +++ b/app/Console/Commands/MakeOsDetection.php @@ -18,6 +18,7 @@ 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 @@ private function loadState(Device $device): void 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 @@ private function collectMetadata(Device $device): void ); $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 @@ private function collectDiscovery(Device $device): void ], $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 @@ private function buildSysObjectIdDiscovery(string $sysObjectID): void 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 @@ private function buildSysObjectIdDiscovery(string $sysObjectID): void 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 @@ private function buildSysDescrDiscovery(string $sysDescr): void 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 @@ private function buildSysDescrDiscovery(string $sysDescr): void 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 @@ private function buildSnmpGetDiscovery(Device $device): void 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 @@ private function buildSnmpGetDiscovery(Device $device): void 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 @@ private function renderYaml(): string ]; $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 @@ private function writeResult(): void // ---------------------- 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 @@ private function suggestSysObjectIdPrefix(string $oid): string 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 @@ private function suggestSysDescrMatch(string $sysDescr): string 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 0bdbddc1e774..3406cbc25a51 100644 --- a/app/Dto/Device/DeviceDiscoveryData.php +++ b/app/Dto/Device/DeviceDiscoveryData.php @@ -7,5 +7,6 @@ public function __construct( public bool $force = false, public bool $pingFallback = false, - ) {} + ) { + } }