From 491cc9da4588b2491317039394866df88f8f3f67 Mon Sep 17 00:00:00 2001 From: Guillermo Tosetti <158747755+GTosetti@users.noreply.github.com> Date: Sun, 29 Nov 2026 19:46:48 -0300 Subject: [PATCH] Fix DeviceId column name in list_file_events_for_host queries 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. --- msticpy/data/queries/m365d/kql_m365_file.yaml | 2 +- msticpy/data/queries/mde/kql_mdatp_file.yaml | 2 +- tests/data/drivers/test_odata_drivers.py | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/msticpy/data/queries/m365d/kql_m365_file.yaml b/msticpy/data/queries/m365d/kql_m365_file.yaml index 6d4c3e68a..52a6f3785 100644 --- a/msticpy/data/queries/m365d/kql_m365_file.yaml +++ b/msticpy/data/queries/m365d/kql_m365_file.yaml @@ -81,7 +81,7 @@ sources: {table} | where {time_column} >= datetime({start}) | where {time_column} <= datetime({end}) - | where DeviceName == "{host_name}" or DeviceID == "{device_id}" + | where DeviceName == "{host_name}" or DeviceId == "{device_id}" {add_query_items}' uri: None parameters: diff --git a/msticpy/data/queries/mde/kql_mdatp_file.yaml b/msticpy/data/queries/mde/kql_mdatp_file.yaml index 75415ce5b..016eb3a54 100644 --- a/msticpy/data/queries/mde/kql_mdatp_file.yaml +++ b/msticpy/data/queries/mde/kql_mdatp_file.yaml @@ -132,7 +132,7 @@ sources: {table} | where {time_column} >= datetime({start}) | where {time_column} <= datetime({end}) - | where DeviceName == "{host_name}" or DeviceID == "{device_id}" + | where DeviceName == "{host_name}" or DeviceId == "{device_id}" {add_query_items}' uri: None parameters: diff --git a/tests/data/drivers/test_odata_drivers.py b/tests/data/drivers/test_odata_drivers.py index 9b0ad5323..3e12e7448 100644 --- a/tests/data/drivers/test_odata_drivers.py +++ b/tests/data/drivers/test_odata_drivers.py @@ -5,6 +5,7 @@ # -------------------------------------------------------------------------- """Miscellaneous data provider driver tests.""" import sys +from datetime import datetime, timezone from unittest.mock import Mock, patch import pandas as pd @@ -79,6 +80,23 @@ def test_MDE_driver(env, api, cloud: None): check.greater_equal(len(qry_prov.list_queries()), 40) +@pytest.mark.parametrize("family", ["MDE", "M365D"]) +def test_mde_file_events_for_host_query(family): + """Test list_file_events_for_host filters on the DeviceId column.""" + with custom_mp_config(MP_PATH): + qry_prov = QueryProvider("MDE") + query = getattr(qry_prov, family).list_file_events_for_host( + "print", + host_name="host1", + device_id="0123456789abcdef", + start=datetime(2024, 1, 1, tzinfo=timezone.utc), + end=datetime(2024, 1, 2, tzinfo=timezone.utc), + ) + # KQL column names are case-sensitive and the table column is DeviceId + check.is_in('DeviceId == "0123456789abcdef"', query) + check.is_not_in("DeviceID", query) + + # Test helper functions for MDE tests def _mde_pre_checks(mde_drv, api): check.is_instance(mde_drv, MDATPDriver)