首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Google Security Command Center -如何以JSON格式导出调查结果

Google Security Command Center -如何以JSON格式导出调查结果
EN

Stack Overflow用户
提问于 2020-07-17 00:58:57
回答 1查看 193关注 0票数 0

使用此示例:

代码语言:javascript
复制
from google.cloud import securitycenter

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

# organization_id is the numeric ID of the organization. e.g.:
# organization_id = "111122222444"
org_name = "organizations/{org_id}".format(org_id=organization_id)
# The "sources/-" suffix lists findings across all sources.  You
# also use a specific source_name instead.
all_sources = "{org_name}/sources/-".format(org_name=org_name)
finding_result_iterator = client.list_findings(all_sources)
for i, finding_result in enumerate(finding_result_iterator):
    print(
        "{}: name: {} resource: {}".format(
            i, finding_result.finding.name, finding_result.finding.resource_name
        )
    )

我想将所有查找结果导出为'google.cloud.securitycenter_v1.types.Finding‘数组,但是类型(finding_result.finding)返回: class JSON

使用json.dumps(finding_result.finding)会导致错误,表明它是不可序列化的。

使用gcloud SDK可以通过指定"--format json“来实现。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-04-05 20:08:07

我想通了。

您必须添加以下导入from google.cloud.securitycenter import ListFindingsResponse

然后在循环中添加以下代码行

ListFindingsResponse.ListFindingsResult.to_json(finding_result)

因此,解决方案应该如下所示

代码语言:javascript
复制
from google.cloud import securitycenter
from google.cloud.securitycenter import ListFindingsResponse

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

# organization_id is the numeric ID of the organization. e.g.:
# organization_id = "111122222444"
org_name = "organizations/{org_id}".format(org_id=organization_id)
# The "sources/-" suffix lists findings across all sources.  You
# also use a specific source_name instead.
all_sources = "{org_name}/sources/-".format(org_name=org_name)
finding_result_iterator = client.list_findings(all_sources)
for i, finding_result in enumerate(finding_result_iterator):
    print(
        ListFindingsResponse.ListFindingsResult.to_json(finding_result)
    )
    print(
        "{}: name: {} resource: {}".format(
            i, finding_result.finding.name, finding_result.finding.resource_name
        )
    )
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62939790

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档