Skip to content

Fix DeviceId column name in list_file_events_for_host queries - #968

Open
Guillermo Tosetti (GTosetti) wants to merge 1 commit into
microsoft:mainfrom
GTosetti:fix/mde-file-events-host-deviceid
Open

Guillermo Tosetti (GTosetti) wants to merge 1 commit into
microsoft:mainfrom
GTosetti:fix/mde-file-events-host-deviceid

Conversation

@GTosetti

Copy link
Copy Markdown

MDE.list_file_events_for_host, MDATP.list_file_events_for_host (same source as MDE) and M365D.list_file_events_for_host filter on DeviceID (kql_mdatp_file.yaml#L135, kql_m365_file.yaml#L84). The column in DeviceFileEvents is DeviceId (table reference), and KQL identifiers are case-sensitive (entity names).

With host_name="host1" and device_id="0123456789abcdef" the query renders as:

DeviceFileEvents | where Timestamp >= datetime(2024-01-01T00:00:00+00:00) | where Timestamp <= datetime(2024-01-02T00:00:00+00:00) | where DeviceName == "host1" or DeviceID == "0123456789abcdef"

The column name does not resolve, so the query cannot compile, whichever of the two parameters is passed. The M365DGraph and MSSentinel providers load the same m365d file. The line has been in place since #680 (555b58a).

The change fixes the column name in both files. It also adds a test in tests/data/drivers/test_odata_drivers.py that renders the query with the print option for the MDE and M365D families.

Running python -m pytest tests/data/drivers/test_odata_drivers.py -k file_events_for_host before the change gives 2 failed; after it, 2 passed. The whole file gives 46 passed, 1 skipped. The rendered MDATP, MDE and M365D queries were also checked with Microsoft.Azure.Kusto.Language 12.4.1, using the DeviceFileEvents columns from the table reference. Before the change it reports diagnostic KS142, The name 'DeviceID' does not refer to any known column, table, variable or function., for each one; after it, no errors.

Not checked: the queries were not run against a Defender or Sentinel workspace.

Prepared with Claude Code (AI-assisted).

🤖 Generated with Claude Code

The MDE, MDATP and M365D list_file_events_for_host queries filtered on
DeviceID. The DeviceFileEvents column is DeviceId and KQL column names
are case-sensitive, so the query failed to compile whatever host name
or device ID was passed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant