Skip to content
Open
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
6 changes: 3 additions & 3 deletions app/Actions/Device/SetDeviceAvailability.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function execute(Device $device, array $results): bool
$connectivity = new ConnectivityHelper($device);

// Determine which sources are currently enabled on this device
$enabled = collect(['icmp', 'snmp'])->filter(fn($source) => $connectivity->{"{$source}IsEnabled"}());
$enabled = collect(['icmp', 'snmp'])->filter(fn ($source) => $connectivity->{"{$source}IsEnabled"}());

// Normalize keys: AvailabilitySource enum values or plain strings
$checked = collect($results)->mapWithKeys(function ($passed, $source) {
Expand All @@ -31,11 +31,11 @@ public function execute(Device $device, array $results): bool
});

// Previously failing sources that weren't checked this run are still considered failing
$previously_failed = collect(explode(',', (string) $device->status_reason))->map(fn($s) => trim($s))->filter();
$previously_failed = collect(explode(',', (string) $device->status_reason))->map(fn ($s) => trim($s))->filter();
$unchecked_failures = $previously_failed->diff($checked->keys());

// A source is failing if it failed in this run, or was previously failing and wasn't re-checked
$failing = $checked->filter(fn($passed) => ! $passed)->keys()->merge($unchecked_failures);
$failing = $checked->filter(fn ($passed) => ! $passed)->keys()->merge($unchecked_failures);

// Only report failures for sources that are currently enabled
$failed_sources = $failing->intersect($enabled)->sort()->values();
Expand Down