Commit Graph

308 Commits

Author SHA1 Message Date
Oliver Kieselbach 0d2f2ae38c refactor: rename /api/preview-whitelist to /api/preview/whitelist
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 16:50:18 +01:00
Oliver Kieselbach a2de05fe33 refactor: reorganize metrics/stats API routes and fix session-reports 404 handling
- Rename app-metrics → metrics/app (tenant + galactic)
- Rename usage-metrics → metrics/usage (tenant)
- Rename platform/usage-metrics → galactic/metrics/usage
- Rename platform-stats → stats/platform (anon whitelist updated)
- SessionReportService: gracefully handle missing table (404) with empty list
- SessionReportsSection: treat 404 as no reports yet (suppress error)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 16:47:55 +01:00
Oliver Kieselbach f092d601db refactor: move session-reports endpoint to /api/galactic/session-reports
Consistent with /api/galactic/sessions and /api/galactic/app-metrics —
all cross-tenant Galactic Admin endpoints live under /api/galactic/.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 16:26:59 +01:00
Oliver Kieselbach 80ee69276d feat: add Report Session to Autopilot Monitor Team (Private Preview)
Tenant Admins can report sessions for analysis via a new button on the
session details page. Creates a ZIP with session JSON, events JSON,
analysis results, timeline TXT, events CSV, optional agent log (5 MB
limit), and optional screenshot — uploaded to central blob storage.

Admin-config page gets a new Session Reports table (Galactic Admin only)
showing all submitted reports with comment, email, and blob reference.

Export utilities (generateUiExport, generateCsvExport) extracted to
shared lib/sessionExportUtils.ts for reuse across admin export and
report modal.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 16:11:09 +01:00
Oliver Kieselbach d619fd87ba changelog update 2026-03-01 16:06:01 +01:00
Oliver Kieselbach 4017d587a6 changed order on admin-config site 2026-03-01 15:50:27 +01:00
Oliver Kieselbach bfb185b8f1 fix timeline for whiteglove enrollment in UI 2026-03-01 15:41:13 +01:00
Oliver Kieselbach 6083a64ec0 layout re-order in admin-config + session table storage fix 2026-03-01 15:02:17 +01:00
Oliver Kieselbach be317a91dc fix: simplify session status logic — only key events change Status
WhiteGlove sessions showed IsPreProvisioned=false and Status=InProgress
despite whiteglove_complete being stored in Events table. Root cause:
phase_changed events repeatedly wrote Status=InProgress via
UpdateSessionStatusAsync, creating ETag contention and silent failures.

Changes:
- Remove InProgress writes from IngestEventsFunction — Status is only
  set by key events (enrollment_complete, enrollment_failed,
  whiteglove_complete, gather_rules_collection_completed)
- Phase-change events now use IncrementSessionEventCountAsync with
  new currentPhase parameter (lightweight, no Status write)
- Add verification after whiteglove_complete: return HTTP 500 if
  IsPreProvisioned not persisted, so agent retries the batch
- Add IsPreProvisioned to SignalR sessionDelta for real-time UI updates
- Remove now-dead promotion rule from UpdateSessionStatusAsync

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 14:42:40 +01:00
Oliver Kieselbach d012c26360 fixes for whiteglove enrollment on agent side and backend. status pending was never set correctly
fix platform-metrics missing agent version and UI filter for it
2026-03-01 12:13:24 +01:00
Oliver Kieselbach 80f5e3790f fix: compute DurationSeconds from Events table at completion to avoid race condition
The performance commit (477b573) removed GetEarliestSessionEventTimestampAsync
from UpdateSessionStatusAsync, relying solely on the current batch's
earliestEventTimestamp. When concurrent Azure Function invocations process
different batches for the same session, the completion batch could read a stale
StartedAt before the earlier batch's Merge committed — producing wrong
DurationSeconds (e.g. 3s instead of 679s).

