使用篩選器將發現項目分組

示範如何依屬性篩選及分組發現項目

程式碼範例

Python

如要向 Security Command Center 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。

from google.cloud import securitycenter_v1

# Create a client.
client = securitycenter_v1.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_result_iterator = client.group_findings(
    request={
        "parent": source_name,
        "group_by": "category",
        "filter": 'state="ACTIVE"',
    }
)
for i, group_result in enumerate(group_result_iterator):
    print((i + 1), group_result)

後續步驟

如要搜尋及篩選其他 Google Cloud 產品的程式碼範例,請參閱Google Cloud 範例瀏覽器