D04 Awsvpcflow Schema Check
Query
// REVIEW ONLY - Mandatory Step 1: AWSVPCFlow Schema & v2-v5 Custom Format Field Population Check
// Critical: AWS VPC Flow Logs v2 omits FlowDirection, PktSrcAddr, PktDstAddr, PktDstAwsService, SublocationType, TcpFlags.
// Run this query first to verify whether your VPC Flow Log format populates v3-v5 enrichment columns!
AWSVPCFlow
| where TimeGenerated > ago(24h)
| summarize
TotalFlows = count(),
VersionsObserved = make_set(Version, 10),
LogStatuses = make_set(LogStatus, 10),
HasVpcIdPct = round(100.0 * countif(isnotempty(column_ifexists("VpcId", ""))) / count(), 1),
HasFlowDirectionPct = round(100.0 * countif(isnotempty(column_ifexists("FlowDirection", ""))) / count(), 1),
HasPktDstAddrPct = round(100.0 * countif(isnotempty(column_ifexists("PktDstAddr", ""))) / count(), 1),
HasAwsServiceTagPct = round(100.0 * countif(isnotempty(column_ifexists("PktDstAwsService", ""))) / count(), 1),
HasTcpFlagsPct = round(100.0 * countif(isnotnull(TcpFlags)) / count(), 1),
HasEcsMetadataPct = round(100.0 * countif(isnotempty(column_ifexists("EcsClusterName", ""))) / count(), 1)
by AccountId, Region
| order by TotalFlows desc
| take 200Explanation
This KQL (Kusto Query Language) query is designed to analyze AWS VPC Flow Logs over the past 24 hours. Here's a simplified breakdown of what it does:
-
Data Source: It queries the
AWSVPCFlowtable, which contains AWS VPC Flow Logs. -
Time Frame: The query focuses on logs generated in the last 24 hours.
-
Summarization: It summarizes the data by
AccountIdandRegion, calculating several metrics:TotalFlows: The total number of flow log entries.VersionsObserved: A set of different versions of flow logs observed, limited to 10 unique versions.LogStatuses: A set of different log statuses observed, limited to 10 unique statuses.HasVpcIdPct: The percentage of log entries that have a non-emptyVpcIdfield.HasFlowDirectionPct: The percentage of log entries that have a non-emptyFlowDirectionfield.HasPktDstAddrPct: The percentage of log entries that have a non-emptyPktDstAddrfield.HasAwsServiceTagPct: The percentage of log entries that have a non-emptyPktDstAwsServicefield.HasTcpFlagsPct: The percentage of log entries that have a non-nullTcpFlagsfield.HasEcsMetadataPct: The percentage of log entries that have a non-emptyEcsClusterNamefield.
-
Sorting and Limiting: The results are ordered by
TotalFlowsin descending order, and only the top 200 results are returned.
The purpose of this query is to verify whether the VPC Flow Log format includes certain enrichment columns (like FlowDirection, PktDstAddr, etc.) and to provide a summary of the data completeness for these fields across different AWS accounts and regions.