diff --git a/rules/analyze/ANALYZE-DEV-007.json b/rules/analyze/ANALYZE-DEV-007.json index 9d2027aff..ed420c19f 100644 --- a/rules/analyze/ANALYZE-DEV-007.json +++ b/rules/analyze/ANALYZE-DEV-007.json @@ -5,7 +5,7 @@ "description": "The device's real-time clock deviates from NTP by more than two minutes. Microsoft documents that a clock off by several minutes causes TPM attestation errors (self-deploying/pre-provisioning) and ESP timeouts.", "severity": "warning", "category": "device", - "version": "1.1.0", + "version": "1.1.1", "author": "Autopilot Monitor", "enabled": true, "evaluateOn": [ @@ -17,7 +17,7 @@ "confidenceThreshold": 50, "conditions": [ { - "signal": "clock_ahead", + "signal": "clock_behind", "source": "event_data", "eventType": "ntp_time_check", "dataField": "offsetSeconds", @@ -26,7 +26,7 @@ "required": false }, { - "signal": "clock_behind", + "signal": "clock_ahead", "source": "event_data", "eventType": "ntp_time_check", "dataField": "offsetSeconds", diff --git a/rules/dist/analyze-rules.json b/rules/dist/analyze-rules.json index 20b225f2c..50865c783 100644 --- a/rules/dist/analyze-rules.json +++ b/rules/dist/analyze-rules.json @@ -1654,7 +1654,7 @@ "description": "The device's real-time clock deviates from NTP by more than two minutes. Microsoft documents that a clock off by several minutes causes TPM attestation errors (self-deploying/pre-provisioning) and ESP timeouts.", "severity": "warning", "category": "device", - "version": "1.1.0", + "version": "1.1.1", "author": "Autopilot Monitor", "enabled": true, "evaluateOn": [ @@ -1666,7 +1666,7 @@ "confidenceThreshold": 50, "conditions": [ { - "signal": "clock_ahead", + "signal": "clock_behind", "source": "event_data", "eventType": "ntp_time_check", "dataField": "offsetSeconds", @@ -1675,7 +1675,7 @@ "required": false }, { - "signal": "clock_behind", + "signal": "clock_ahead", "source": "event_data", "eventType": "ntp_time_check", "dataField": "offsetSeconds", diff --git a/src/Web/autopilot-monitor-web/app/sessions/components/SessionInfoCard.tsx b/src/Web/autopilot-monitor-web/app/sessions/components/SessionInfoCard.tsx index 7bf4f6ccd..7d925aa1a 100644 --- a/src/Web/autopilot-monitor-web/app/sessions/components/SessionInfoCard.tsx +++ b/src/Web/autopilot-monitor-web/app/sessions/components/SessionInfoCard.tsx @@ -4,6 +4,7 @@ import { useState } from "react"; import { Session } from "@/types"; import { SessionStatusBadge } from "@/components/SessionStatusBadge"; import FailureSnapshotBlock from "./FailureSnapshotBlock"; +import { deviceClockDirection } from "./sessionInfoLogic"; import { formatDuration } from "@/lib/formatting"; interface SessionInfoCardProps { @@ -125,7 +126,7 @@ export default function SessionInfoCard({ session, enrollmentDuration, displaySt Clock Skew: Device clock is {Math.abs(ntpOffset.offsetSeconds).toFixed(1)}s - {ntpOffset.offsetSeconds > 0 ? " ahead of" : " behind"} UTC + {" "}{deviceClockDirection(ntpOffset.offsetSeconds)} UTC {ntpOffset.ntpServer && <> (NTP: {ntpOffset.ntpServer})} diff --git a/src/Web/autopilot-monitor-web/app/sessions/components/__tests__/sessionInfoLogic.test.ts b/src/Web/autopilot-monitor-web/app/sessions/components/__tests__/sessionInfoLogic.test.ts new file mode 100644 index 000000000..fe0ec25d2 --- /dev/null +++ b/src/Web/autopilot-monitor-web/app/sessions/components/__tests__/sessionInfoLogic.test.ts @@ -0,0 +1,14 @@ +import { describe, expect, it } from "vitest"; +import { deviceClockDirection } from "../sessionInfoLogic"; + +describe("deviceClockDirection", () => { + it("reads a positive NTP offset as a device clock behind UTC", () => { + // NTP 12:37:07, device 02:36:56 -> offsetSeconds = NTP - device = +36010.3 + expect(deviceClockDirection(36010.3)).toBe("behind"); + }); + + it("reads a negative NTP offset as a device clock ahead of UTC", () => { + // NTP 10:21:22, device 19:21:22 -> offsetSeconds = -32400.3 + expect(deviceClockDirection(-32400.3)).toBe("ahead of"); + }); +}); diff --git a/src/Web/autopilot-monitor-web/app/sessions/components/sessionInfoLogic.ts b/src/Web/autopilot-monitor-web/app/sessions/components/sessionInfoLogic.ts new file mode 100644 index 000000000..3999cd609 --- /dev/null +++ b/src/Web/autopilot-monitor-web/app/sessions/components/sessionInfoLogic.ts @@ -0,0 +1,8 @@ +/** + * Direction of the device clock relative to NTP, read from the agent's `ntp_time_check` + * event. The agent computes `offsetSeconds = NTP time − device time` + * (`NtpTimeCheckService`), so a positive value means the device clock is BEHIND. + */ +export function deviceClockDirection(offsetSeconds: number): "ahead of" | "behind" { + return offsetSeconds > 0 ? "behind" : "ahead of"; +}