首页 > 解决方案 > 通过 python SDK 获取 Azure 安全中心警报

问题描述

我想使用 python SDK 列出 azure 安全中心警报。

我找到了这个包: https ://pypi.org/project/azure-mgmt-security/

它必须包含在 microsoft 文档中:

https://docs.microsoft.com/en-gb/python/azure/?view=azure-python https://github.com/Azure/azure-sdk-for-python

但我找不到任何参考或示例。

有谁知道我在哪里可以找到这些信息?

此致。

标签: pythonazureazure-sdk-pythonsecuritycenter

解决方案


我只能提供一个粗略的参考。

安装包azure-mgmt-security后,你应该使用List包中的方法,源代码在这里

这是有关如何进行身份验证的文档。这是有关如何获取tenantId / client_id / key的文档。

这是我的代码:

from azure.mgmt.security import SecurityCenter
from azure.common.credentials import ServicePrincipalCredentials

subscription_id = "xxxx"

# Tenant ID for your Azure subscription
TENANT_ID = '<Your tenant ID>'

# Your service principal App ID
CLIENT = '<Your service principal ID>'

# Your service principal password
KEY = '<Your service principal password>'

credentials = ServicePrincipalCredentials(
    client_id = CLIENT,
    secret = KEY,
    tenant = TENANT_ID
)

client = SecurityCenter(credentials=credentials,subscription_id=subscription_id,asc_location="centralus")
client.alerts.list()

此外,您可以在 python 中将List Alerts api与 http 请求一起使用。


推荐阅读