按时间对发现结果进行分组

演示如何对特定时间点的发现结果进行分组

代码示例

Python

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

from datetime import datetime, timedelta

from google.cloud import securitycenter

# Create a client.
client = securitycenter.SecurityCenterClient()

# 'source_name' is the resource path for a source that has been
# created previously (you can use list_sources to find a specific one).
# Its format is:
# source_name = "{parent}/sources/{source_id}"
# 'parent' must be in one of the following formats:
#   "organizations/{organization_id}"
#   "projects/{project_id}"
#   "folders/{folder_id}"
# source_name = "organizations/111122222444/sources/1234"

# Group findings as of yesterday.
read_time = datetime.utcnow() - timedelta(days=1)

group_result_iterator = client.group_findings(
    request={"parent": source_name, "group_by": "category", "read_time": read_time}
)
for i, group_result in enumerate(group_result_iterator):
    print((i + 1), group_result)

后续步骤

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