AzureのLogAnayticsやAzureDataExplorlerで利用するKQL(Kusto Query Language)をまとめてみました。
AzureDataExplorlerで利用するにはテーブル名が異なるかもしれないですが、クエリ自体の参考はなるかと思います。
- 1.LogAnalyticsでよく利用するKQL
- 1-1. ActivityLog で削除操作のログを表示
- 1-2. SigninLog でログイン失敗したログを表示
- 1-3. AzureFW で特定期間内でdenyされたログを表示
- 1-4. AzureFW のネットワークルールで特定のIP,特定アクションのログを表示
- 1-5. AzureFW のアプリケーションルールで特定のFQDN,特定ルールのログを表示
- 1-6. AplicationGateway のアクセスログで特定IPのステータス200以外のログを表示
- 1-7. AplicationGateway のアクセスログでバックエンドからの応答がないログを表示
- 1-8. AplicationGateway のFirewallログで特定IPのステータス200以外のログを表示
- 1-9. summarize で件数の合計値を表示
- 1-10. extend を利用して常に先月の期間を指定して出力
- 1-11. Windows のログインログを表示
- 1-12. Syslog を表示
- 1-13. Heartbeat ログを表示
- 1-14. M365のログを表示
- 1-15. blobの操作ログを表示
1.LogAnalyticsでよく利用するKQL
下記のコマンドは基本的に project を利用して個人的に必要な情報のみを出力しています。
1-1. ActivityLog で削除操作のログを表示
OerationNameValue に ”delete” が含まれるログを出力します。
また、IPアドレスでもフィルタをかけています。
AzureActivity
| where OperationNameValue contains "delete"
| where CallerIpAddress contains "1.1."
| project TimeGenerated, OperationNameValue, ResourceGroup, Caller, CallerIpAddress, Properties
1-2. SigninLog でログイン失敗したログを表示
ログイン成功以外のログを表示させるため、ResultType が 0 以外の結果を出力しています。
SigninLogs
| where OperationName == "Sign-in activity"
| where ResultType != 0
| project TimeGenerated, OperationName, ResultSignature, ResultType, IPAddress, Status, UserDisplayName, UserId, UserPrincipalName
1-3. AzureFW で特定期間内でdenyされたログを表示
AzureFirewallPolicyを利用した際のクエリになります。
AzureDiagnostics
| where TimeGenerated between (datetime("2025-09-24 00:00:00.000+09:00") .. datetime("2025-09-25 00:00:00.000+09:00"))
| where Action_s contains "deny"
1-4. AzureFW のネットワークルールで特定のIP,特定アクションのログを表示
AzureFirewallPolicyを利用した際のクエリになります。
AzureDiagnostics
| where TimeGenerated between (datetime("2025-09-24 00:00:00.000+09:00") .. datetime("2025-09-25 00:00:00.000+09:00"))
| where Category == "AZFWNetworkRule"
| where DestinationIp_s contains "23.192."
| where Action_s contains "allow"
1-5. AzureFW のアプリケーションルールで特定のFQDN,特定ルールのログを表示
AzureFirewallPolicyを利用した際のクエリになります。
AzureDiagnostics
| where TimeGenerated between (datetime("2025-09-24 00:00:00.000+09:00") .. datetime("2025-09-25 00:00:00.000+09:00"))
| where Category == "AZFWApplicationRule"
| where Fqdn_s contains "yahoo.co.jp"
| where Rule_s contains "Allow-Internet"
1-6. AplicationGateway のアクセスログで特定IPのステータス200以外のログを表示
Firewallログと異なり、ClientIP(Pが大文字)なのでその点だけ注意が必要です。
AzureDiagnostics
| where TimeGenerated between (datetime("2025-09-10 00:00:00.000+09:00") .. datetime("2025-09-11 00:00:00.000+09:00"))
| where Category == "ApplicationGatewayAccessLog"
| where ClientIP contains "1.1.1.1"
| where httpStatus_d != 200
1-7. AplicationGateway のアクセスログでバックエンドからの応答がないログを表示
基本的にはバックエンドのserverStatusには値が入っていますが、ApplicationGateway自体の障害時などにはserverStatusに値が入らなくなることがあります。
その状態のログを判断するためのクエリです。
AzureDiagnostics
| where TimeGenerated between (datetime("2025-09-10 00:00:00.000+09:00") .. datetime("2025-09-11 00:00:00.000+09:00"))
| where Category == "ApplicationGatewayAccessLog"
| where serverStatus_d == "-" or serverStatus_d == ""
| where httpStatus_d >= 500
1-8. AplicationGateway のFirewallログで特定IPのステータス200以外のログを表示
アクセスログと異なり、ClientIp(pが小文字)なのでその点だけ注意が必要です。
AzureDiagnostics
| where TimeGenerated between (datetime("2025-09-10 00:00:00.000+09:00") .. datetime("2025-09-11 00:00:00.000+09:00"))
| where Category == "ApplicationGatewayFirewallLog"
| where ClientIp contains "1.1.1.1"
| where httpStatus_d != 200
1-9. summarize で件数の合計値を表示
summarize を利用して合計値を表示できます。
今回は AzureFirewallログの AZFWApplicationRule のログ数の合計値を表示しています。
AzureDiagnostics
| where TimeGenerated between (datetime("2025-09-24 00:00:00.000+09:00") .. datetime("2025-09-25 00:00:00.000+09:00"))
| where Category == "AZFWApplicationRule"
| summarize count() by Category
1-10. extend を利用して常に先月の期間を指定して出力
extend を利用して常に先月の期間を指定して出力できます。
毎月自動実行するクエリなどで利用すると楽です。
今回はサインインログを対象にしています。
SigninLogs
| extend today_month_Y = datetime_part("Year",now())
| extend last_month_Y = datetime_part("Year",now(-20d))
| extend today_M = datetime_part("Month",now())
| extend last_M = datetime_part("Month",now(-20d))
| extend now_day1 = strcat(tostring(today_month_Y), "-", tostring(today_M), "-", "01", "T23:59:59+09:00")
| extend last_month_day1 = strcat(tostring(last_month_Y), "-", tostring(last_M), "-", "01", "T00:00:00+09:00")
| extend date_now_day1 = todatetime(now_day1)
| extend date_last_month_day1 = todatetime(last_month_day1)
| extend last_Month_end_day = date_now_day1 - 1d
| extend startDate = date_last_month_day1
| extend endDate = last_Month_end_day
| where TimeGenerated between(startDate .. endDate)
| where OperationName == "Sign-in activity"
1-11. Windows のログインログを表示
ログイン成功は4624、ログイン失敗は4625のイベントIDとなるため、それらの項目で絞って出力させます。
Event
| where EventID == 4624 or EventID == 4625
| project TimeGenerated, Source, EventLog, EventLevel, EventData, EventID, RenderedDescription, EventCategory
1-12. Syslog を表示
仮想マシンの名前で絞って出力しています。
Syslog
| where Computer contains "vm"
| project TimeGenerated, SourceSystem, Computer, Facility, HostName, SeverityLevel, SyslogMessage, ProcessID, HostIP
1-13. Heartbeat ログを表示
出力させる項目だけ絞って出力しています。
Heartbeat
| project TimeGenerated, Computer, ComputerIP, ComputerPrivateIPs, OSType, OSName, OSMajorVersion, OSMinorVersion, Version, ResourceGroup, Resource, VMUUID
1-14. M365のログを表示
SharePointOnlineのファイルアップロード/ダウンロードのログも見ることができます。
OfficeActivity
1-15. blobの操作ログを表示
blobのファイルを表示、もしくはダウンロードしたログを表示できます。
StorageBlobLogs
| where OperationName contains "Get"
| project TimeGenerated, AccountName, StatusCode, StatusText, Uri, CallerIpAddress, ObjectKey, LastModifiedTime, Category
なお、ファイルストレージのログは StorageFileLogs を利用すると確認できます。