![](/img/trans.png)
[英]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.