*/ protected function getViewData(): array { $tenant = Filament::getTenant(); if (! $tenant instanceof Tenant) { return [ 'pollingInterval' => null, 'items' => [], ]; } $tenantId = (int) $tenant->getKey(); $items = []; $highSeverityCount = (int) Finding::query() ->where('tenant_id', $tenantId) ->where('finding_type', Finding::FINDING_TYPE_DRIFT) ->where('status', Finding::STATUS_NEW) ->where('severity', Finding::SEVERITY_HIGH) ->count(); if ($highSeverityCount > 0) { $items[] = [ 'title' => 'High severity drift findings', 'body' => "{$highSeverityCount} finding(s) need review.", 'url' => FindingResource::getUrl('index', tenant: $tenant), ]; } $latestDriftSuccess = OperationRun::query() ->where('tenant_id', $tenantId) ->where('type', 'drift.generate') ->where('status', 'completed') ->where('outcome', 'succeeded') ->whereNotNull('completed_at') ->latest('completed_at') ->first(); if (! $latestDriftSuccess) { $items[] = [ 'title' => 'No drift scan yet', 'body' => 'Generate drift after you have at least two successful inventory runs.', 'url' => DriftLanding::getUrl(tenant: $tenant), ]; } else { $isStale = $latestDriftSuccess->completed_at?->lt(now()->subDays(7)) ?? true; if ($isStale) { $items[] = [ 'title' => 'Drift stale', 'body' => 'Last drift scan is older than 7 days.', 'url' => DriftLanding::getUrl(tenant: $tenant), ]; } } $latestDriftFailure = OperationRun::query() ->where('tenant_id', $tenantId) ->where('type', 'drift.generate') ->where('status', 'completed') ->where('outcome', 'failed') ->latest('id') ->first(); if ($latestDriftFailure instanceof OperationRun) { $items[] = [ 'title' => 'Drift generation failed', 'body' => 'Investigate the latest failed run.', 'url' => OperationRunLinks::view($latestDriftFailure, $tenant), ]; } $activeRuns = (int) OperationRun::query() ->where('tenant_id', $tenantId) ->active() ->count(); if ($activeRuns > 0) { $items[] = [ 'title' => 'Operations in progress', 'body' => "{$activeRuns} run(s) are active.", 'url' => OperationRunLinks::index($tenant), ]; } return [ 'pollingInterval' => ActiveRuns::existForTenant($tenant) ? '10s' : null, 'items' => $items, ]; } }