[英]Are “Cross Application Queries” possible using the Azure API format for app insights?
[英]How to access Application Insights data using the Azure API format with AD authentication
根據您的描述,您需要先創建一個Service Principle,然后使用它來獲取API token 消息。 請參閱此鏈接: 使用門戶創建可以訪問資源的 Azure Active Directory 應用程序和服務主體。 您將獲得客戶端 id(app id) 和 client_secret。 您可以使用以下腳本獲取令牌(使用 Power Shell)。
##get token
$TENANTID="******"
$APPID="<client_id>"
$PASSWORD="<client_secret>"
$result=Invoke-RestMethod -Uri https://login.microsoftonline.com/$TENANTID/oauth2/token?api-version=1.0 -Method Post -Body @{"grant_type" = "client_credentials"; "resource" = "https://management.core.windows.net/"; "client_id" = "$APPID"; "client_secret" = "$PASSWORD" }
$token=$result.access_token
獲得令牌后,您需要構造頭消息。 像下面這樣:
$Headers=@{
'authorization'="Bearer $token"
'host'="management.azure.com"
'contentype'='application/json'
}
然后,您可以使用 API 來獲取您想要的信息。
Invoke-RestMethod -Uri $url -Headers $Headers -Method GET
更新:
如果要使用 Applications Insights REST API,則不需要使用服務原則來獲取令牌。 您需要創建一個 API 密鑰。 請參閱此鏈接。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.