Query Details

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 200

Explanation

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:

  1. Data Source: It queries the AWSVPCFlow table, which contains AWS VPC Flow Logs.

  2. Time Frame: The query focuses on logs generated in the last 24 hours.

  3. Summarization: It summarizes the data by AccountId and Region, 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-empty VpcId field.
    • HasFlowDirectionPct: The percentage of log entries that have a non-empty FlowDirection field.
    • HasPktDstAddrPct: The percentage of log entries that have a non-empty PktDstAddr field.
    • HasAwsServiceTagPct: The percentage of log entries that have a non-empty PktDstAwsService field.
    • HasTcpFlagsPct: The percentage of log entries that have a non-null TcpFlags field.
    • HasEcsMetadataPct: The percentage of log entries that have a non-empty EcsClusterName field.
  4. Sorting and Limiting: The results are ordered by TotalFlows in 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.