Query compliance data
Prepare queries for current compliance results, historical outcomes, and framework mappings.
Before You Begin
Arrange BigQuery access. Replace YOUR_PROJECT, YOUR_CE_DATASET, and YOUR_CMDB_DATASET with your export identifiers. Run each example separately in a GoogleSQL editor.
The examples use a seven-day window. Adjust it to the available evaluations. An empty result does not establish compliance. LIMIT restricts displayed rows, not bytes scanned. See the dataset schema for fields and record grain.
Query Current Results
This example selects the latest recorded output time within the window for the EC2 detailed-monitoring policy, then finds violations and adds inventory context. It selects a whole policy evaluation rather than each resource's latest historical observation.
WITH recent_output AS (
SELECT policyId, runTime, object.id AS resource_id, status, remediationMessage
FROM `YOUR_PROJECT.YOUR_CE_DATASET.PolicyOutput`
WHERE policyId = '/ce/ca/aws/ec2/instance-detailed-monitoring'
AND runTime >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 7 DAY)
AND runTime < CURRENT_TIMESTAMP()
), latest_output AS (
SELECT *
FROM recent_output
WHERE runTime = (SELECT MAX(runTime) FROM recent_output)
)
SELECT
policy_output.policyId,
policy_output.runTime,
policy_output.resource_id,
instance.Name AS resource_name,
instance.CA10__instanceId__c AS instance_id,
policy_output.status,
policy_output.remediationMessage
FROM latest_output AS policy_output
LEFT JOIN `YOUR_PROJECT.YOUR_CMDB_DATASET.CA10__CaAwsInstance__c` AS instance
ON policy_output.resource_id = instance.Id
WHERE policy_output.status = 'INCOMPLIANT'
ORDER BY policy_output.resource_id
LIMIT 100;
The left join preserves results without matching inventory records. Inventory attributes may reflect a different time from the evaluation. To select a completed run and inspect its snapshot time, use Find your first policy result.
Compare Historical Outcomes
Replace YOUR_RESOURCE_ID with the CMDB ID of one resource. This query compares consecutive observations inside the selected window:
SELECT
policyId,
object.id AS resource_id,
runTime,
status,
LAG(status) OVER (ORDER BY runTime) AS previous_observed_status,
statusDate,
currentStateMessage
FROM `YOUR_PROJECT.YOUR_CE_DATASET.PolicyOutput`
WHERE policyId = '/ce/ca/aws/ec2/instance-detailed-monitoring'
AND object.id = 'YOUR_RESOURCE_ID'
AND runTime >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 7 DAY)
AND runTime < CURRENT_TIMESTAMP()
ORDER BY runTime DESC
LIMIT 100;
The first chronological observation has no preceding status in this window; that does not mean the resource has no earlier history. Use statusDate to distinguish a status change from a repeated evaluation.
Query Framework Mappings
Sections describes framework hierarchy; SectionPolicies associates policies with sections. Discover the available columns before writing a mapping join:
SELECT table_name, column_name, data_type
FROM `YOUR_PROJECT.YOUR_CE_DATASET.INFORMATION_SCHEMA.COLUMNS`
WHERE table_name IN ('Sections', 'SectionPolicies', 'FrameworksWithMappedCePolicies')
ORDER BY table_name, ordinal_position;
The dataset also lists CeFindings and CeFindingsTrend. Inspect all three reporting view definitions:
SELECT table_name, view_definition
FROM `YOUR_PROJECT.YOUR_CE_DATASET.INFORMATION_SCHEMA.VIEWS`
WHERE table_name IN (
'FrameworksWithMappedCePolicies',
'CeFindings',
'CeFindingsTrend'
)
ORDER BY table_name;
After confirming the exported keys, join policy associations to section identifiers and filter the intended framework version. Mapping column names and view filters are not established here, so a complete mapping join requires export verification. Keep multiple associations from duplicating resource counts. See Review framework coverage.
Review Run Health
Review execution separately from resource status:
SELECT policyId, runTime, snapshotTime, completed, stats
FROM `YOUR_PROJECT.YOUR_CE_DATASET.PolicyRun`
WHERE policyId = '/ce/ca/aws/ec2/instance-detailed-monitoring'
AND runTime >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 7 DAY)
AND runTime < CURRENT_TIMESTAMP()
ORDER BY runTime DESC
LIMIT 20;
Completion does not mean every resource passed. Investigate missing or unsuccessful evaluations through Review policy runs before interpreting reporting gaps.
Prepare Downstream Reporting and Audit Evidence
Retain the query, time window, policy ID, resource ID, and run time with exported evidence. Include snapshot time when joining run context. State whether a report counts resources, policy-resource outcomes, executions, or control mappings.
Check view definitions, inventory timing, and join multiplicity before reusing a query in a dashboard or scheduled report. Keep unmapped controls, undetermined outcomes, and absent evaluations distinguishable from compliant results. Confirm export refresh and history availability with your Technical Account Manager (TAM).