Fix: re-introduce the single-row Events table lookup (maxPerPage: 1) only at
completion (Succeeded/Failed) — once per session lifecycle, minimal cost.
Revert MapToSessionSummary to use stored DurationSeconds with null-fallback
for in-progress sessions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 10:16:11 +01:00
Oliver Kieselbach 2092a1f00c fix duraton in session list 2026-03-01 09:18:08 +01:00
Oliver Kieselbach 56e83e5281 fix layout 2026-03-01 01:20:00 +01:00
Oliver Kieselbach c6227f546f feat: add agent self-metrics collector and platform metrics page
Add AgentSelfMetricsCollector that measures the agent's own CPU, memory,
threads, handles, and HTTP network traffic (bytes up/down, latency,
request count) with zero overhead — no WMI, no PerformanceCounters,
just Process properties and lock-free Interlocked counters.

NetworkMetrics tracks all BackendApiClient HTTP calls via Stopwatch and
byte counting in finally blocks. The collector emits agent_metrics_snapshot
events (Severity.Debug) through the existing spool/upload pipeline.

Add Galactic Admin-only /platform-metrics page that aggregates agent
footprint data across sessions with CPU/memory/network assessment badges,
per-session breakdowns, and agent version distribution.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 01:11:20 +01:00
Oliver Kieselbach 477b573f1f perf: eliminate redundant table scans, improve concurrency, optimize SignalR
- Remove full event-count recount (partition scan) from UpdateSessionStatusAsync;
  IncrementSessionEventCountAsync already maintains the count atomically
- Remove redundant GetEarliestSessionEventTimestampAsync calls from
  UpdateSessionStatusAsync and IncrementSessionEventCountAsync; the caller
  (IngestEventsFunction) already computes and passes the timestamp
- Switch UpdateSessionStatusAsync from Replace to Merge mode, writing only
  changed fields to drastically reduce ETag conflicts under concurrency
- Increase ETag retry limit from 3 to 5 with jitter-based exponential backoff
- Add server-side time-range filter (90 days) to UsageMetrics queries,
  avoiding loading the entire sessions table into memory
- Remove full session object from SignalR eventStream message; session delta
  updates now flow via the existing newevents tenant-group message
- Add newevents handler to session detail page for live session delta updates
- Auto-rejoin SignalR groups on reconnect to prevent silent update loss

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-28 23:49:47 +01:00
Oliver Kieselbach 65f4c5a2bb more efficient WMI queries 2026-02-28 23:48:09 +01:00
Oliver Kieselbach ab08d48d94 added missing event timestamps 2026-02-28 21:23:25 +01:00
Oliver Kieselbach 4bf2b965ae fix: compute SAS URL expiry on input change for instant feedback
Move SAS expiry calculation from page-level state into DiagnosticsSection
so the expiry indicator updates immediately when the user types or pastes
a new URL, instead of requiring a save and page reload.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-28 20:47:52 +01:00
Oliver Kieselbach 4e21ae3008 security: enforce admin authorization, fix error leakage, prevent injection
- H1: Require TenantAdmin or GalacticAdmin for mutative tenant endpoints
  (DeleteSession, MarkSessionFailed, UpdateTenantConfiguration,
  AnalyzeRules CRUD, GatherRules CRUD)
- M1: Add EnsureValidGuid validation to TenantOffboardFunction to
  prevent OData injection via tenantId route parameter
- M2: Remove ex.Message from error responses in UsageMetrics,
  PlatformUsageMetrics, TriggerMaintenance, TenantOffboard,
  ReseedFromGitHub to prevent internal error leakage
- M4: Use requireGalacticAdmin on ProtectedRoute and server-derived
  user.isGalacticAdmin instead of localStorage for admin-configuration
- N1: Add 1-second Regex timeout to agent GatherRuleExecutor and
  ImeLogTracker to prevent ReDoS from malicious patterns

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-28 20:46:50 +01:00
Oliver Kieselbach 59d7988092 changed wording 2026-02-28 19:33:36 +01:00
Oliver Kieselbach 13a781bd34 refactor: reorganize project structure 2026-02-28 19:25:34 +01:00
Oliver Kieselbach 4ce531191b feat: RuleStates table + community rules + remove global edit/delete
- New RuleStates table stores per-tenant enabled/disabled state separately
  from rule definitions, so built-in/community rule updates propagate
  centrally without losing tenant preferences
- New IsCommunity flag on GatherRule and AnalyzeRule models; community
  rules behave like built-in but show a Community badge in the UI
- Merge logic updated: global partition holds definitions (built-in +
  community), RuleStates holds per-tenant toggles, tenant partition
  holds custom rules only
