Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions LibreNMS/Util/Compare.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
2 changes: 1 addition & 1 deletion app/Actions/Device/ValidateDeviceAndCreate.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct(
private Device $device,
private bool $force = false,
private bool $pingFallback = false
){
) {
}

public function execute(): bool
Expand Down
2 changes: 1 addition & 1 deletion app/Actions/Device/ValidateNewDevice.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
Expand Down
34 changes: 18 additions & 16 deletions app/Console/Commands/MakeOsDetection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}

Expand Down Expand Up @@ -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),
);
}
Expand All @@ -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),
};
}

Expand All @@ -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',
Expand All @@ -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,
Expand All @@ -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',
Expand All @@ -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,
Expand Down Expand Up @@ -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',
Expand All @@ -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,
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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',
Expand All @@ -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";
}
}
Expand All @@ -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");
}
Expand Down
3 changes: 2 additions & 1 deletion app/Dto/Device/DeviceDiscoveryData.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
public function __construct(
public bool $force = false,
public bool $pingFallback = false,
) {}
) {
}
}