如何在Azure资源组模板中检索Application Insights实例的检测密钥?

Ale*_*all 19 azure azure-resource-manager azure-application-insights

有没有办法在Azure资源组模板中检索Application Insights实例的Instrumentation Key?

我已经尝试过这里的说明来检索Azure资源上可用的列表*操作列表,但Microsoft.Insights/components不会在任何地方出现在列表中.这让我觉得目前无法在模板中检索Instrumentation Key

Ale*_*all 45

经过一些挖掘和实验,这就是我发现的作品:

"outputs": {
    "MyAppInsightsInstrumentationKey": {
        "value": "[reference(resourceId('Microsoft.Insights/components', variables('myAppInsightsInstanceName')), '2014-04-01').InstrumentationKey]",
        "type": "string"
    }
}
Run Code Online (Sandbox Code Playgroud)

  • 您还可以使用指向 Insights 实例名称的“listKeys()”函数:https://azure.microsoft.com/en-us/documentation/articles/resource-group-template-functions/#listkeys I对于 Log Analytics/OMS/OpsInsight 工作区主共享密钥和辅助共享密钥有类似的问题,虽然资源提供程序不包含该博客指示的所需的和列出*操作,但它仍然能够返回我的密钥。 (2认同)

Fel*_*sto 9

尝试一下(使用 azure cli)

az resource show -g $RESOURCE_GROUP -n $APP_INSIGHTS --resource-type "microsoft.insights/components" --query properties.InstrumentationKey
Run Code Online (Sandbox Code Playgroud)

  • 杰出的!特别是因为“az monitor app-insights api-key show ...”没有公开它。 (2认同)

Lil*_*045 5

Instrumentation Key 属于资源,可以在 Azure 资源管理器模板中找到。如果要查找 Instrumentation Key,则需要将 ResourceType 定义为 Microsoft.Insights/components。试试下面的代码:

$resourcevalue=Get-AzureRmResource -ResourceGroupName Default-ApplicationInsights-*** -ResourceType Microsoft.Insights/components -ResourceName **hdinsights -ApiVersion 2015-05-01 $resourcevalue.Properties.InstrumentationKey

  • 谢谢,但我希望检索模板本身中的密钥,以便它可以自动填充到门户中的应用程序设置中。 (2认同)