:100644 100644 9c016ea74 000000000 M LibreNMS/Enum/PollingMethodType.php :100644 100644 8551ea8e5 000000000 M LibreNMS/Enum/SecretType.php :100644 100644 43dd2167c 000000000 M LibreNMS/Interfaces/PollingMethod.php :100644 100644 c9638169b 000000000 M LibreNMS/Polling/ConnectivityHelper.php :100644 100644 283fc25fd 000000000 M LibreNMS/Polling/Method/IcmpPollingMethod.php :100644 100644 4e6dea022 000000000 M LibreNMS/Polling/Method/IpmiPollingMethod.php :100644 100644 7bbeda09a 000000000 M LibreNMS/Polling/Method/SnmpPollingMethod.php :100644 100644 810ce9335 000000000 M LibreNMS/Polling/Method/UnixAgentPollingMethod.php :100644 100644 4f1ce64c3 000000000 M LibreNMS/Polling/ModuleStatus.php :100644 100644 be4c3bce4 000000000 M LibreNMS/Polling/Secrets/SecretData.php :100644 100644 37f0ab7d1 000000000 M LibreNMS/Polling/Secrets/SnmpSecret.php :100644 100644 907f6c919 000000000 M app/Actions/Device/ValidateDeviceAndCreate.php :100644 100644 b8adb7a54 000000000 M app/Casts/EncryptedArray.php :100644 100644 c60cff70f 000000000 M app/Http/Controllers/Device/AddDeviceController.php :100644 100644 df180f044 000000000 M app/Http/Controllers/Device/EditPollingController.php :100644 100644 9667dc3cc 000000000 M app/Http/Controllers/SecretController.php :100644 100644 b8dd4aa43 000000000 M app/Models/Device.php :100644 100644 ec2cb3b41 000000000 M app/Models/DevicePollingMethod.php :100644 100644 4603c163a 000000000 M database/migrations/2026_04_01_140348_create_secrets_table.php :100644 100644 8ca13e06e 000000000 M database/migrations/2026_04_01_140352_create_device_polling_method_table.php :100644 100644 182279f14 000000000 M database/migrations/2026_04_01_162956_migrate_snmp_secrets.php :100644 100644 e0091fdd7 000000000 M database/migrations/2026_04_02_204759_migrate_ipmi_secrets.php :100644 100644 ed0207129 000000000 M database/migrations/2026_04_03_000000_migrate_icmp_polling.php :100644 100644 76e5f1fd5 000000000 M tests/AddHostCliTest.php :100644 100644 83fa14209 000000000 M tests/OSDiscoveryTest.php diff --git a/LibreNMS/Enum/PollingMethodType.php b/LibreNMS/Enum/PollingMethodType.php index 9c016ea74c7c3c61ae8c5d8a658b74c47b9c8e80..a8444926971801338953651c944464077860e4d6 100644 --- a/LibreNMS/Enum/PollingMethodType.php +++ b/LibreNMS/Enum/PollingMethodType.php @@ -45,7 +45,7 @@ enum PollingMethodType: string } /** - * @param array $schema + * @param array $schema * @return array */ public static function buildSchemaFields(array $schema, string $dataVar = 'formData'): array @@ -68,11 +68,10 @@ enum PollingMethodType: string return [ ...$field, - 'key' => $key, - 'field_type' => $field['type'] ?? 'text', + 'key' => $key, + 'field_type' => $field['type'] ?? 'text', 'visible_if_expression' => $visibleIfExpression, ]; })->values()->all(); } } - diff --git a/LibreNMS/Enum/SecretType.php b/LibreNMS/Enum/SecretType.php index 8551ea8e5c0d23feebc2443b39be9932d5857ecb..30053f0b7e996c7f54476050bd372331e3dccf69 100644 --- a/LibreNMS/Enum/SecretType.php +++ b/LibreNMS/Enum/SecretType.php @@ -26,11 +26,9 @@ namespace LibreNMS\Enum; -use LibreNMS\Polling\Secrets\IcmpSecret; use LibreNMS\Polling\Secrets\IpmiSecret; use LibreNMS\Polling\Secrets\SecretData; use LibreNMS\Polling\Secrets\SnmpSecret; -use LibreNMS\Polling\Secrets\UnixAgentSecret; enum SecretType: string { @@ -57,5 +55,4 @@ enum SecretType: string self::Ipmi => IpmiSecret::class, }; } - } diff --git a/LibreNMS/Interfaces/PollingMethod.php b/LibreNMS/Interfaces/PollingMethod.php index 43dd2167c22de4415eadbf9b7acb872857bf785d..e5265edb5636eb03ec27cc88b6ebc894c01bdb68 100644 --- a/LibreNMS/Interfaces/PollingMethod.php +++ b/LibreNMS/Interfaces/PollingMethod.php @@ -6,18 +6,21 @@ interface PollingMethod { /** * UI/form schema for device-specific settings. + * * @return array, visible_if: array}> */ public static function getSettingsSchema(): array; /** * Defaults for polling method per-device settings + * * @return array */ public static function getDefaults(): array; /** * Validation rules for polling method per-device settings + * * @return array */ public static function getRules(): array; diff --git a/LibreNMS/Polling/ConnectivityHelper.php b/LibreNMS/Polling/ConnectivityHelper.php index c9638169bc1d4d7e23351a8ba178749645fa13bd..22b86dc49d12791aaf5771c975ac4b09d01e087b 100644 --- a/LibreNMS/Polling/ConnectivityHelper.php +++ b/LibreNMS/Polling/ConnectivityHelper.php @@ -33,7 +33,8 @@ class ConnectivityHelper { public function __construct( private readonly Device $device, - ) {} + ) { + } /** * Check if a specific polling method is configured and enabled for this device. @@ -46,7 +47,7 @@ class ConnectivityHelper public function isAvailable(): bool { foreach ($this->device->pollingMethods as $method) { - if ($method->enabled && $method->affects_availability && !$method->last_check_successful) { + if ($method->enabled && $method->affects_availability && ! $method->last_check_successful) { return true; } } diff --git a/LibreNMS/Polling/Method/IcmpPollingMethod.php b/LibreNMS/Polling/Method/IcmpPollingMethod.php index 283fc25fd03e73eaa087e75fb4c40d7ce1669183..621a047c2d68a609f590b4521d5189a7fce3085e 100644 --- a/LibreNMS/Polling/Method/IcmpPollingMethod.php +++ b/LibreNMS/Polling/Method/IcmpPollingMethod.php @@ -11,7 +11,8 @@ readonly class IcmpPollingMethod implements PollingMethod public function __construct( public bool $enabled, public bool $affectsAvailability, - ) {} + ) { + } public static function fromModel(DevicePollingMethod $method): self { diff --git a/LibreNMS/Polling/Method/IpmiPollingMethod.php b/LibreNMS/Polling/Method/IpmiPollingMethod.php index 4e6dea02265840d2a64721896b6b06a864705ae7..006db2c3f6b224eaf44bdca85a8d9c3a196d7ff3 100644 --- a/LibreNMS/Polling/Method/IpmiPollingMethod.php +++ b/LibreNMS/Polling/Method/IpmiPollingMethod.php @@ -19,7 +19,8 @@ readonly class IpmiPollingMethod implements PollingMethod public int $cipherSuite, public int $timeout, public string $type, - ) {} + ) { + } public static function fromModel(DevicePollingMethod $method): self { diff --git a/LibreNMS/Polling/Method/SnmpPollingMethod.php b/LibreNMS/Polling/Method/SnmpPollingMethod.php index 7bbeda09a40c4ad94c886528a7628af2daca307e..5698772e7f81ffd35c50699de02180c25e5ae6e1 100644 --- a/LibreNMS/Polling/Method/SnmpPollingMethod.php +++ b/LibreNMS/Polling/Method/SnmpPollingMethod.php @@ -31,7 +31,8 @@ readonly class SnmpPollingMethod implements PollingMethod public int $retries, public int $maxRepeaters, public int $maxOid, - ) {} + ) { + } public static function fromModel(DevicePollingMethod $method): self { diff --git a/LibreNMS/Polling/Method/UnixAgentPollingMethod.php b/LibreNMS/Polling/Method/UnixAgentPollingMethod.php index 810ce9335f69a425cc4be522adf0faf6ff4af113..e0760daae4fae127b1a566d94832fa3f7cb3e05d 100644 --- a/LibreNMS/Polling/Method/UnixAgentPollingMethod.php +++ b/LibreNMS/Polling/Method/UnixAgentPollingMethod.php @@ -13,7 +13,8 @@ readonly class UnixAgentPollingMethod implements PollingMethod public bool $enabled, public bool $affectsAvailability, public int $port, - ) {} + ) { + } public static function fromModel(DevicePollingMethod $method): self { diff --git a/LibreNMS/Polling/ModuleStatus.php b/LibreNMS/Polling/ModuleStatus.php index 4f1ce64c3dc3f1d9c55142a41a2c4df65a343c25..00103791e2676b04bbf6e4d4e062461aa8d0db47 100644 --- a/LibreNMS/Polling/ModuleStatus.php +++ b/LibreNMS/Polling/ModuleStatus.php @@ -26,7 +26,6 @@ namespace LibreNMS\Polling; - class ModuleStatus implements \Stringable { public function __construct( @@ -76,7 +75,6 @@ class ModuleStatus implements \Stringable return 'globally'; } - public function hasSubModules(): bool { return ! empty($this->submodules); diff --git a/LibreNMS/Polling/Secrets/SecretData.php b/LibreNMS/Polling/Secrets/SecretData.php index be4c3bce4aa95a4280ce6e333126d36c6b018d55..cc3b9cd8ca93518e71b175868d99d1e0d66dc5f4 100644 --- a/LibreNMS/Polling/Secrets/SecretData.php +++ b/LibreNMS/Polling/Secrets/SecretData.php @@ -35,12 +35,12 @@ abstract class SecretData implements Arrayable, Jsonable, JsonSerializable /** * Create a new DTO instance from an array. */ - public static abstract function fromArray(array $data): static; + abstract public static function fromArray(array $data): static; /** * Get validation rules for this credential type. */ - public static abstract function rules(): array; + abstract public static function rules(): array; /** * Get UI schema for this credential type. diff --git a/LibreNMS/Polling/Secrets/SnmpSecret.php b/LibreNMS/Polling/Secrets/SnmpSecret.php index 37f0ab7d135385f880a9d86b92407d5425dd6e4b..9c3aba6038b6380dfc8a2ef0fe837db720001a0c 100644 --- a/LibreNMS/Polling/Secrets/SnmpSecret.php +++ b/LibreNMS/Polling/Secrets/SnmpSecret.php @@ -58,6 +58,7 @@ class SnmpSecret extends SecretData /** * @deprecated + * * @param array $device * @return static */ diff --git a/app/Actions/Device/ValidateDeviceAndCreate.php b/app/Actions/Device/ValidateDeviceAndCreate.php index 907f6c919d8ed7d8ed8ce8cc60702e25f0845e44..46eb7929f1403038ac1bc8c833d84ccbb96554eb 100644 --- a/app/Actions/Device/ValidateDeviceAndCreate.php +++ b/app/Actions/Device/ValidateDeviceAndCreate.php @@ -127,8 +127,8 @@ class ValidateDeviceAndCreate $host_unreachable_exception = new HostUnreachableSnmpException($this->device->hostname); // Retrieve existing SNMP secret from relations if set - $existingSnmpSecret = $this->device->relationLoaded('pollingMethods') - ? $this->device->pollingMethods->firstWhere('method_type', PollingMethodType::Snmp)?->secret + $existingSnmpSecret = $this->device->relationLoaded('pollingMethods') + ? $this->device->pollingMethods->firstWhere('method_type', PollingMethodType::Snmp)?->secret : null; // which snmp version should we try (and in what order) diff --git a/app/Casts/EncryptedArray.php b/app/Casts/EncryptedArray.php index b8adb7a54469590122383b429af0e87b3d2b371c..3faab0f2dded6b20a1194c2f50c498310028498c 100644 --- a/app/Casts/EncryptedArray.php +++ b/app/Casts/EncryptedArray.php @@ -32,7 +32,7 @@ class EncryptedArray implements CastsAttributes * * @param array $attributes */ - public function set(Model $model, string $key, mixed $value, array $attributes): string|null + public function set(Model $model, string $key, mixed $value, array $attributes): ?string { if (! is_array($value) || empty($value)) { return null; diff --git a/app/Http/Controllers/Device/AddDeviceController.php b/app/Http/Controllers/Device/AddDeviceController.php index c60cff70f4002576f756d7a55543daf1cb7f329f..e765a46f26e4c33eb6a71c2a9d6a131fe70dd84e 100644 --- a/app/Http/Controllers/Device/AddDeviceController.php +++ b/app/Http/Controllers/Device/AddDeviceController.php @@ -25,8 +25,9 @@ class AddDeviceController use AuthorizesRequests; public function __construct( - private readonly SecretService $secretService, - ) {} + private readonly SecretService $secretService, + ) { + } public function index(Request $request): View { @@ -39,11 +40,11 @@ class AddDeviceController $settingsSchema = $methodClass::getSettingsSchema(); return [ - 'type' => $type->value, - 'label' => __('poller.methods.' . $type->value), - 'schema_fields' => $schemaFields, + 'type' => $type->value, + 'label' => __('poller.methods.' . $type->value), + 'schema_fields' => $schemaFields, 'schema_defaults' => collect($schema)->mapWithKeys( - fn(array $field, string $key): array => [ + fn (array $field, string $key): array => [ $key => $field['default'] ?? (isset($field['options']) ? array_key_first($field['options']) : ''), ] )->all(), @@ -52,15 +53,15 @@ class AddDeviceController }); $availableSecrets = Secret::query()->orderBy('description')->get()->groupBy( - fn(Secret $s): string => $s->secret_type->value + fn (Secret $s): string => $s->secret_type->value ); return view('device.add', [ - 'availableMethods' => $availableMethods, - 'availableSecrets' => $availableSecrets, - 'poller_groups' => PollerGroup::orderBy('group_name')->pluck('group_name', 'id'), - 'default_poller_group' => LibrenmsConfig::get('default_poller_group', 0), - 'port_association_modes' => PortAssociationMode::getModes(), + 'availableMethods' => $availableMethods, + 'availableSecrets' => $availableSecrets, + 'poller_groups' => PollerGroup::orderBy('group_name')->pluck('group_name', 'id'), + 'default_poller_group' => LibrenmsConfig::get('default_poller_group', 0), + 'port_association_modes' => PortAssociationMode::getModes(), 'default_port_association_mode' => LibrenmsConfig::get('default_port_association_mode', 'ifIndex'), ]); } @@ -72,8 +73,8 @@ class AddDeviceController $validated = $request->validated(); $device = new Device([ - 'hostname' => $validated['hostname'], - 'poller_group' => $validated['poller_group'] ?? LibrenmsConfig::get('default_poller_group', 0), + 'hostname' => $validated['hostname'], + 'poller_group' => $validated['poller_group'] ?? LibrenmsConfig::get('default_poller_group', 0), 'port_association_mode' => PortAssociationMode::getId($validated['port_assoc_mode'] ?? 'ifIndex') ?? 1, ]); @@ -97,16 +98,16 @@ class AddDeviceController // SNMP port/transport live in settings on the form; promote them onto // the device row where the legacy schema expects them. if ($type === PollingMethodType::Snmp) { - $device->port = (int) ($settings['port'] ?? LibrenmsConfig::get('snmp.port', 161)); + $device->port = (int) ($settings['port'] ?? LibrenmsConfig::get('snmp.port', 161)); $device->transport = $settings['transport'] ?? LibrenmsConfig::get('snmp.transports.0', 'udp'); unset($settings['port'], $settings['transport']); } $pollingMethod = new DevicePollingMethod([ - 'method_type' => $type, - 'enabled' => true, + 'method_type' => $type, + 'enabled' => true, 'affects_availability' => (bool) ($data['affects_availability'] ?? false), - 'settings' => $settings, + 'settings' => $settings, ]); if ($type->hasSecret()) { @@ -123,9 +124,9 @@ class AddDeviceController if (! $snmpActive) { $device->snmp_disable = 1; - $device->os = $validated['os'] ?: 'ping'; - $device->sysName = $validated['sysName'] ?: ''; - $device->hardware = $validated['hardware'] ?: ''; + $device->os = $validated['os'] ?: 'ping'; + $device->sysName = $validated['sysName'] ?: ''; + $device->hardware = $validated['hardware'] ?: ''; } else { $device->snmp_disable = 0; } @@ -133,12 +134,12 @@ class AddDeviceController // Per-method validate flags: validate if *any* active method requests it. // The SNMP method's validate flag doubles as the old force_add inverse. $forceAdd = collect($rawMethods) - ->filter(fn(array $data): bool => (bool) ($data['active'] ?? false)) - ->every(fn(array $data): bool => empty($data['validate'])); + ->filter(fn (array $data): bool => (bool) ($data['active'] ?? false)) + ->every(fn (array $data): bool => empty($data['validate'])); try { $validator = new ValidateDeviceAndCreate($device, $forceAdd); - $success = $validator->execute(); + $success = $validator->execute(); if (! $success) { return back()->withInput()->withErrors(['hostname' => __('Failed to save device.')]); @@ -174,8 +175,8 @@ class AddDeviceController return new Secret([ 'secret_type' => SecretType::tryFrom($type->value), 'description' => $data['description'] ?? '', - 'default' => (bool) ($data['default'] ?? false), - 'data' => $data['secret_data'] ?? [], + 'default' => (bool) ($data['default'] ?? false), + 'data' => $data['secret_data'] ?? [], ]); } diff --git a/app/Http/Controllers/Device/EditPollingController.php b/app/Http/Controllers/Device/EditPollingController.php index df180f044d3c57e0da3406eb672a86a4a1bc4837..2cfd44b304a01fbe1486a056ca782cf938671409 100644 --- a/app/Http/Controllers/Device/EditPollingController.php +++ b/app/Http/Controllers/Device/EditPollingController.php @@ -23,7 +23,8 @@ class EditPollingController public function __construct( private readonly SecretService $secretService, - ) {} + ) { + } /** * @throws AuthorizationException @@ -62,11 +63,11 @@ class EditPollingController ->orderBy('description') ->get(); $secretDescriptions = $secretsForType->mapWithKeys(fn (Secret $availableSecret): array => [ - (string)$availableSecret->id => $availableSecret->description, + (string) $availableSecret->id => $availableSecret->description, ])->all(); $secretFormDataById = $secretsForType->mapWithKeys(fn (Secret $availableSecret): array => [ - (string)$availableSecret->id => collect($schemaFields)->mapWithKeys(fn (array $field): array => [ - $field['key'] => $canUnmaskSecrets ? (string)data_get($availableSecret->data, $field['key'], '') : '', + (string) $availableSecret->id => collect($schemaFields)->mapWithKeys(fn (array $field): array => [ + $field['key'] => $canUnmaskSecrets ? (string) data_get($availableSecret->data, $field['key'], '') : '', ])->all(), ])->all(); @@ -79,10 +80,10 @@ class EditPollingController ])->all(), 'settings_fields' => PollingMethodType::buildSchemaFields($settingsSchema, 'settingsData'), 'settings' => $row?->settings ?? [], - 'affects_availability' => $row?->affects_availability ?? (bool)($methodClass::getDefaults()['affects_availability'] ?? false), + 'affects_availability' => $row?->affects_availability ?? (bool) ($methodClass::getDefaults()['affects_availability'] ?? false), 'secret' => $secret, 'secret_form_data' => collect($schema)->mapWithKeys(fn (array $field, string $key): array => [ - $key => $canUnmaskSecrets ? (string)data_get($secret?->data, $key, '') : '', + $key => $canUnmaskSecrets ? (string) data_get($secret?->data, $key, '') : '', ])->all(), 'secret_descriptions' => $secretDescriptions, 'secret_form_data_by_id' => $secretFormDataById, @@ -124,7 +125,7 @@ class EditPollingController 'device_id' => $device->device_id, 'method_type' => $type, 'enabled' => true, - 'affects_availability' => (bool)($methodClass::getDefaults()['affects_availability'] ?? false), + 'affects_availability' => (bool) ($methodClass::getDefaults()['affects_availability'] ?? false), 'secret_id' => $secret?->id, 'settings' => $this->buildSettings($methodClass, $request->validatedSettings()), ]); @@ -183,7 +184,7 @@ class EditPollingController if ($type->hasSecret() && array_key_exists('secret_id', $validated)) { $this->authorize('update', Secret::class); - $row->secret_id = $this->resolveExistingSecret((int)$validated['secret_id'], $type)->id; + $row->secret_id = $this->resolveExistingSecret((int) $validated['secret_id'], $type)->id; } elseif ($type->hasSecret() && $request->has('secret_data')) { $this->authorize('update', Secret::class); $mode = $validated['secret_update_mode'] ?? 'update'; @@ -199,8 +200,8 @@ class EditPollingController $methodClass = $type->methodClass(); - $row->enabled = (bool)($validated['enabled'] ?? true); - $row->affects_availability = (bool)($validated['affects_availability'] ?? false); + $row->enabled = (bool) ($validated['enabled'] ?? true); + $row->affects_availability = (bool) ($validated['affects_availability'] ?? false); $row->settings = $this->mergeSettings($row->settings ?? [], $validated['settings'] ?? [], $methodClass); $row->save(); diff --git a/app/Http/Controllers/SecretController.php b/app/Http/Controllers/SecretController.php index 9667dc3ccb69f0535773ae2ba48735403cb8cf26..79f4cbe1f62db76b17853003c5c61c568c42ebeb 100644 --- a/app/Http/Controllers/SecretController.php +++ b/app/Http/Controllers/SecretController.php @@ -114,7 +114,7 @@ class SecretController extends Controller $validated = $request->validate([ 'description' => 'required|string|max:255', - 'default' => 'boolean', + 'default' => 'boolean', ]); $secretType = $secret->secret_type; @@ -128,8 +128,8 @@ class SecretController extends Controller $secret->update([ 'description' => $validated['description'], - 'default' => $request->boolean('default'), - 'data' => $data, + 'default' => $request->boolean('default'), + 'data' => $data, ]); $toast->success(__('Secret updated')); diff --git a/app/Models/Device.php b/app/Models/Device.php index b8dd4aa4303f4eb5e72f0aa07e3d70fba9082ae0..05a670e4bb01e2d4361fd1833c1319210a6a2b4a 100644 --- a/app/Models/Device.php +++ b/app/Models/Device.php @@ -2,7 +2,6 @@ namespace App\Models; -use App\Data\DeviceCredentialRepository; use App\Facades\LibrenmsConfig; use App\Models\Traits\Filterable; use App\View\SimpleTemplate; diff --git a/app/Models/DevicePollingMethod.php b/app/Models/DevicePollingMethod.php index ec2cb3b413f436e2ca79b6c08a400e71a9bf47c8..69a0e6fd0e153749ab00dad8d05e36cd03a48a21 100644 --- a/app/Models/DevicePollingMethod.php +++ b/app/Models/DevicePollingMethod.php @@ -23,7 +23,7 @@ class DevicePollingMethod extends Model 'method_type' => PollingMethodType::class, 'enabled' => 'boolean', 'affects_availability' => 'boolean', - 'settings' => 'array', + 'settings' => 'array', 'last_checked_at' => 'datetime', 'last_check_successful' => 'boolean', ]; diff --git a/database/migrations/2026_04_01_140348_create_secrets_table.php b/database/migrations/2026_04_01_140348_create_secrets_table.php index 4603c163aad564f902f7b2fe60364d210823c027..b572943bc099a4204c254018757559d372a563c6 100644 --- a/database/migrations/2026_04_01_140348_create_secrets_table.php +++ b/database/migrations/2026_04_01_140348_create_secrets_table.php @@ -4,7 +4,8 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration { +return new class extends Migration +{ /** * Run the migrations. */ diff --git a/database/migrations/2026_04_01_140352_create_device_polling_method_table.php b/database/migrations/2026_04_01_140352_create_device_polling_method_table.php index 8ca13e06e291667e0a576b9273f6877f2c0a505a..6f2ab612689e5172b74ebd5c21eb93c1e7512472 100644 --- a/database/migrations/2026_04_01_140352_create_device_polling_method_table.php +++ b/database/migrations/2026_04_01_140352_create_device_polling_method_table.php @@ -4,7 +4,8 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Database\Schema\Blueprint; use Illuminate\Support\Facades\Schema; -return new class extends Migration { +return new class extends Migration +{ /** * Run the migrations. */ diff --git a/database/migrations/2026_04_01_162956_migrate_snmp_secrets.php b/database/migrations/2026_04_01_162956_migrate_snmp_secrets.php index 182279f14cf69e4896cf195d7a10875f1afaa186..0cb5b47f4fc75f73d3adbb757e21cb569c786908 100644 --- a/database/migrations/2026_04_01_162956_migrate_snmp_secrets.php +++ b/database/migrations/2026_04_01_162956_migrate_snmp_secrets.php @@ -3,7 +3,8 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Support\Facades\DB; -return new class extends Migration { +return new class extends Migration +{ public function up(): void { DB::transaction(function () { diff --git a/database/migrations/2026_04_02_204759_migrate_ipmi_secrets.php b/database/migrations/2026_04_02_204759_migrate_ipmi_secrets.php index e0091fdd7768ba58b0a41ba277b4c726ad3fad62..00de6791f352e3d547e60326a13285d455d6c91d 100644 --- a/database/migrations/2026_04_02_204759_migrate_ipmi_secrets.php +++ b/database/migrations/2026_04_02_204759_migrate_ipmi_secrets.php @@ -4,7 +4,8 @@ use Illuminate\Contracts\Encryption\EncryptException; use Illuminate\Database\Migrations\Migration; use Illuminate\Support\Facades\DB; -return new class extends Migration { +return new class extends Migration +{ public function up(): void { DB::transaction(function () { @@ -37,7 +38,7 @@ return new class extends Migration { $data = [ 'username' => $attribs['ipmi_username'] ?? '', 'password' => $attribs['ipmi_password'] ?? '', - 'kg_key' => $attribs['ipmi_kg_key'] ?? null, + 'kg_key' => $attribs['ipmi_kg_key'] ?? null, ]; try { @@ -47,14 +48,14 @@ return new class extends Migration { $secretId = DB::table('secrets')->insertGetId([ 'description' => "IPMI for device {$hostnamesByDevice[$deviceId]}", 'secret_type' => 'ipmi', - 'default' => false, - 'data' => encrypt(json_encode($data)), - 'created_at' => now(), - 'updated_at' => now(), + 'default' => false, + 'data' => encrypt(json_encode($data)), + 'created_at' => now(), + 'updated_at' => now(), ]); $secretMap[$hash] = $secretId; $secretMeta[$secretId] = [ - 'count' => 1, + 'count' => 1, 'hostname' => $hostnamesByDevice[$deviceId], ]; } else { @@ -63,13 +64,13 @@ return new class extends Migration { } $pollingMethods[] = [ - 'device_id' => $deviceId, - 'method_type' => 'ipmi', - 'enabled' => true, + 'device_id' => $deviceId, + 'method_type' => 'ipmi', + 'enabled' => true, 'affects_availability' => false, - 'secret_id' => $secretId, - 'created_at' => now(), - 'updated_at' => now(), + 'secret_id' => $secretId, + 'created_at' => now(), + 'updated_at' => now(), ]; } catch (EncryptException) { // ignore @@ -87,7 +88,7 @@ return new class extends Migration { $id++; DB::table('secrets')->where('id', $secretId)->update([ 'description' => "IPMI (shared #$id)", - 'updated_at' => now(), + 'updated_at' => now(), ]); } } diff --git a/database/migrations/2026_04_03_000000_migrate_icmp_polling.php b/database/migrations/2026_04_03_000000_migrate_icmp_polling.php index ed02071290d20b85cff27cd65056a2bbd1fad3b9..4fbe1d15bb7b1c8b9befc50415b0b96954ee4925 100644 --- a/database/migrations/2026_04_03_000000_migrate_icmp_polling.php +++ b/database/migrations/2026_04_03_000000_migrate_icmp_polling.php @@ -3,7 +3,8 @@ use Illuminate\Database\Migrations\Migration; use Illuminate\Support\Facades\DB; -return new class extends Migration { +return new class extends Migration +{ /** * Run the migrations. */ diff --git a/tests/AddHostCliTest.php b/tests/AddHostCliTest.php index 76e5f1fd594bdd32208ed5234a4bdc4b067d91e4..5d8634989fed2955f9bfaea5c2f01dcfd59fea2a 100644 --- a/tests/AddHostCliTest.php +++ b/tests/AddHostCliTest.php @@ -48,8 +48,6 @@ final class AddHostCliTest extends DBTestCase $device = Device::findByHostname($this->hostName); $this->assertNotNull($device); - - $snmpMethod = $device->getPollingMethod(PollingMethodType::Snmp); $this->assertNotNull($snmpMethod); $secret = $snmpMethod->secret; @@ -72,8 +70,6 @@ final class AddHostCliTest extends DBTestCase $device = Device::findByHostname($this->hostName); $this->assertNotNull($device); - - $snmpMethod = $device->getPollingMethod(PollingMethodType::Snmp); $this->assertNotNull($snmpMethod); $secret = $snmpMethod->secret; @@ -92,8 +88,6 @@ final class AddHostCliTest extends DBTestCase $device = Device::findByHostname($this->hostName); $this->assertNotNull($device); - - $snmpMethod = $device->getPollingMethod(PollingMethodType::Snmp); $this->assertNotNull($snmpMethod); $secret = $snmpMethod->secret; @@ -177,7 +171,6 @@ final class AddHostCliTest extends DBTestCase $device = Device::findByHostname($this->hostName); $this->assertNotNull($device); - $this->assertEquals('hardware', $device->hardware, 'Wrong hardware name'); $this->assertEquals('nameOfOS', $device->os, 'Wrong os name'); $this->assertEquals('system', $device->sysName, 'Wrong system name'); diff --git a/tests/OSDiscoveryTest.php b/tests/OSDiscoveryTest.php index 83fa142095e4d1229010b307b3e253cd2b0d0124..dd8f0926dfbb3ccc743968b5accb901f0cda8c47 100644 --- a/tests/OSDiscoveryTest.php +++ b/tests/OSDiscoveryTest.php @@ -187,15 +187,15 @@ final class OSDiscoveryTest extends TestCase 'hostname' => $this->getSnmpsimIp(), 'os' => 'generic', ]); - + $device->setRelation('pollingMethods', collect([ new \App\Models\DevicePollingMethod([ 'method_type' => \LibreNMS\Enum\PollingMethodType::Snmp, 'enabled' => true, 'affects_availability' => true, - ]) + ]), ])); - + $secret = new \App\Models\Secret([ 'secret_type' => \LibreNMS\Enum\SecretType::Snmp, 'data' => [