Group assets by state

Demonstrates how to group assets by state change

Code sample


from datetime import timedelta

from import securitycenter

client = securitycenter.SecurityCenterClient()

duration = timedelta(days=5)

# organization_id is the numeric ID of the organization.
# organization_id = "1234567777"
org_name = "organizations/{org_id}".format(org_id=organization_id)
result_iterator = client.group_assets(
        "parent": org_name,
        "group_by": "state_change",
        "compare_duration": duration,
for i, result in enumerate(result_iterator):
    print((i + 1), result)

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.