検出結果の時間別でのグループ化

特定の時点での検出結果をグループ化する方法を示します。

コードサンプル

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 のサンプルをご覧ください。