sophos-central-mcp-server 0.11.1 → 0.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -5
- package/dist/client/fusion-client.d.ts +8 -2
- package/dist/client/fusion-client.d.ts.map +1 -1
- package/dist/client/fusion-client.js +8 -6
- package/dist/client/fusion-client.js.map +1 -1
- package/dist/fusion/inventory.d.ts +118 -0
- package/dist/fusion/inventory.d.ts.map +1 -0
- package/dist/fusion/inventory.js +289 -0
- package/dist/fusion/inventory.js.map +1 -0
- package/dist/fusion/queries/search.d.ts +7 -0
- package/dist/fusion/queries/search.d.ts.map +1 -1
- package/dist/fusion/queries/search.js +7 -0
- package/dist/fusion/queries/search.js.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/tools/fusion-inventory.d.ts +24 -0
- package/dist/tools/fusion-inventory.d.ts.map +1 -0
- package/dist/tools/fusion-inventory.js +354 -0
- package/dist/tools/fusion-inventory.js.map +1 -0
- package/dist/tools/fusion-search.d.ts.map +1 -1
- package/dist/tools/fusion-search.js +8 -4
- package/dist/tools/fusion-search.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
> Sophos. It calls the public Sophos APIs using credentials you supply. Use it at your own
|
|
6
6
|
> risk, and raise problems as issues on this repository rather than with Sophos support.
|
|
7
7
|
|
|
8
|
-
MCP (Model Context Protocol) server for the Sophos Fusion and Sophos Central APIs. Supports partner, organisation, and single-tenant credential types with automatic region routing. **
|
|
8
|
+
MCP (Model Context Protocol) server for the Sophos Fusion and Sophos Central APIs. Supports partner, organisation, and single-tenant credential types with automatic region routing. **334 tools** covering 23 Sophos API namespaces: the Sophos Central REST APIs plus the Sophos Fusion GraphQL APIs (`sophos_fusion_*`). Install it as a Claude Desktop extension (`.mcpb`), run it with npx, or host it yourself over streamable HTTP.
|
|
9
9
|
|
|
10
10
|
The npm package, the `.mcpb` bundle and the binaries keep the `sophos-central-mcp-server` name so existing installs update in place.
|
|
11
11
|
|
|
@@ -170,7 +170,7 @@ The script:
|
|
|
170
170
|
npm test
|
|
171
171
|
```
|
|
172
172
|
|
|
173
|
-
Builds, then runs the `node:test` suites in `test/` with `fetch` stubbed: the Fusion GraphQL transport (including the HTTP 200 with `errors` case), the QL builder, the reference-data cache, and the path-keyed retry for the intermittent case-write fault, the migration guard, the policy assignment and web profile writes (body shapes, refusals, target lookups and read-back) against an in-memory policy store, the no-retry rule for a POST or mutation after a 5xx, the read-modify-write and PATCH update tools, the request shapes of the tools checked against the published specs, the request shapes of the October 2026 bulk endpoint, S/MIME and Search tools, the item and page totals the REST list tools report, a registration check that lists all
|
|
173
|
+
Builds, then runs the `node:test` suites in `test/` with `fetch` stubbed: the Fusion GraphQL transport (including the HTTP 200 with `errors` case), the QL builder, the reference-data cache, and the path-keyed retry for the intermittent case-write fault, the migration guard, the policy assignment and web profile writes (body shapes, refusals, target lookups and read-back) against an in-memory policy store, the no-retry rule for a POST or mutation after a 5xx, the read-modify-write and PATCH update tools, the request shapes of the tools checked against the published specs, the request shapes of the October 2026 bulk endpoint, S/MIME and Search tools, the item and page totals the REST list tools report, the endpoint inventory's reduction to the latest snapshot and its stale flag, a registration check that lists all 334 tools over an in-memory transport and checks the descriptions for the measured warnings, the `SOPHOS_FUSION_GRAPHQL_URL` check, and the HTTP transport (Origin guard, bearer token, listen address, concurrent calls) run against an in-memory Sophos. Nothing in `npm test` reaches Sophos.
|
|
174
174
|
|
|
175
175
|
To exercise the Fusion tools against a live tenant, put credentials in `.env` (or export them) and run:
|
|
176
176
|
|
|
@@ -198,7 +198,7 @@ It spawns the built server over stdio and calls the tools through an MCP client,
|
|
|
198
198
|
- **One-click install**: Ships as a Claude Desktop extension (`.mcpb`) with credentials held in the OS secure store
|
|
199
199
|
- **Two API generations**: the Sophos Central REST APIs and the Sophos Fusion GraphQL APIs on one credential, with `sophos_fusion_*` tools for the GraphQL side
|
|
200
200
|
- **Migration aware**: the Classic case and detection tools refuse a tenant that has moved to Sophos Fusion and name the `sophos_fusion_*` tool to use instead; `sophos_fusion_list_case_reference_data` reports the tenant type
|
|
201
|
-
- **Full API coverage**:
|
|
201
|
+
- **Full API coverage**: 334 tools across endpoints, alerts, policies, firewalls, web filtering, licensing, audit events, email (including S/MIME), mobile, XDR, Data Lake search, cases, SIEM, and more
|
|
202
202
|
|
|
203
203
|
## Screenshots
|
|
204
204
|
|
|
@@ -496,9 +496,9 @@ Sophos Fusion Detections GraphQL API v2. One QL search replaces the Classic run,
|
|
|
496
496
|
|
|
497
497
|
### Fusion Search (4 tools)
|
|
498
498
|
|
|
499
|
-
Sophos Fusion Search GraphQL API v1 (12/10/2026): Data Lake searches in QL, the counterpart of the SQL XDR Query tools. Asynchronous: start a search, poll it by its URN until `COMPLETE`, check `outcome.success` (`ALL`, `PARTIAL` or `NONE`), then page the rows by cursor (up to 1000 per page). Working example `from process earliest=-1h | fields host_id, image_path`. Project with `| fields`: an unprojected search returns over 800 fields, so field metadata is off unless asked for. Results expire (30 days in testing). `sophos_fusion_get_or_create_search` reuses a matching search only when the query has absolute time bounds; a relative one (`earliest=-1h`) starts a new search each call.
|
|
499
|
+
Sophos Fusion Search GraphQL API v1 (12/10/2026): Data Lake searches in QL, the counterpart of the SQL XDR Query tools. Asynchronous: start a search, poll it by its URN until `COMPLETE`, check `outcome.success` (`ALL`, `PARTIAL` or `NONE`), then page the rows by cursor (up to 1000 per page). Working example `from process earliest=-1h | fields host_id, image_path`. Project with `| fields`: an unprojected search returns over 800 fields, so field metadata is off unless asked for. Results expire (30 days in testing). `sophos_fusion_get_or_create_search` reuses a matching search only when the query has absolute time bounds; a relative one (`earliest=-1h`) starts a new search each call. A search returns at most 10,000 rows, newest first, and its `total` then reads 10,000 however many rows matched (an aggregate counted 69,323 behind one), so a total of 10,000 means rows may be missing: count with `| aggregate count`, and narrow the query. A results page can take longer than 30 seconds (37 seconds measured), so the server waits up to 120 seconds for one.
|
|
500
500
|
|
|
501
|
-
Endpoint inventory: `softwareinfo` (installed applications), `patchstate` (installed OS patches, one row per KB) and `inventoryinfo` (device record). One snapshot per device per day, offline devices included, so check last seen with `sophos_list_endpoints
|
|
501
|
+
Endpoint inventory: `softwareinfo` (installed applications), `patchstate` (installed OS patches, one row per KB) and `inventoryinfo` (device record). One snapshot per device per day, offline devices included, so check last seen with `sophos_list_endpoints`, or use `sophos_fusion_endpoint_inventory` below, which does that for you. Example `from softwareinfo where product.name contains 'Chrome' earliest=-1d | fields host_id, device.hostname, product.name, product.version`. `inventoryinfo` also holds device discovery events (`metadata.event_code` `device_discovery`, `normalizer` `sophos-xdr-telemetry-normalizer`): a device the endpoint saw on its network, filed under the reporting endpoint's `host_id`, with the seen device's IP and MAC and no hostname or OS. Drop them with `where normalizer != 'sophos-xdr-telemetry-normalizer'`, as `sophos_fusion_endpoint_inventory` does.
|
|
502
502
|
|
|
503
503
|
| Tool | Description |
|
|
504
504
|
|------|-------------|
|
|
@@ -507,6 +507,16 @@ Endpoint inventory: `softwareinfo` (installed applications), `patchstate` (insta
|
|
|
507
507
|
| `sophos_fusion_get_search` | Status, outcome, partition diagnostics and expiry of a search |
|
|
508
508
|
| `sophos_fusion_get_search_results` | One page of rows from a search or partition, with totals and the next cursor |
|
|
509
509
|
|
|
510
|
+
### Fusion Endpoint Inventory (1 tool)
|
|
511
|
+
|
|
512
|
+
Installed applications (`softwareinfo`), installed OS patches (`patchstate`) or the device record (`inventoryinfo`) from the Data Lake, reduced to each device's latest snapshot and flagged by when the device was last seen. The Data Lake keeps writing a daily snapshot for about 30 days after a device goes offline, so a snapshot dated today can describe a device that has been offline for weeks. Each device is matched on `host_id` (its endpoint ID) to `lastSeenAt` from the Endpoint API and marked `stale` (last seen more than `stale_after_days` ago, default 3), `fresh`, or `unmatched` (deleted, re-registered, or a third-party sensor). It shows what is installed, not what is missing: there is no CVE or missing-patch field.
|
|
513
|
+
|
|
514
|
+
Filter by `endpoint_id`, `hostname`, `software_name` (softwareinfo) or `kb` (patchstate), and return only `stale`, `fresh` or `unmatched` devices with `status`. The summary counts every device. For example, `{ schema: "softwareinfo", software_name: "Chrome" }` lists each device's Chrome versions with its last seen. Calls with the same arguments in the same UTC hour reuse the same searches, so paging with `offset` is quick.
|
|
515
|
+
|
|
516
|
+
| Tool | Description |
|
|
517
|
+
|------|-------------|
|
|
518
|
+
| `sophos_fusion_endpoint_inventory` | Latest inventory snapshot per device, with stale, fresh and unmatched counts |
|
|
519
|
+
|
|
510
520
|
### Detections (6 tools)
|
|
511
521
|
|
|
512
522
|
Sophos Central Detections REST API, async: start a query, poll for completion, then fetch results. Refused for a tenant that has moved to Fusion, with a pointer to `sophos_fusion_search_detections`.
|
|
@@ -833,6 +843,7 @@ src/
|
|
|
833
843
|
│ ├── queries/cases.ts # Cases v2 GraphQL documents
|
|
834
844
|
│ ├── queries/detections.ts # Detections v2 documents: the case summary lookup and the QL search
|
|
835
845
|
│ ├── queries/search.ts # Search v1 documents: create, get-or-create, status, results
|
|
846
|
+
│ ├── inventory.ts # Inventory QL, latest snapshot per device, stale flag
|
|
836
847
|
│ ├── case-reference-data.ts # Per-tenant cache of case types, statuses, verdicts
|
|
837
848
|
│ ├── cases-ql.ts # QL builder for the cases search
|
|
838
849
|
│ ├── format.ts # Severity scales, timestamps, ID checks, mentions, tags, detection rows
|
|
@@ -843,6 +854,7 @@ src/
|
|
|
843
854
|
│ ├── fusion-cases.ts # Sophos Fusion cases (GraphQL)
|
|
844
855
|
│ ├── fusion-detections.ts # Sophos Fusion detection search (GraphQL)
|
|
845
856
|
│ ├── fusion-search.ts # Sophos Fusion Data Lake search (GraphQL)
|
|
857
|
+
│ ├── fusion-inventory.ts # Sophos Fusion endpoint inventory with last seen
|
|
846
858
|
│ ├── tenants.ts # Tenant listing (partner/org only)
|
|
847
859
|
│ ├── partner.ts # Partner admin, roles, billing (partner/org only)
|
|
848
860
|
│ ├── alerts.ts # Alert list, get, acknowledge, search
|
|
@@ -67,6 +67,11 @@ export interface FusionClientOptions {
|
|
|
67
67
|
/** Base for the short full-jitter backoff between those attempts. Default 300 ms, capped at 2 s. */
|
|
68
68
|
transientBackoffMs?: number;
|
|
69
69
|
}
|
|
70
|
+
/** Options for one query() call. */
|
|
71
|
+
export interface FusionQueryOptions {
|
|
72
|
+
/** Per-attempt timeout for this call, in place of the client's. */
|
|
73
|
+
timeoutMs?: number;
|
|
74
|
+
}
|
|
70
75
|
/** Thrown when the GraphQL layer returns errors and no usable data. */
|
|
71
76
|
export declare class FusionGraphQLError extends Error {
|
|
72
77
|
readonly errors: GraphQLErrorEntry[];
|
|
@@ -117,9 +122,10 @@ export declare class FusionClient {
|
|
|
117
122
|
* FusionGraphQLError when the response carries errors and no usable data,
|
|
118
123
|
* and a plain Error for transport failures. The transient partnerPreferences
|
|
119
124
|
* fault is retried up to transientAttempts times; every other GraphQL-layer
|
|
120
|
-
* error surfaces at once.
|
|
125
|
+
* error surfaces at once. options.timeoutMs replaces the per-attempt timeout
|
|
126
|
+
* for this call, for an operation known to run longer (a Search results page).
|
|
121
127
|
*/
|
|
122
|
-
query<T extends object>(tenantId: string, document: string, variables?: Record<string, unknown
|
|
128
|
+
query<T extends object>(tenantId: string, document: string, variables?: Record<string, unknown>, options?: FusionQueryOptions): Promise<FusionQueryResult<T>>;
|
|
123
129
|
/**
|
|
124
130
|
* PUT raw bytes to a presigned upload URL (case files). The signature lives
|
|
125
131
|
* in the URL, so no bearer token is sent, and the Content-Type must match
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fusion-client.d.ts","sourceRoot":"","sources":["../../src/client/fusion-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAK7D,sDAAsD;AACtD,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,KAAK,CAAC,MAAM,G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MAAM,CAErB;IAED;;;;;;;;;OASG;IACG,KAAK,CAAC,CAAC,SAAS,MAAM,EAC1B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,SAAS,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,EACvC,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAwChC;;;;;;OAMG;IACG,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA6BrF;;;;;OAKG;YACW,gBAAgB;IAmH9B,OAAO,CAAC,KAAK;CAGd;AAED;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,MAAM,EACnD,IAAI,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,SAAS,GAC9C,iBAAiB,CAAC,CAAC,CAAC,CAqBtB;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,iBAAiB,GAAG,MAAM,CAUnE;AAED,mFAAmF;AACnF,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEpD"}
|
|
@@ -97,10 +97,12 @@ export class FusionClient {
|
|
|
97
97
|
* FusionGraphQLError when the response carries errors and no usable data,
|
|
98
98
|
* and a plain Error for transport failures. The transient partnerPreferences
|
|
99
99
|
* fault is retried up to transientAttempts times; every other GraphQL-layer
|
|
100
|
-
* error surfaces at once.
|
|
100
|
+
* error surfaces at once. options.timeoutMs replaces the per-attempt timeout
|
|
101
|
+
* for this call, for an operation known to run longer (a Search results page).
|
|
101
102
|
*/
|
|
102
|
-
async query(tenantId, document, variables = {}) {
|
|
103
|
+
async query(tenantId, document, variables = {}, options = {}) {
|
|
103
104
|
const token = await this.tokenManager.getToken();
|
|
105
|
+
const timeoutMs = options.timeoutMs ?? this.timeoutMs;
|
|
104
106
|
const fetchOptions = {
|
|
105
107
|
method: "POST",
|
|
106
108
|
headers: {
|
|
@@ -113,7 +115,7 @@ export class FusionClient {
|
|
|
113
115
|
};
|
|
114
116
|
const mutation = isMutation(document);
|
|
115
117
|
for (let attempt = 1;; attempt++) {
|
|
116
|
-
const body = await this.executeWithRetry(fetchOptions, mutation);
|
|
118
|
+
const body = await this.executeWithRetry(fetchOptions, mutation, timeoutMs);
|
|
117
119
|
try {
|
|
118
120
|
return interpretGraphQLBody(body);
|
|
119
121
|
}
|
|
@@ -174,12 +176,12 @@ export class FusionClient {
|
|
|
174
176
|
* mutation that failed that way may already have taken effect (a case
|
|
175
177
|
* created, evidence attached), so it is not repeated.
|
|
176
178
|
*/
|
|
177
|
-
async executeWithRetry(options, mutation = false) {
|
|
179
|
+
async executeWithRetry(options, mutation = false, timeoutMs = this.timeoutMs) {
|
|
178
180
|
let lastError = null;
|
|
179
181
|
for (let attempt = 0; attempt <= this.retries; attempt++) {
|
|
180
182
|
try {
|
|
181
183
|
const controller = new AbortController();
|
|
182
|
-
const timeout = setTimeout(() => controller.abort(),
|
|
184
|
+
const timeout = setTimeout(() => controller.abort(), timeoutMs);
|
|
183
185
|
let response;
|
|
184
186
|
try {
|
|
185
187
|
// A redirect is refused rather than followed: the request carries the tenant's ID and the query or mutation to the new host.
|
|
@@ -232,7 +234,7 @@ export class FusionClient {
|
|
|
232
234
|
catch (error) {
|
|
233
235
|
lastError =
|
|
234
236
|
error instanceof Error && error.name === "AbortError"
|
|
235
|
-
? new Error(`Sophos Fusion API request timed out after ${
|
|
237
|
+
? new Error(`Sophos Fusion API request timed out after ${timeoutMs}ms`)
|
|
236
238
|
: error instanceof Error
|
|
237
239
|
? error
|
|
238
240
|
: new Error(String(error));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fusion-client.js","sourceRoot":"","sources":["../../src/client/fusion-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,yBA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,IAAI,CAAC,GAAG,CAAC,CAAC;AACzB,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,UAAU,CAAC,QAAgB;IACzC,OAAO,8BAA8B,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AACvD,CAAC"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Endpoint inventory from the Fusion Data Lake: the QL for the softwareinfo,
|
|
3
|
+
* patchstate and inventoryinfo schemas, the reduction to each device's latest
|
|
4
|
+
* snapshot, and the stale flag from the Endpoint API's lastSeenAt.
|
|
5
|
+
*
|
|
6
|
+
* Measured on two tenants, 03/11/2026:
|
|
7
|
+
* - host_id is the Endpoint API endpoint ID (sensor_id carries the same value),
|
|
8
|
+
* so it joins to lastSeenAt exactly. Hostnames do not: one tenant had five
|
|
9
|
+
* endpoint records named DC01, and a re-registered device keeps its old
|
|
10
|
+
* host_id rows under the same hostname as the new record.
|
|
11
|
+
* - The snapshot rows have no last seen of their own: device.last_seen_time is
|
|
12
|
+
* null, and the Endpoint API record embedded in inventoryinfo's
|
|
13
|
+
* original_data has no lastSeenAt.
|
|
14
|
+
* - A tenant writes one snapshot batch a day. Rows of one device's snapshot
|
|
15
|
+
* sit within a few milliseconds of each other; snapshots are a day apart.
|
|
16
|
+
* - Snapshots keep coming for 30 days after a device was last seen (three
|
|
17
|
+
* devices on two tenants), rebuilt from its last report.
|
|
18
|
+
* - Results come back newest first, and a search returns at most 10,000 rows
|
|
19
|
+
* (an aggregate counted 16,098 where the rows search stopped at 10,000).
|
|
20
|
+
* - inventoryinfo also holds device_discovery events from the telemetry
|
|
21
|
+
* normalizer: another device the endpoint saw on its network, filed under
|
|
22
|
+
* the reporting endpoint's host_id. They are not snapshots, so the QL drops
|
|
23
|
+
* them.
|
|
24
|
+
*/
|
|
25
|
+
export declare const INVENTORY_SCHEMAS: readonly ["softwareinfo", "patchstate", "inventoryinfo"];
|
|
26
|
+
export type InventorySchema = (typeof INVENTORY_SCHEMAS)[number];
|
|
27
|
+
/** The normalizer that files device_discovery events into inventoryinfo. */
|
|
28
|
+
export declare const DISCOVERY_NORMALIZER = "sophos-xdr-telemetry-normalizer";
|
|
29
|
+
/** Rows of one snapshot are milliseconds apart and snapshots a day apart. */
|
|
30
|
+
export declare const SNAPSHOT_SPREAD_MS: number;
|
|
31
|
+
/** A search returns at most this many rows. */
|
|
32
|
+
export declare const MAX_SEARCH_ROWS = 10000;
|
|
33
|
+
export declare const DAY_MS: number;
|
|
34
|
+
export interface InventoryFilters {
|
|
35
|
+
endpointId?: string;
|
|
36
|
+
hostname?: string;
|
|
37
|
+
softwareName?: string;
|
|
38
|
+
kb?: string;
|
|
39
|
+
}
|
|
40
|
+
export interface InventoryWindow {
|
|
41
|
+
earliest: string;
|
|
42
|
+
latest: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Absolute bounds ending at the next whole UTC hour. getOrCreateSearch reuses
|
|
46
|
+
* a search only for absolute bounds, so every call in the same hour gets the
|
|
47
|
+
* same search: paging and a retry after a timeout cost nothing.
|
|
48
|
+
*/
|
|
49
|
+
export declare function inventoryWindow(now: number, days: number): InventoryWindow;
|
|
50
|
+
/** One row per device and hostname: its newest row time and its row count. */
|
|
51
|
+
export declare function buildDevicesQl(schema: InventorySchema, filters: InventoryFilters, window: InventoryWindow): string;
|
|
52
|
+
/** The rows, projected to the fields the tool returns. */
|
|
53
|
+
export declare function buildRowsQl(schema: InventorySchema, filters: InventoryFilters, window: InventoryWindow): string;
|
|
54
|
+
/** A field by its dotted name, from a flat key or the nested objects. */
|
|
55
|
+
export declare function pick(row: Record<string, unknown>, path: string): unknown;
|
|
56
|
+
/** Epoch milliseconds to ISO 8601, or null. */
|
|
57
|
+
export declare function msToIso(value: unknown): string | null;
|
|
58
|
+
export interface InventoryDevice {
|
|
59
|
+
hostId: string;
|
|
60
|
+
hostname: string | null;
|
|
61
|
+
sensorType: string | null;
|
|
62
|
+
maxTime: number;
|
|
63
|
+
rowCount: number;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Merges the aggregate rows into one entry per host_id. A renamed device has
|
|
67
|
+
* a row per hostname; the newest row names it.
|
|
68
|
+
*/
|
|
69
|
+
export declare function mergeDeviceAggregates(rows: Array<Record<string, unknown>>): Map<string, InventoryDevice>;
|
|
70
|
+
/**
|
|
71
|
+
* The time below which every device's latest snapshot has been read: rows
|
|
72
|
+
* come newest first, so once a row older than this arrives, reading can stop.
|
|
73
|
+
*/
|
|
74
|
+
export declare function readFloor(devices: Iterable<InventoryDevice>): number | null;
|
|
75
|
+
export interface LatestSnapshot {
|
|
76
|
+
/** The snapshot's newest row time, epoch milliseconds. */
|
|
77
|
+
time: number;
|
|
78
|
+
rows: Array<Record<string, unknown>>;
|
|
79
|
+
/** Every row of the snapshot was read, so rows is the whole snapshot. */
|
|
80
|
+
complete: boolean;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Keeps each device's latest snapshot: its rows within SNAPSHOT_SPREAD_MS of
|
|
84
|
+
* the device's newest row read. readAll says the search had no more rows. Rows
|
|
85
|
+
* come newest first, so a device's snapshot is complete once a row older than
|
|
86
|
+
* the snapshot was read; a device whose rows were not reached has no entry,
|
|
87
|
+
* and one cut off part way has complete false.
|
|
88
|
+
*/
|
|
89
|
+
export declare function latestSnapshots(rows: Array<Record<string, unknown>>, readAll: boolean): Map<string, LatestSnapshot>;
|
|
90
|
+
export type DeviceStatus = "fresh" | "stale" | "unmatched";
|
|
91
|
+
export interface LastSeen {
|
|
92
|
+
status: DeviceStatus;
|
|
93
|
+
daysSinceSeen: number | null;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Stale when the endpoint was last seen more than staleAfterDays ago, fresh
|
|
97
|
+
* otherwise, unmatched when there is no lastSeenAt to judge by.
|
|
98
|
+
*/
|
|
99
|
+
export declare function classifyLastSeen(lastSeenAt: string | null | undefined, now: number, staleAfterDays: number): LastSeen;
|
|
100
|
+
/** Endpoint API lookups take UUIDs only; anything else is a third-party ID. */
|
|
101
|
+
export declare function lookupIds(hostIds: Iterable<string>): string[];
|
|
102
|
+
/** "KB5007651" from a patch title, or null. */
|
|
103
|
+
export declare function kbFromTitle(title: string | null): string | null;
|
|
104
|
+
/** The fields the tool returns for one row of each schema. */
|
|
105
|
+
export declare function compactRow(schema: InventorySchema, row: Record<string, unknown>): Record<string, unknown>;
|
|
106
|
+
/** A device's compact rows by name and version, or KB, title and install time; nulls last. */
|
|
107
|
+
export declare function sortRows<T extends Record<string, unknown>>(schema: InventorySchema, rows: T[]): T[];
|
|
108
|
+
/** Stale first, then unmatched, then fresh; by hostname, then endpoint ID, within each. */
|
|
109
|
+
export declare function compareDevices(a: {
|
|
110
|
+
status: DeviceStatus;
|
|
111
|
+
hostname: string | null;
|
|
112
|
+
endpoint_id: string;
|
|
113
|
+
}, b: {
|
|
114
|
+
status: DeviceStatus;
|
|
115
|
+
hostname: string | null;
|
|
116
|
+
endpoint_id: string;
|
|
117
|
+
}): number;
|
|
118
|
+
//# sourceMappingURL=inventory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inventory.d.ts","sourceRoot":"","sources":["../../src/fusion/inventory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAIH,eAAO,MAAM,iBAAiB,0DAA2D,CAAC;AAC1F,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEjE,4EAA4E;AAC5E,eAAO,MAAM,oBAAoB,oCAAoC,CAAC;AAEtE,6EAA6E;AAC7E,eAAO,MAAM,kBAAkB,QAAiB,CAAC;AAEjD,+CAA+C;AAC/C,eAAO,MAAM,eAAe,QAAS,CAAC;AAEtC,eAAO,MAAM,MAAM,QAAsB,CAAC;AAwB1C,MAAM,WAAW,gBAAgB;IAC/B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MA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EAAE,CAcnG;AAID,2FAA2F;AAC3F,wBAAgB,cAAc,CAC5B,CAAC,EAAE;IAAE,MAAM,EAAE,YAAY,CAAC;IAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,EACzE,CAAC,EAAE;IAAE,MAAM,EAAE,YAAY,CAAC;IAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,GACxE,MAAM,CAMR"}
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Endpoint inventory from the Fusion Data Lake: the QL for the softwareinfo,
|
|
3
|
+
* patchstate and inventoryinfo schemas, the reduction to each device's latest
|
|
4
|
+
* snapshot, and the stale flag from the Endpoint API's lastSeenAt.
|
|
5
|
+
*
|
|
6
|
+
* Measured on two tenants, 03/11/2026:
|
|
7
|
+
* - host_id is the Endpoint API endpoint ID (sensor_id carries the same value),
|
|
8
|
+
* so it joins to lastSeenAt exactly. Hostnames do not: one tenant had five
|
|
9
|
+
* endpoint records named DC01, and a re-registered device keeps its old
|
|
10
|
+
* host_id rows under the same hostname as the new record.
|
|
11
|
+
* - The snapshot rows have no last seen of their own: device.last_seen_time is
|
|
12
|
+
* null, and the Endpoint API record embedded in inventoryinfo's
|
|
13
|
+
* original_data has no lastSeenAt.
|
|
14
|
+
* - A tenant writes one snapshot batch a day. Rows of one device's snapshot
|
|
15
|
+
* sit within a few milliseconds of each other; snapshots are a day apart.
|
|
16
|
+
* - Snapshots keep coming for 30 days after a device was last seen (three
|
|
17
|
+
* devices on two tenants), rebuilt from its last report.
|
|
18
|
+
* - Results come back newest first, and a search returns at most 10,000 rows
|
|
19
|
+
* (an aggregate counted 16,098 where the rows search stopped at 10,000).
|
|
20
|
+
* - inventoryinfo also holds device_discovery events from the telemetry
|
|
21
|
+
* normalizer: another device the endpoint saw on its network, filed under
|
|
22
|
+
* the reporting endpoint's host_id. They are not snapshots, so the QL drops
|
|
23
|
+
* them.
|
|
24
|
+
*/
|
|
25
|
+
import { isUuid, qlString } from "./format.js";
|
|
26
|
+
export const INVENTORY_SCHEMAS = ["softwareinfo", "patchstate", "inventoryinfo"];
|
|
27
|
+
/** The normalizer that files device_discovery events into inventoryinfo. */
|
|
28
|
+
export const DISCOVERY_NORMALIZER = "sophos-xdr-telemetry-normalizer";
|
|
29
|
+
/** Rows of one snapshot are milliseconds apart and snapshots a day apart. */
|
|
30
|
+
export const SNAPSHOT_SPREAD_MS = 10 * 60 * 1000;
|
|
31
|
+
/** A search returns at most this many rows. */
|
|
32
|
+
export const MAX_SEARCH_ROWS = 10_000;
|
|
33
|
+
export const DAY_MS = 24 * 60 * 60 * 1000;
|
|
34
|
+
const HOUR_MS = 60 * 60 * 1000;
|
|
35
|
+
/**
|
|
36
|
+
* Leaf fields each schema's rows search projects. QL returns the whole parent
|
|
37
|
+
* object of a nested leaf (all of device for device.hostname), and refuses
|
|
38
|
+
* device.storage_volumes, so the volumes are read from the device object.
|
|
39
|
+
*/
|
|
40
|
+
const COMMON_FIELDS = ["host_id", "time", "sensor_type", "device.hostname", "device.os.name"];
|
|
41
|
+
const SCHEMA_FIELDS = {
|
|
42
|
+
softwareinfo: ["product.name", "product.version", "product.vendor_name", "install_time"],
|
|
43
|
+
patchstate: ["kb_article.title", "kb_article.install_time", "actor.user.name"],
|
|
44
|
+
inventoryinfo: [
|
|
45
|
+
"device.os.version",
|
|
46
|
+
"device.os.last_update_time",
|
|
47
|
+
"device.boot_time",
|
|
48
|
+
"device.domain",
|
|
49
|
+
"device.type_id",
|
|
50
|
+
"device.is_domain_controller",
|
|
51
|
+
"device.mac",
|
|
52
|
+
"device.ip",
|
|
53
|
+
],
|
|
54
|
+
};
|
|
55
|
+
/** Whole-second UTC ISO 8601, the absolute bound form QL takes. */
|
|
56
|
+
function isoSeconds(ms) {
|
|
57
|
+
return new Date(ms).toISOString().replace(/\.\d{3}Z$/, "Z");
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Absolute bounds ending at the next whole UTC hour. getOrCreateSearch reuses
|
|
61
|
+
* a search only for absolute bounds, so every call in the same hour gets the
|
|
62
|
+
* same search: paging and a retry after a timeout cost nothing.
|
|
63
|
+
*/
|
|
64
|
+
export function inventoryWindow(now, days) {
|
|
65
|
+
const latest = Math.ceil(now / HOUR_MS) * HOUR_MS;
|
|
66
|
+
return { earliest: isoSeconds(latest - days * DAY_MS), latest: isoSeconds(latest) };
|
|
67
|
+
}
|
|
68
|
+
/** The where clause and time bounds both searches share. */
|
|
69
|
+
function baseQl(schema, filters, window) {
|
|
70
|
+
if (filters.softwareName !== undefined && schema !== "softwareinfo") {
|
|
71
|
+
throw new Error("software_name filters softwareinfo only.");
|
|
72
|
+
}
|
|
73
|
+
if (filters.kb !== undefined && schema !== "patchstate") {
|
|
74
|
+
throw new Error("kb filters patchstate only.");
|
|
75
|
+
}
|
|
76
|
+
const where = [`normalizer != ${qlString(DISCOVERY_NORMALIZER)}`];
|
|
77
|
+
if (filters.endpointId !== undefined)
|
|
78
|
+
where.push(`host_id = ${qlString(filters.endpointId)}`);
|
|
79
|
+
if (filters.hostname !== undefined)
|
|
80
|
+
where.push(`device.hostname contains ${qlString(filters.hostname)}`);
|
|
81
|
+
if (filters.softwareName !== undefined)
|
|
82
|
+
where.push(`product.name contains ${qlString(filters.softwareName)}`);
|
|
83
|
+
if (filters.kb !== undefined)
|
|
84
|
+
where.push(`kb_article.title contains ${qlString(filters.kb)}`);
|
|
85
|
+
return `from ${schema} where ${where.join(" and ")} earliest='${window.earliest}' latest='${window.latest}'`;
|
|
86
|
+
}
|
|
87
|
+
/** One row per device and hostname: its newest row time and its row count. */
|
|
88
|
+
export function buildDevicesQl(schema, filters, window) {
|
|
89
|
+
return `${baseQl(schema, filters, window)} | aggregate max(time), count by host_id, device.hostname, sensor_type`;
|
|
90
|
+
}
|
|
91
|
+
/** The rows, projected to the fields the tool returns. */
|
|
92
|
+
export function buildRowsQl(schema, filters, window) {
|
|
93
|
+
return `${baseQl(schema, filters, window)} | fields ${[...COMMON_FIELDS, ...SCHEMA_FIELDS[schema]].join(", ")}`;
|
|
94
|
+
}
|
|
95
|
+
/** A field by its dotted name, from a flat key or the nested objects. */
|
|
96
|
+
export function pick(row, path) {
|
|
97
|
+
if (path in row)
|
|
98
|
+
return row[path];
|
|
99
|
+
let value = row;
|
|
100
|
+
for (const part of path.split(".")) {
|
|
101
|
+
if (value === null || typeof value !== "object")
|
|
102
|
+
return undefined;
|
|
103
|
+
value = value[part];
|
|
104
|
+
}
|
|
105
|
+
return value;
|
|
106
|
+
}
|
|
107
|
+
function toNumber(value) {
|
|
108
|
+
const n = typeof value === "number" ? value : typeof value === "string" && value.trim() !== "" ? Number(value) : NaN;
|
|
109
|
+
return Number.isFinite(n) ? n : null;
|
|
110
|
+
}
|
|
111
|
+
function str(value) {
|
|
112
|
+
return typeof value === "string" && value.trim() !== "" ? value.trim() : null;
|
|
113
|
+
}
|
|
114
|
+
/** Epoch milliseconds to ISO 8601, or null. */
|
|
115
|
+
export function msToIso(value) {
|
|
116
|
+
const n = toNumber(value);
|
|
117
|
+
return n === null || n <= 0 ? null : new Date(n).toISOString();
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Merges the aggregate rows into one entry per host_id. A renamed device has
|
|
121
|
+
* a row per hostname; the newest row names it.
|
|
122
|
+
*/
|
|
123
|
+
export function mergeDeviceAggregates(rows) {
|
|
124
|
+
const devices = new Map();
|
|
125
|
+
for (const row of rows) {
|
|
126
|
+
const hostId = str(row.host_id);
|
|
127
|
+
const maxTime = toNumber(row.max_time);
|
|
128
|
+
if (!hostId || maxTime === null)
|
|
129
|
+
continue;
|
|
130
|
+
const count = toNumber(row.row_count) ?? 0;
|
|
131
|
+
const hostname = str(row.device_hostname ?? pick(row, "device.hostname"));
|
|
132
|
+
const sensorType = str(row.sensor_type);
|
|
133
|
+
const known = devices.get(hostId);
|
|
134
|
+
if (!known) {
|
|
135
|
+
devices.set(hostId, { hostId, hostname, sensorType, maxTime, rowCount: count });
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
known.rowCount += count;
|
|
139
|
+
if (maxTime > known.maxTime || (maxTime === known.maxTime && !known.hostname)) {
|
|
140
|
+
known.maxTime = maxTime;
|
|
141
|
+
known.hostname = hostname ?? known.hostname;
|
|
142
|
+
known.sensorType = sensorType ?? known.sensorType;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return devices;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* The time below which every device's latest snapshot has been read: rows
|
|
149
|
+
* come newest first, so once a row older than this arrives, reading can stop.
|
|
150
|
+
*/
|
|
151
|
+
export function readFloor(devices) {
|
|
152
|
+
let floor = null;
|
|
153
|
+
for (const device of devices) {
|
|
154
|
+
const start = device.maxTime - SNAPSHOT_SPREAD_MS;
|
|
155
|
+
floor = floor === null ? start : Math.min(floor, start);
|
|
156
|
+
}
|
|
157
|
+
return floor;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Keeps each device's latest snapshot: its rows within SNAPSHOT_SPREAD_MS of
|
|
161
|
+
* the device's newest row read. readAll says the search had no more rows. Rows
|
|
162
|
+
* come newest first, so a device's snapshot is complete once a row older than
|
|
163
|
+
* the snapshot was read; a device whose rows were not reached has no entry,
|
|
164
|
+
* and one cut off part way has complete false.
|
|
165
|
+
*/
|
|
166
|
+
export function latestSnapshots(rows, readAll) {
|
|
167
|
+
const newest = new Map();
|
|
168
|
+
let oldestRead = Infinity;
|
|
169
|
+
for (const row of rows) {
|
|
170
|
+
const hostId = str(row.host_id);
|
|
171
|
+
const time = toNumber(row.time);
|
|
172
|
+
if (!hostId || time === null)
|
|
173
|
+
continue;
|
|
174
|
+
oldestRead = Math.min(oldestRead, time);
|
|
175
|
+
newest.set(hostId, Math.max(newest.get(hostId) ?? time, time));
|
|
176
|
+
}
|
|
177
|
+
const out = new Map();
|
|
178
|
+
for (const row of rows) {
|
|
179
|
+
const hostId = str(row.host_id);
|
|
180
|
+
const time = toNumber(row.time);
|
|
181
|
+
if (!hostId || time === null)
|
|
182
|
+
continue;
|
|
183
|
+
const newestTime = newest.get(hostId);
|
|
184
|
+
const start = newestTime - SNAPSHOT_SPREAD_MS;
|
|
185
|
+
if (time < start)
|
|
186
|
+
continue;
|
|
187
|
+
let snapshot = out.get(hostId);
|
|
188
|
+
if (!snapshot) {
|
|
189
|
+
snapshot = { time: newestTime, rows: [], complete: readAll || oldestRead < start };
|
|
190
|
+
out.set(hostId, snapshot);
|
|
191
|
+
}
|
|
192
|
+
snapshot.rows.push(row);
|
|
193
|
+
}
|
|
194
|
+
return out;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Stale when the endpoint was last seen more than staleAfterDays ago, fresh
|
|
198
|
+
* otherwise, unmatched when there is no lastSeenAt to judge by.
|
|
199
|
+
*/
|
|
200
|
+
export function classifyLastSeen(lastSeenAt, now, staleAfterDays) {
|
|
201
|
+
const seen = lastSeenAt ? Date.parse(lastSeenAt) : NaN;
|
|
202
|
+
if (!Number.isFinite(seen))
|
|
203
|
+
return { status: "unmatched", daysSinceSeen: null };
|
|
204
|
+
const age = now - seen;
|
|
205
|
+
return {
|
|
206
|
+
status: age > staleAfterDays * DAY_MS ? "stale" : "fresh",
|
|
207
|
+
daysSinceSeen: Math.round((age / DAY_MS) * 10) / 10,
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
/** Endpoint API lookups take UUIDs only; anything else is a third-party ID. */
|
|
211
|
+
export function lookupIds(hostIds) {
|
|
212
|
+
return [...new Set([...hostIds].filter(isUuid))];
|
|
213
|
+
}
|
|
214
|
+
/** "KB5007651" from a patch title, or null. */
|
|
215
|
+
export function kbFromTitle(title) {
|
|
216
|
+
const match = title?.match(/\bKB\d{6,8}\b/i);
|
|
217
|
+
return match ? match[0].toUpperCase() : null;
|
|
218
|
+
}
|
|
219
|
+
/** The fields the tool returns for one row of each schema. */
|
|
220
|
+
export function compactRow(schema, row) {
|
|
221
|
+
if (schema === "softwareinfo") {
|
|
222
|
+
return {
|
|
223
|
+
name: str(pick(row, "product.name")),
|
|
224
|
+
version: str(pick(row, "product.version")),
|
|
225
|
+
vendor: str(pick(row, "product.vendor_name")),
|
|
226
|
+
installed_at: msToIso(pick(row, "install_time")),
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
if (schema === "patchstate") {
|
|
230
|
+
const title = str(pick(row, "kb_article.title"));
|
|
231
|
+
return {
|
|
232
|
+
kb: kbFromTitle(title),
|
|
233
|
+
title,
|
|
234
|
+
installed_at: msToIso(pick(row, "kb_article.install_time")),
|
|
235
|
+
installed_by: str(pick(row, "actor.user.name")),
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
const volumes = pick(row, "device.storage_volumes");
|
|
239
|
+
return {
|
|
240
|
+
os: str(pick(row, "device.os.name")),
|
|
241
|
+
os_version: str(pick(row, "device.os.version")),
|
|
242
|
+
os_last_update_at: msToIso(pick(row, "device.os.last_update_time")),
|
|
243
|
+
boot_time: msToIso(pick(row, "device.boot_time")),
|
|
244
|
+
domain: str(pick(row, "device.domain")),
|
|
245
|
+
device_type: str(pick(row, "device.type_id")),
|
|
246
|
+
is_domain_controller: pick(row, "device.is_domain_controller") ?? null,
|
|
247
|
+
mac: str(pick(row, "device.mac")),
|
|
248
|
+
ip: str(pick(row, "device.ip")),
|
|
249
|
+
storage_volumes: Array.isArray(volumes)
|
|
250
|
+
? volumes.map((v) => ({
|
|
251
|
+
uid: str(v?.uid),
|
|
252
|
+
encryption_status: str(v?.encryption_status_id),
|
|
253
|
+
}))
|
|
254
|
+
: null,
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
const ROW_ORDER = {
|
|
258
|
+
softwareinfo: ["name", "version"],
|
|
259
|
+
patchstate: ["kb", "title", "installed_at"],
|
|
260
|
+
inventoryinfo: [],
|
|
261
|
+
};
|
|
262
|
+
/** A device's compact rows by name and version, or KB, title and install time; nulls last. */
|
|
263
|
+
export function sortRows(schema, rows) {
|
|
264
|
+
const keys = ROW_ORDER[schema];
|
|
265
|
+
return [...rows].sort((a, b) => {
|
|
266
|
+
for (const key of keys) {
|
|
267
|
+
const x = a[key];
|
|
268
|
+
const y = b[key];
|
|
269
|
+
if (x === y)
|
|
270
|
+
continue;
|
|
271
|
+
if (x === null || x === undefined)
|
|
272
|
+
return 1;
|
|
273
|
+
if (y === null || y === undefined)
|
|
274
|
+
return -1;
|
|
275
|
+
const order = String(x).localeCompare(String(y), "en", { sensitivity: "base", numeric: true });
|
|
276
|
+
if (order !== 0)
|
|
277
|
+
return order;
|
|
278
|
+
}
|
|
279
|
+
return 0;
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
const STATUS_ORDER = { stale: 0, unmatched: 1, fresh: 2 };
|
|
283
|
+
/** Stale first, then unmatched, then fresh; by hostname, then endpoint ID, within each. */
|
|
284
|
+
export function compareDevices(a, b) {
|
|
285
|
+
return (STATUS_ORDER[a.status] - STATUS_ORDER[b.status] ||
|
|
286
|
+
(a.hostname ?? "").localeCompare(b.hostname ?? "", "en", { sensitivity: "base" }) ||
|
|
287
|
+
a.endpoint_id.localeCompare(b.endpoint_id));
|
|
288
|
+
}
|
|
289
|
+
//# sourceMappingURL=inventory.js.map
|