fix boot time and session list duration

This commit is contained in:
Oliver Kieselbach
2026-02-17 16:05:29 +01:00
parent 09c74aa3e8
commit 1d60904fb0
2 changed files with 16 additions and 7 deletions
@@ -447,7 +447,15 @@ namespace AutopilotMonitor.Functions.Services
if (status == SessionStatus.Succeeded || status == SessionStatus.Failed)
{
// Use the provided completedAt timestamp (from event) if available, otherwise use current time
session["CompletedAt"] = completedAt ?? DateTime.UtcNow;
var effectiveCompletedAt = completedAt ?? DateTime.UtcNow;
session["CompletedAt"] = effectiveCompletedAt;
// Store accurate DurationSeconds based on first event timestamp (not registration StartedAt)
// The agent registers before events arrive, so registration StartedAt is always earlier
// than the actual enrollment start — using the first event gives the true enrollment duration.
var durationStart = effectiveEarliest ?? currentStartedAt;
if (durationStart < effectiveCompletedAt)
session["DurationSeconds"] = (int)(effectiveCompletedAt - durationStart).TotalSeconds;
}
// Set failure reason if failed
@@ -649,9 +657,10 @@ namespace AutopilotMonitor.Functions.Services
Status = status,
FailureReason = entity.GetString("FailureReason") ?? string.Empty,
EventCount = SafeGetInt32(entity, "EventCount") ?? 0,
DurationSeconds = completedAt.HasValue
? (int)(completedAt.Value - startedAt).TotalSeconds
: (int)(DateTime.UtcNow - startedAt).TotalSeconds,
DurationSeconds = SafeGetInt32(entity, "DurationSeconds")
?? (completedAt.HasValue
? (int)(completedAt.Value - startedAt).TotalSeconds
: (int)(DateTime.UtcNow - startedAt).TotalSeconds),
EnrollmentType = entity.GetString("EnrollmentType") ?? "v1",
DiagnosticsBlobName = entity.GetString("DiagnosticsBlobName")
};
@@ -1635,10 +1635,10 @@ function DeviceDetailsCard({ events }: { events: EnrollmentEvent[] }) {
)}
{/* System */}
{(bootTime?.bootTime || agentStarted?.bootTime || agentStarted?.agentVersion || imeVersion || aadJoinStatus?.joinType || deviceLocation?.country || deviceLocation?.Country || deviceLocation?.timezone || deviceLocation?.Timezone) && (
{(bootTime?.bootTimeUtc || bootTime?.bootTime || agentStarted?.bootTime || agentStarted?.agentVersion || imeVersion || aadJoinStatus?.joinType || deviceLocation?.country || deviceLocation?.Country || deviceLocation?.timezone || deviceLocation?.Timezone) && (
<DetailSection title="System">
{(bootTime?.bootTime || agentStarted?.bootTime) && (
<DetailRow label="Boot Time" value={new Date(bootTime?.bootTime || agentStarted?.bootTime).toLocaleString()} />
{(bootTime?.bootTimeUtc || bootTime?.bootTime || agentStarted?.bootTime) && (
<DetailRow label="Boot Time" value={new Date(bootTime?.bootTimeUtc || bootTime?.bootTime || agentStarted?.bootTime).toLocaleString()} />
)}
{bootTime?.uptimeMinutes && <DetailRow label="Uptime until enrollment starts" value={`${Math.floor(bootTime.uptimeMinutes / 60)}h ${bootTime.uptimeMinutes % 60}m`} />}
{agentStarted?.agentVersion && <DetailRow label="Monitor Agent Version" value={agentStarted.agentVersion.replace(/\+([0-9a-f]{7})[0-9a-f]+$/, '+$1')} />}