Query Details

02 Overview Source Availability Strip

Query

// REVIEW ONLY - AWS Security Operations Workbook Visual Query
// Tab: Overview | Panel: source-availability-strip | Visualization: table | Mode: All
// Security Question: Which AWS telemetry sources are healthy, delayed, experiencing connector errors, or completely disconnected right now?
// Drill-Through: Switch to Tab 2 (Data Health) for per-account SLA lag and SentinelHealth error reasons.
// Empty/No-Data Contract: Unexpected empty state: ExpectedCatalog always emits 7 rows even when zero AWS tables exist.
let Start = {TimeRange:start};
let End = {TimeRange:end};
let OrgFilter = base64_decode_tostring("{Organization:base64}");
let AccountFilter = base64_decode_tostring("{AwsAccount:base64}");
let RegionFilter = base64_decode_tostring("{AwsRegion:base64}");
let EnvFilter = base64_decode_tostring("{Environment:base64}");
let WorkloadFilter = base64_decode_tostring("{Workload:base64}");
let SeverityFilter = base64_decode_tostring("{Severity:base64}");
let SourceFilter = base64_decode_tostring("{SourceTable:base64}");
let SummaryPref = base64_decode_tostring("{SummaryMode:base64}");
let SelectedPrincipalFilter = base64_decode_tostring("{SelectedPrincipal:base64}");
let SelectedIpFilter = base64_decode_tostring("{SelectedIp:base64}");
let ExpectedCatalog = datatable(SourceTable:string, DefaultFreshnessMin:real, DefaultZeroVolMin:real)[
    "AWSCloudTrail", 30.0, 180.0,
    "AWSGuardDuty", 60.0, 720.0,
    "AWSVPCFlow", 30.0, 120.0,
    "AWSRoute53Resolver", 30.0, 120.0,
    "AWSWAF", 30.0, 180.0,
    "AWSNetworkFirewallAlert", 60.0, 720.0,
    "AWSCloudWatch", 60.0, 360.0
];
let SlaOverrides = union isfuzzy=true
    (datatable(SearchKey:string)[]),
    (_GetWatchlist('AWS_SourceSlaConfig'))
| where isnotempty(tostring(column_ifexists("SearchKey", "")))
| where tolower(tostring(column_ifexists("Enabled", ""))) == "true"
| summarize OverrideFreshness=min(todouble(column_ifexists("ExpectedFreshnessMinutes", ""))),
    OverrideZeroVol=min(todouble(column_ifexists("ZeroVolumeAlertMinutes", "")))
    by SourceTable=tostring(column_ifexists("SourceTable", ""));
let ObservedUnion = union isfuzzy=true
    (datatable(SourceTable:string, TimeGenerated:datetime, Received:datetime, Account:string, Region:string, Billed:real)[]),
    (AWSCloudTrail | where TimeGenerated between (Start .. End)
        | where AccountFilter == "*" or RecipientAccountId == AccountFilter or UserIdentityAccountId == AccountFilter
        | where RegionFilter == "*" or AWSRegion == RegionFilter
        | project SourceTable="AWSCloudTrail", TimeGenerated, Received=todatetime(column_ifexists("_TimeReceived", TimeGenerated)), Account=RecipientAccountId, Region=AWSRegion, Billed=todouble(_BilledSize)),
    (AWSGuardDuty | where TimeGenerated between (Start .. End)
        | where AccountFilter == "*" or AccountId == AccountFilter
        | where RegionFilter == "*" or Region == RegionFilter
        | project SourceTable="AWSGuardDuty", TimeGenerated, Received=todatetime(column_ifexists("_TimeReceived", TimeGenerated)), Account=AccountId, Region, Billed=todouble(_BilledSize)),
    (AWSVPCFlow | where TimeGenerated between (Start .. End)
        | where AccountFilter == "*" or AccountId == AccountFilter
        | where RegionFilter == "*" or Region == RegionFilter
        | project SourceTable="AWSVPCFlow", TimeGenerated, Received=todatetime(column_ifexists("_TimeReceived", TimeGenerated)), Account=AccountId, Region, Billed=todouble(_BilledSize)),
    (AWSRoute53Resolver | where TimeGenerated between (Start .. End)
        | where AccountFilter == "*" or AccountId == AccountFilter
        | where RegionFilter == "*" or Region == RegionFilter
        | project SourceTable="AWSRoute53Resolver", TimeGenerated, Received=todatetime(column_ifexists("_TimeReceived", TimeGenerated)), Account=AccountId, Region, Billed=todouble(_BilledSize)),
    (AWSWAF | where TimeGenerated between (Start .. End)
        | project SourceTable="AWSWAF", TimeGenerated, Received=todatetime(column_ifexists("_TimeReceived", TimeGenerated)), Account=WebAclId, Region=HttpSourceName, Billed=todouble(_BilledSize)),
    (AWSNetworkFirewallAlert | where TimeGenerated between (Start .. End)
        | project SourceTable="AWSNetworkFirewallAlert", TimeGenerated, Received=todatetime(column_ifexists("_TimeReceived", TimeGenerated)), Account=FirewallName, Region=AvailabilityZone, Billed=todouble(_BilledSize)),
    (AWSCloudWatch | where TimeGenerated between (Start .. End)
        | project SourceTable="AWSCloudWatch", TimeGenerated, Received=todatetime(column_ifexists("_TimeReceived", TimeGenerated)), Account="CloudWatchStream", Region="*", Billed=todouble(_BilledSize))
