如何编写 Kusto 查询以获取哨兵中的上个月日志?

How to write a Kusto query to get previous month logs in sentinel?

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

下面是您的操作方法。我展示了两种方式。 'easy' 方法是手动填入当月的日期。更难的方法需要您使用 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