首页 > 解决方案 > Azure Log Analytics 数据收集器的 ARM 模板

问题描述

我一直在尝试为 Log Analytics 数据收集器 API 连接创建一个 ARM 模板。我几乎得到了 ARM 模板,但我找不到在哪里可以在 API 连接中插入 Workspace Key 值以使其工作。

这是我的 ARM 模板,用于 Azure 日志分析数据收集器的 API 连接。=

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
  },
  "variables": {
  },
  "resources": [
    {
      "properties": {
        "displayName": "pankajtestlog",
        "statuses": [
          {
            "status": "Connected"
          }
        ],
        "customParameterValues": {},
        "nonSecretParameterValues": {
          "username": "yP4jrRxnB8EfXIO8Y27as+JbDMEUmIOk1K4QB5NuvTei9yELgzdjUCejWmwgb4AVpw81lg0NpOcpvdvmLM/Hqw=="
        },
        "createdTime": "2020-04-11T07:57:31.1911201Z",
        "changedTime": "2020-04-11T07:57:31.1911201Z",
        "api": {
          "name": "azureloganalyticsdatacollector",
          "displayName": "Azure Log Analytics Data Collector",
          "description": "Azure Log Analytics Data Collector will send data to any Azure Log Analytics workspace.",
          "iconUri": "https://connectoricons-prod.azureedge.net/azureloganalyticsdatacollector/icon_1.0.1274.1744.png",
          "brandColor": "#0072C6",
          "category": "Standard",
          "id": "/subscriptions/44357e6b-77a0-4b60-a817-27e62ffb6fdd/providers/Microsoft.Web/locations/usgovarizona/managedApis/azureloganalyticsdatacollector",
          "type": "Microsoft.Web/locations/managedApis"
        },
        "testLinks": []
      },
      "id": "/subscriptions/44357e6b-77a0-4b60-a817-27e62ffb6fdd/resourceGroups/RG-Guardian-POC/providers/Microsoft.Web/connections/azureloganalyticsdatacollector-1",
      "name": "azureloganalyticsdatacollector-1",
      "type": "Microsoft.Web/connections",
      "location": "usgovarizona",
      "apiVersion": "2016-06-01"
    }
  ],
  "outputs": {
  }
}

如果您在此处看到模板,则 nonSecretParameterValues 下的用户名参数是 Workspace ID,但我无法找到要为 Workspace 共享密钥添加的属性。下面的屏幕截图会有所帮助。有人可以帮我添加该属性,或者您对此有任何 ARM。我从 ARMClient Tool 获得了这个模板。

在此处输入图像描述

标签: azurearmazure-logic-appsazure-log-analytics

解决方案


如果需要arm模板中的log analytics workspace share key,可以使用ARM模板函数listKeys获取。更多详细信息,请参阅文档

表达式应该像

listKeys(resourceId('<group name>','Microsoft.OperationalInsights/workspaces', '<space name>'), providers('Microsoft.OperationalInsights', 'workspaces').apiVersions[0]).primarySharedKey]

例如

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "location":{
        "type": "string",
      "defaultValue": "[resourceGroup().location]"


    },
    "azureloganalyticsdatacollector_1_Connection_Name": {
      "type": "string",
      "defaultValue": "azureloganalyticsdatacollector"
    },
    "azureloganalyticsdatacollector_1_Connection_DisplayName": {
      "type": "string",
      "defaultValue": "test2"
    },
    "azureloganalyticsdatacollector_1_username": {
      "type": "string",
      "defaultValue":"fcbee0dd-1bb6-4c2b-a522-ea90b8606752",
      "metadata": {
        "description": "The unique identifier of the Azure Log Analytics workspace."
      },

    },
    "azureloganalyticsdatacollector_1_password": {
      "type": "securestring",
       "defaultValue":"5SFB4B54oiTKBZDcJrBgMw8c81hEaW7rYtC2A9wLh4/eATEOI4XxvGBVOor/ulmYRJePr3VqxACjBk7fvCpWbQ==",
      "metadata": {
        "description": "The primary or secondary key of the Azure Log Analytics workspace."
      }
    }
  },
  "variables": {},
  "resources": [
 {
      "type": "MICROSOFT.WEB/CONNECTIONS",
      "apiVersion": "2018-07-01-preview",
      "name": "[parameters('azureloganalyticsdatacollector_1_Connection_Name')]",
      "location": "[parameters('location')]",
      "properties": {
        "api": {
          "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', parameters('location'), '/managedApis/', 'azureloganalyticsdatacollector')]"
        },
        "displayName": "[parameters('azureloganalyticsdatacollector_1_Connection_DisplayName')]",
        "parameterValues": {
          "username": "[parameters('azureloganalyticsdatacollector_1_username')]",
          "password": "[listKeys(resourceId('defaultresourcegroup-se','Microsoft.OperationalInsights/workspaces', 'DefaultWorkspace-e5b0fcfa-e859-43f3-8d84-5e5fe29f4c68-SE'), providers('Microsoft.OperationalInsights', 'workspaces').apiVersions[0]).primarySharedKey]"
        }
      }
    }
  ],
  "outputs": {

  }
}

在此处输入图像描述


推荐阅读