Agrupar resultados con filtro

Muestra cómo filtrar y agrupar resultados por propiedades

Código de ejemplo

Python

Para autenticarte en Security Command Center, configura las credenciales predeterminadas de la aplicación. Para obtener más información, consulta el artículo Configurar la autenticación en un entorno de desarrollo local.

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)

Siguientes pasos

Para buscar y filtrar ejemplos de código de otros Google Cloud productos, consulta el Google Cloud navegador de ejemplos.