【问题标题】:Get Azure Security Center alerts via python SDK通过 python SDK 获取 Azure 安全中心警报
【发布时间】:2021-02-16 22:50:20
【问题描述】:

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

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

它必须包含在微软文档中:

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

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

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

最好的问候。

【问题讨论】:

  • 我已经更新了我的代码。如果有帮助,请您在guide 之后帮助将其标记为答案?谢谢。

标签: python azure azure-sdk-python securitycenter


【解决方案1】:

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

安装包azure-mgmt-security后,应使用包中的List方法,源代码为here

这里是关于如何认证的doc。 这里是doc关于如何获取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 请求一起使用。

【讨论】:

    【解决方案2】:

    截至 2021 年 2 月的今天,Microsoft 再次更改了凭据的实例化方式。这是当前的:

    from azure.identity import DefaultAzureCredential
    
    # Acquire a credential object for the app identity. When running in the cloud,
    # DefaultAzureCredential uses the app's managed identity (MSI) or user-assigned service principal.
    # When run locally, DefaultAzureCredential relies on environment variables named
    # AZURE_CLIENT_ID, AZURE_CLIENT_SECRET, and AZURE_TENANT_ID.
    
    credential = DefaultAzureCredential()
    

    而且它还改变了SecurityCenter签名,credentials参数被重命名为credential,没有“s”。

    完整文档here

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-15
      • 2020-01-06
      • 2011-11-21
      • 1970-01-01
      • 2021-01-19
      • 2019-04-10
      • 1970-01-01
      • 2013-12-14
      相关资源
      最近更新 更多