按状态对资产进行分组

演示如何按状态变化对资产进行分组

代码示例

Python

如需向 Security Command Center 进行身份验证,请设置应用默认凭据。 如需了解详情,请参阅为本地开发环境设置身份验证

from datetime import timedelta

from google.cloud import securitycenter

client = securitycenter.SecurityCenterClient()

duration = timedelta(days=5)

# 'parent' must be in one of the following formats:
#   "organizations/{organization_id}"
#   "projects/{project_id}"
#   "folders/{folder_id}"
parent = f"organizations/{organization_id}"
result_iterator = client.group_assets(
    request={
        "parent": parent,
        "group_by": "state_change",
        "compare_duration": duration,
    }
)
for i, result in enumerate(result_iterator):
    print((i + 1), result)

后续步骤

如需搜索和过滤其他 Google Cloud 产品的代码示例,请参阅 Google Cloud 示例浏览器