- Fixed AnalyzeRule Trigger field not being persisted to/from Table Storage
- Fixed EnsureBuiltInRulesSeededAsync comparison to include Version,
  Trigger, and TriggerPhase so definition changes auto-propagate
- Removed Edit (Global) and Delete (Global) from Gather/Analyze rules UI;
  rule management is now exclusively via Git + Reseed
- Added Community filter option to type filter dropdowns
- ReseedFromGitHubFunction now deletes both IsBuiltIn and IsCommunity
  rules from global partition before reseeding
- GalacticAdminService dependency removed from Gather/AnalyzeRulesFunction

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-28 17:33:46 +01:00
Oliver Kieselbach 19856ad331 Merge branch 'main' of https://github.com/okieselbach/Autopilot-Monitor 2026-02-28 16:48:29 +01:00
Oliver Kieselbach 35f7f59520 fix SessionDetailsPage flickering 2026-02-28 16:48:25 +01:00
okieselbach 0b322f2d2c chore: regenerate rules/dist from individual files 2026-02-28 13:12:14 +00:00
Oliver Kieselbach 65860d7e9b version bump 2026-02-28 14:11:35 +01:00
Oliver Kieselbach e5b0faf692 fixed combine workflow to allwow push 2026-02-28 14:10:39 +01:00
Oliver Kieselbach a1c9e9a576 chagned gather rule phase definition 2026-02-28 14:07:57 +01:00
Oliver Kieselbach 46d947563b Reseed ime pattern button + tenant management on desktop layout 2026-02-28 13:48:16 +01:00
Oliver Kieselbach 17e8e67f9b fix navbar 2026-02-28 13:27:16 +01:00
Oliver Kieselbach 64a9a0aa99 chore: unignore rules/dist/ and add initial combined rule files
rules/dist/ was excluded by the global dist/ .gitignore pattern.
Added !rules/dist/ exception so the combine-rules workflow can
commit the generated files. Also adds the initial dist files.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-28 13:24:15 +01:00
Oliver Kieselbach 7cb5cf040c fix: add count_per_group_gte operator to analyze rule schema
Adds the missing operator to the enum so ANALYZE-APP-006.json passes
schema validation in the combine-rules workflow.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-28 13:19:35 +01:00
Oliver Kieselbach 1f796bf6e3 feat: externalize rules to GitHub + API consolidation + preview mode
## Rules as GitHub single source of truth
- Add 75 individual JSON rule files (2 gather, 18 analyze, 55 IME patterns)
  under rules/gather/, rules/analyze/, rules/ime-log-patterns/
- Add JSON Schemas for all three rule types with VS Code IntelliSense support
- Add CI combine script (rules/scripts/combine.js) + GitHub Action that
  validates schemas with ajv-cli and generates rules/dist/ combined files
- Convert BuiltIn*.cs from hardcoded C# objects to embedded JSON resource loaders
- Add GitHubRuleRepository service to fetch dist/ files from raw.githubusercontent.com
- Add ReseedFromGitHubFunction: POST /api/rules/reseed-from-github?type=all|gather|analyze|ime

## IME Log Patterns
- Extend ImeLogPattern model with Description and IsBuiltIn properties
- Add ImeLogPatterns table + API constants
- Add TableStorageService CRUD methods for IME log patterns
- Add ImeLogPatternService (CRUD, merge, auto-seed from embedded JSON)
- Add ImeLogPatternsFunction: GET/PUT /api/rules/ime-log-patterns (Phase 1: read-only
  for tenants, Galactic Admin can enable/disable/edit globally)
- Add IME Log Patterns management page (/ime-log-patterns)
- Wire GetAgentConfigFunction to use ImeLogPatternService instead of static class