| summarize EventsInWindow=count(), DistinctAccounts=dcount(Account), DistinctRegions=dcount(Region),
    LastEventUtc=max(TimeGenerated), LastReceivedUtc=max(Received),
    P50LagMin=round(max_of(0.0, percentile(datetime_diff('second', Received, TimeGenerated), 50)) / 60.0, 1),
    P95LagMin=round(max_of(0.0, percentile(datetime_diff('second', Received, TimeGenerated), 95)) / 60.0, 1),
    BillableGB=round(sum(Billed) / 1073741824.0, 3)
    by SourceTable;
let HealthErrs = union isfuzzy=true
    (datatable(TimeGenerated:datetime, SentinelResourceType:string, Status:string, SentinelResourceKind:string, SentinelResourceName:string, Reason:string)[]),
    (SentinelHealth
     | where TimeGenerated between (Start .. End)
     | project TimeGenerated, SentinelResourceType, Status, SentinelResourceKind, SentinelResourceName, Reason)
| where SentinelResourceType == "DataConnector" and Status in ("Failure", "Warning", "Partial Success")
| where SentinelResourceKind has_any ("AmazonWebServices", "AWS") or SentinelResourceName has_any ("AWS", "Amazon")
| summarize AwsConnectorErrors=count(), ErrorReasons=make_set(Reason, 5);
ExpectedCatalog
| where SourceFilter == "*" or SourceTable == SourceFilter
| join kind=leftouter SlaOverrides on SourceTable
| join kind=leftouter ObservedUnion on SourceTable
| extend Dummy = 1
| join kind=leftouter (HealthErrs | extend Dummy = 1) on Dummy
| extend TargetFreshnessMin = coalesce(OverrideFreshness, DefaultFreshnessMin),
    TargetZeroVolMin = coalesce(OverrideZeroVol, DefaultZeroVolMin),
    FreshnessMin = iff(isnull(LastEventUtc), 999999.0, round(datetime_diff('second', now(), LastEventUtc) / 60.0, 1))
| extend SourceStatus = case(
    coalesce(EventsInWindow, 0) == 0 and coalesce(AwsConnectorErrors, 0) > 0, "🔴 CONNECTOR_ERROR",
    coalesce(EventsInWindow, 0) == 0, "🟡 NOT_CONNECTED_OR_NO_DATA",
    FreshnessMin > TargetZeroVolMin, "🔴 STALE_BLIND_SPOT",
    FreshnessMin > TargetFreshnessMin or coalesce(P95LagMin, 0.0) > TargetFreshnessMin, "🟠 DELAYED",
    "🟢 HEALTHY")
| project SourceTable, SourceStatus, EventsInWindow=coalesce(EventsInWindow, 0),
    DistinctAccounts=coalesce(DistinctAccounts, 0), DistinctRegions=coalesce(DistinctRegions, 0),
    FreshnessMin=iff(FreshnessMin == 999999.0, -1.0, FreshnessMin), TargetFreshnessMin,
    P95LagMin=coalesce(P95LagMin, 0.0), BillableGB=coalesce(BillableGB, 0.0),
    AwsConnectorErrors=coalesce(AwsConnectorErrors, 0)
| order by SourceTable asc
| take 5000

Explanation

This query is designed to assess the current health status of various AWS telemetry sources. It checks if these sources are healthy, delayed, experiencing connector errors, or completely disconnected. Here's a simplified breakdown of what the query does:

  1. Time and Filters Setup: It begins by setting up time ranges and various filters (like organization, account, region, environment, workload, severity, source, etc.) based on encoded parameters.

  2. Expected Catalog: It defines a list of expected AWS telemetry sources (like AWSCloudTrail, AWSGuardDuty, etc.) along with their default freshness and zero-volume thresholds.

  3. SLA Overrides: It checks for any overrides to the default thresholds using a watchlist, allowing for customized settings per source.

  4. Data Collection: It gathers data from various AWS sources within the specified time range, applying the filters set earlier. It calculates metrics like the number of events, distinct accounts and regions, the time of the last event, and data lag.

  5. Health Errors: It collects any errors related to AWS data connectors from SentinelHealth, focusing on failures, warnings, or partial successes.

  6. Status Evaluation: For each source, it determines the current status:

    • 🔴 CONNECTOR_ERROR: No events and connector errors are present.
    • 🟡 NOT_CONNECTED_OR_NO_DATA: No events and no connector errors.
    • 🔴 STALE_BLIND_SPOT: Data is older than the zero-volume threshold.
    • 🟠 DELAYED: Data is delayed beyond the freshness threshold.
    • 🟢 HEALTHY: Data is within acceptable limits.
  7. Output: It outputs a table with the source name, status, number of events, distinct accounts and regions, freshness, lag, billable data size, and connector errors, sorted by source name.

This query helps in monitoring the health of AWS telemetry data sources, identifying issues, and ensuring data is being received and processed in a timely manner.