首页 > 解决方案 > 如何编写 Kusto 查询以在哨兵中获取上个月的日志?

问题描述

| where TimeGenerated > ago(30d) 只给我最近 30 天的日志,我正在搜索查询以从表中获取上个月的日志,因此我可以将其直接导出到 Power BI。

标签: azurepowerbipowerquerykqlazure-sentinel

解决方案


下面是如何做到这一点。我展示了两种方式。'简单'的方法是把当月的日期塞进去。更难的方法需要您使用该make_datetime功能。

// The Easy 'Manual' Way
AuditLogs
| where TimeGenerated >= datetime('2021-08-01') and TimeGenerated <= datetime('2021-08-31')
// Automated Way
let lastmonth = getmonth(datetime(now)) -1;
let year = getyear(datetime(now)); 
let monthEnd = endofmonth(datetime(now),-1); 
AuditLogs
| where TimeGenerated >= make_datetime(year,lastmonth,01) and TimeGenerated <= monthEnd

https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/make-datetimefunction


推荐阅读