我正在尝试编写一个函数应用程序,它将从日志分析工作区获取数据,并使用python3推送到事件中心。函数应用程序使用托管标识。我正在使用azure sdk for python。我当前的代码如下所示:
def getAzureEventData():
"""
if "MSI_ENDPOINT" in os.environ:
print("GeTTING MSI Authentication")
creds = MSIAuthentication()
else:
creds, *_ = get_azure_cli_credentials()
"""
## want to find out which one is correct tested each one.
creds = DefaultAzureCredential()
creds=CredentialWrapper()
creds = MSIAuthentication()
#creds, _ = get_azure_cli_credentials(resource="https://api.loganalytics.io")
log_client = LogAnalyticsDataClient(creds)
laQuery = 'ActivityLog | where TimeGenerated > ago(1d)'
result = log_client.query(cisalog_workspace_id, QueryBody(query=laQuery))
根据我看到的例子
creds, _ = get_azure_cli_credentials(resource="https://api.loganalytics.io")
但是当我在没有任何DefaultCredential()
的情况下使用该函数时,我得到404错误,该错误表示未启用系统管理的标识。当我使用DefualtCrednetial
时,我得到访问令牌错误,并且根据建议,我正在使用在internet上找到的包装器。当我使用它时,我得到异常:ErrorResponseException:(InvalidTokenError)提供的身份验证对此资源无效。
所以我很困惑如何使用LogAnalyticsSDK客户端。我在本地和门户网站上进行测试。我的最终目标是使用系统管理的身份和IAM角色来访问LA workspace的功能应用程序。我已将工作区上的监视读取器角色授予SMI。仍然面临这个问题
如果要在Azure函数中使用AzureMSI调用Azure日志分析Rest API,则需要将Azure RABC角色
Log Analytics Reader
分配给MSI。有关更多详情,请参阅here比如说
Enable Azure Function MSI
分配角色
我的
cred_wrapper.py
我的功能代码
相关问题 更多 >
编程相关推荐