首页 > 解决方案 > 从查询中获取输出并在后续 KQL 查询中使用

问题描述

我正在使用 Azure Log Analytics 来查看某些感兴趣的事件。

我想从满足特定标准的数据中获取时间戳,然后在进一步的查询中重用这些时间戳,即查看这些时间周围还发生了什么。

以下查询返回所需的结果,但我不知道如何使用interestingTimesvar 然后在每个先前返回的时间戳的 X 分钟内执行进一步的搜索并显示数据。

let interestingTimes = 
Event
| where TimeGenerated between (datetime(2021-04-01T11:57:22) .. datetime('2021-04-01T15:00:00'))
| where EventID == 1
| parse EventData with * '<Data Name="Image">' ImageName "<" *
| where ImageName contains "MicrosoftEdge.exe"
| project TimeGenerated
;

任何指针将不胜感激。

标签: azure-log-analyticskqlazure-sentinel

解决方案


interestingTimes只能在您声明它的查询中使用。您不能在另一个查询中使用它,除非您也在那里定义它。

顺便说一句,您可以通过添加一个过滤器来提高查询效率,该过滤器将利用列的内置索引EventData,以便parse操作符在更少的记录上运行:

let interestingTimes = 
Event
| where TimeGenerated between (datetime(2021-04-01T11:57:22) .. datetime('2021-04-01T15:00:00'))
| where EventID == 1
| where EventData has "MicrosoftEdge.exe" // <-- OPTIMIZATION that will filter out most records
| parse EventData with * '<Data Name="Image">' ImageName "<" *
| where ImageName contains "MicrosoftEdge.exe"
| project TimeGenerated
;

推荐阅读