问题
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