0

与此类似:如何通过云功能将 GCP 的安全中心资产导出到云存储?

我需要将 Security Command Center 中的结果导出到 BigQuery,以便我们可以轻松过滤所需的数据并生成自定义报告。

以本文档为例(https://cloud.google.com/security-command-center/docs/how-to-api-list-findings#python),我写了以下内容:

from google.cloud import securitycenter
from google.cloud import bigquery

JSONPath = "Path to JSON File For Service Account"
client = securitycenter.SecurityCenterClient().from_service_account_json(JSONPath)
BQclient = bigquery.Client().from_service_account_json(JSONPath)
table_id = "project.security_center.assets"
org_name = "organizations/1234567891011"
all_sources = "{org_name}/sources/-".format(org_name=org_name)
finding_result_iterator = client.list_findings(request={"parent": all_sources})
for i, finding_result in enumerate(finding_result_iterator):
    errors = BQclient.insert_rows_json(table_id, finding_result)
    if errors == []:
        print("New rows have been added.")
    else:
        print("Encountered errors while inserting rows: {}".format(errors))

但是,这给了我错误:

“json_rows 参数应该是一个字典序列”。

对此的任何帮助将不胜感激:)

4

1 回答 1

0

我设法通过以下方式对其进行排序:

for i, finding_result in enumerate(finding_result_iterator):
rows_to_insert = [
    {u"category": finding_result.finding.category, u"name": finding_result.finding.name, u"project": finding_result.resource.project_display_name, u"external_uri": finding_result.finding.external_uri},
]
于 2021-04-29T11:23:16.723 回答