Get Azure Security Center alerts via python SDK

醉酒当歌 提交于 2021-01-29 10:43:41

问题


I want to list azure security center alerts using the python SDK.

I found this package: https://pypi.org/project/azure-mgmt-security/

It must be included in the microsoft documentation:

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

but I can not find any reference or example.

Does anyone know where I can find this information?

Best regards.


回答1:


I can just give a rough reference.

After install the package azure-mgmt-security, you should use List method in the package, source code is here.

Here is the the doc on how to authentication. Here is doc on how to get tenantId / client_id / key.

Here is my code:

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()

Also, you can use List Alerts api with a http request in python.



来源:https://stackoverflow.com/questions/56768159/get-azure-security-center-alerts-via-python-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!