我想使用 python SDK 列出 azure 安全中心警报。
我找到了这个包:https://pypi.org/project/azure-mgmt-security/ https://pypi.org/project/azure-mgmt-security/
它必须包含在微软文档中:
https://learn.microsoft.com/en-gb/python/azure/?view=azure-python https://learn.microsoft.com/en-gb/python/azure/?view=azure-python
https://github.com/Azure/azure-sdk-for-python https://github.com/Azure/azure-sdk-for-python
但我找不到任何参考或例子。
有谁知道我在哪里可以找到这些信息?
此致。
我只能给一个大概的参考。
安装包后azure 管理安全 https://pypi.org/project/azure-mgmt-security/,你应该使用List
包中的方法,源码为here https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/security/azure-mgmt-security/azure/mgmt/security/operations/alerts_operations.py#L40.
这是doc https://learn.microsoft.com/en-us/python/azure/python-sdk-azure-authenticate?view=azure-python#mgmt-auth-token关于如何认证。
这是doc https://learn.microsoft.com/en-us/azure/active-directory/develop/howto-create-service-principal-portal关于如何获取租户 ID / 客户端 ID / 密钥。
这是我的代码:
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()
另外,您可以使用列表警报 API https://learn.microsoft.com/en-us/rest/api/securitycenter/alerts/list在 python 中使用 http 请求。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)