## API route consolidation
- All rule endpoints now under /api/rules/* for single certificate exclusion path:
  /api/rules/gather, /api/rules/analyze, /api/rules/ime-log-patterns,
  /api/rules/reseed-from-github

## Export buttons
- Add per-rule and export-all JSON download buttons to gather-rules,
  analyze-rules, and ime-log-patterns pages

## Admin configuration
- Replace old individual reseed buttons with unified "Fetch & Reseed from GitHub"
  (calls new GitHub endpoint) plus compact individual-type reseed buttons
- Add CDN cache hint: GitHub raw.githubusercontent.com caches up to 5 minutes

## Preview mode
- ?preview=1 URL param seeds localStorage.previewMode (persists across navigation)
- ?preview=0 clears it; toggle in Navbar settings dropdown (indigo, eye icon)
- IME Log Patterns nav link gated behind galacticAdminMode OR previewMode
- Preview badge shown on nav link when active for normal users

## Tests
- Add xUnit test project (net8.0) with 5 tests for embedded resource loading,
  known IME actions validation, and valid categories check

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-28 13:12:09 +01:00
Oliver Kieselbach 923f03ea39 fix fleet health 2026-02-28 00:22:06 +01:00
Oliver Kieselbach 5f848aa7b5 fix: gather rules toggle bug, global delete, mobile layout improvements
- fix: handleToggleRule sent only {enabled} — now sends full rule object
  to prevent overwriting all fields with empty values on toggle
- feat: GatherRule global delete (Galactic Admin) — new DeleteGlobalRuleAsync,
  ?global=true query param on DELETE endpoint, Delete (Global) button in UI
- fix: admin-configuration page mobile layout — Maintenance, Reseed Analyze,
  Reseed Gather panels: action buttons moved to bottom (flex vertical)
- fix: tenant management list mobile layout — badges and buttons below info text
- fix: session detail event timeline — filter badges + expand/collapse in one
  flex-wrap row; expand/collapse show icon-only on mobile, text on sm+

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-28 00:12:40 +01:00
Oliver Kieselbach b0ff5f08c8 fix layout 2026-02-27 22:09:11 +01:00
Oliver Kieselbach 54a3327c2c fix: fleet health model bar chart - full name visible, slimmer bar
Model name now renders fully above the bar (no truncation, break-words).
Bar height reduced from h-4 to h-2. Percentage and device count shown
inline right-aligned next to the name row.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-27 21:58:00 +01:00
Oliver Kieselbach cb7b270144 fix wording 2026-02-27 21:51:17 +01:00
Oliver Kieselbach 084e02d31e changelog update 2026-02-27 21:48:06 +01:00
Oliver Kieselbach 56c51cd888 feat: shorten tenant ID in galactic session table + copy on click
Tenant ID column in galactic admin mode now shows only the first two
GUID segments (e.g. b54dc1af-5320). Full ID shown as tooltip. Click
copies the full tenant ID to clipboard; copy icon appears on hover.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-27 21:46:29 +01:00
Oliver Kieselbach fafff58c92 fix: diag log path entries use full-width layout with line-wrap, remove core collector hint
- Path and description stack vertically in their own row (break-all for long paths)
- Replaced rounded-full chips with rounded-lg full-width entries in both settings and admin-config
- Removed 'Core collectors Hello Detector...' info box from settings

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-27 21:33:31 +01:00
Oliver Kieselbach 3d7c4a0af2 feat: configurable diagnostics log paths + reseed gather rules
- Add DiagnosticsLogPath model and DiagnosticsPathGuards (agent-side allowlist)
- Global paths configurable by Galactic Admin (AdminConfiguration.DiagnosticsGlobalLogPathsJson)
- Tenant-specific paths configurable in Settings (TenantConfiguration.DiagnosticsLogPathsJson)
- Backend merges global + tenant paths and delivers via AgentConfigResponse (ConfigVersion 9)
- Agent reads merged paths in DiagnosticsPackageService, validates via guards before adding to ZIP
- Admin Configuration page: new Diagnostics Log Paths panel (teal/cyan)
- Settings page: Additional Log Paths section with global read-only chips + tenant chip editor
- Add reseed endpoint and service method for gather rules (POST /api/gather-rules/reseed)
- Docs: SectionGatherRules guard lists collapse by default; SectionSettings adds Additional Log Paths row

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-27 21:21:30 +01:00
Oliver Kieselbach a99a1c02af fix layout 2026-02-27 20:21:16 +01:00
Oliver Kieselbach 6f6ecb311c Refactorings 2026-02-27 20:06:14 +01:00
Oliver Kieselbach f07a354c35 fix: 8-second timeout on /api/auth/me to prevent cold-start hang on landing page
The fetchUserInfo call to GET /api/auth/me had no timeout. When Azure
Functions are cold (scale-to-zero), this could block for 20-60 seconds,
holding isLoading=true and showing only the spinner on the landing page.

Add an AbortController with an 8-second deadline. On timeout the abort
signal causes the fetch to throw, which is caught by the existing catch
block that falls back to MSAL token claims — the user can still log in
normally. isGalacticAdmin/isTenantAdmin will be false until the backend
is warm and the next auth refresh succeeds.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-27 19:30:49 +01:00
Oliver Kieselbach b0c66bdf70 feat: gather rules JSON toggle, parameter UI, built-in rules, analyze rules docs
- Add Form/JSON toggle to Gather Rules editor (create + edit), matching Analyze Rules pattern
- Add missing parameter UI for eventlog (source/provider), file (readContent), and logparser (pattern, trackPosition, maxLines) collector types
- Add two disabled built-in gather rules: dsregcmd /status on DevicePreparation phase change, and last startup event (Event ID 12) from System eventlog
- Fix file collector to read last 4000 chars instead of first (more useful for log files)
- Docs: expand registry allowlist to all 21 prefixes, update file read description
- Docs: add comprehensive Analyze Rules section with confidence scoring, condition types, trigger types, and examples
- Add Documentation link in Analyze Rules page header

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-27 19:25:21 +01:00
Oliver Kieselbach 8eb8c31e90 feat: EventLog collector rewrite, dynamic gather rule UI hints, docs
Agent:
- Rewrite EventLog collector from System.Diagnostics.EventLog to
  EventLogReader — supports operational/analytic logs (e.g.,
  Microsoft-Windows-Shell-Core/Operational), not just classic logs
- New parameters: eventId (XPath filter), messageFilter (*contains*),
  source (provider name), maxEntries (1-50)
- Event entries now include Event ID in output: [ID:62407]

UI (gather-rules):
- Dynamic target placeholder and hint text per collector type
- EventLog parameter fields: Event ID, Max Entries, Message Filter
- buildParameters() serializes params per collector type (create+edit)
- on_event placeholder updated to show enrollment_complete/failed
- Documentation link in header → /docs#gather-rules

Docs:
- New "Gather Rules" section with all 6 collector types documented
- Each collector: target format, parameters, allowlists, examples
- Trigger types documented (startup, interval, phase_change, on_event)
- Hash-based deep linking from gather-rules page

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-27 18:58:22 +01:00
Oliver Kieselbach fc963ef85e fix: show domainName (tenantId) in Device Block Management dropdowns
Consistent with Session Event Export tenant dropdown format.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-27 17:48:04 +01:00
Oliver Kieselbach a553f09ec3 fix: CSV export row order and RowKey, tenant dropdown, input cleaning
- CSV now sorted by Timestamp+Sequence (matches Azure Table order exactly)
- Added RowKey as first CSV column (format: yyyyMMddHHmmssfff_Sequence)
- Backend: map entity.RowKey in MapToEnrollmentEvent, expose via EnrollmentEvent
- Tenant ID field replaced with dropdown (domainName + tenantId) + free-text input
- cleanId() helper strips leading/trailing quotes and whitespace from ID inputs

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-27 17:41:24 +01:00
Oliver Kieselbach 17cfc91273 fix: persistent sequence counter across boots, spool RemoveEvents collision fix
The event sequence counter reset to 0 on every agent restart, causing three
bugs in WhiteGlove (pre-provisioning) sessions: spool sort order mixed boot
events, backend status regressed from Pending to InProgress, and UI timeline
split broke. Additionally, EventSpool.RemoveEvents used a glob pattern that
could delete files from both boots sharing the same sequence number.

Changes:
- SessionPersistence: persist sequence in session.seq alongside session.id
- EventSpool: RemoveEvents uses exact filename instead of glob, new
  GetMaxSequence for crash recovery
- MonitoringService: init sequence from persistence + spool ceiling, periodic
  save every 50 events + on critical events, save before WhiteGlove exit
- TableStorageService: document WhiteGlove guard as promotion rule
- EnrollmentEvent: clarify Timestamp is agent-side, not server-side

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-27 17:39:53 +01:00