首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GCP安全命令中心API -如何获得source_properties

问GCP安全命令中心API -如何获得source_properties
EN

Stack Overflow用户
提问于 2022-03-24 22:12:06
回答 1查看 176关注 0票数 0

当你在谷歌控制台,安全指挥中心,发现,你可以点击一个项目来查看详细信息。有一节列出了“属性”和“源属性”。我想得到这些价值中的一些。下面的代码取自此页面(https://cloud.google.com/security-command-center/docs/how-to-api-list-findings),并对其进行了修改,以获得我需要的内容:

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

client = securitycenter.SecurityCenterClient()
organization_id = "<my organization id>"
org_name = "organizations/{org_id}".format(org_id=organization_id)
finding_result_iterator = client.list_findings(request={"parent": all_sources, "filter": 'severity="HIGH"'})
for i, finding_result in enumerate(finding_result_iterator):
    sourceId = finding_result.finding.resource_name
    title = finding_result.finding.category
    alertTime = finding_result.finding.event_time
    serviceName = finding_result.resource.type_
    description = ""
    additionalInfo = ""

我想从Source获得“解释”和“推荐”值,但我不知道从哪里得到它们。参考页显示循环中每个finding_result的输出。控制台显示这些属性,但我不知道如何获得它们,我一直在网上搜索答案。我希望这里有人知道答案。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-03-25 21:26:46

所以,我对我的问题有点不耐烦,不管是在这里还是在谷歌的支持下。当我加强我的电话过滤器,我发现记录确实有两个值,我正在寻找。对于那些感兴趣的人,我已经包括了一些无用的测试代码如下。

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

client = securitycenter.SecurityCenterClient()

organization_id = "<my org id>"
org_name = "organizations/{org_id}".format(org_id=organization_id)
all_sources = "{org_name}/sources/-".format(org_name=org_name)
finding_result_iterator = client.list_findings(request={"parent": all_sources, "filter": 'severity="HIGH" AND state="ACTIVE" AND category!="Persistence: IAM Anomalous Grant" AND category!="MFA_NOT_ENFORCED"'})
for i, finding_result in enumerate(finding_result_iterator):
    sourceId = finding_result.finding.resource_name
    projectId = finding_result.resource.project_display_name
    title = finding_result.finding.category
    alertTime = finding_result.finding.event_time
    serviceName = finding_result.resource.type_
    description = ""
    additionalInfo = ""
    externalUri = ""
    if hasattr(finding_result.finding,"external_uri"):
        externalUri = finding_result.finding.external_uri
    sourceProps = finding_result.finding.source_properties
 
    for item in sourceProps:
        if (item == "Explanation"):
            description = str(sourceProps[item])
        if (item == "Recommendation"):
            additionalInfo = str(sourceProps[item])

    print("TITLE: " + title)
    print("   PROJECT ID: " + projectId)
    print("   DESCRIPTION: " + description)
    print("   SOURCE ID: " + sourceId)
    print("   ALERT TIME: {}".format(alertTime))
    print("   SERVICE NAME: " + serviceName)
    print("   ADDITIONAL INFO: Recommendation: " + additionalInfo)
    if len(externalUri) > 0:
        print(", External URI: " + externalUri)

    if i < 1:
        break

因此,虽然这个问题有点浪费,但代码可能会帮助其他人尝试使用。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71610058

复制
相关文章

相似问题

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