【问题标题】:Azure template deployment for IoT Hub and diagnostics settings does not workIoT 中心的 Azure 模板部署和诊断设置不起作用
【发布时间】:2018-10-17 07:13:12
【问题描述】:

我正在将 Azure RM 模板部署与 Visual Studio 2017 资源组项目一起使用,以在 Log Analytics 中部署具有诊断设置的 IoTHub 实例。

单独部署 IoTHub 是成功的,问题在于诊断设置模板的部署。

我按照说明将诊断设置部署为Non-Compute resource template

我收到的奇怪错误如下:

错误:代码=无效模板; Message=部署模板验证 失败:'模板资源'Microsoft.Insights/BasicDiagnostics' 在“69”行和“9”列输入“providers/diagnosticSettings” 段长度不正确。嵌套资源类型必须具有 与其资源名称相同的段数。根资源 类型的段长度必须比其资源名称大一。

即使我按照提供的示例遵循文档,为什么它会这样失败?

这是我的模板定义:

  "resources": [
    {
      "type": "Microsoft.Devices/IotHubs",
      "sku": {
        "name": "[parameters('sku.name')]",
        "capacity": "[parameters('sku.units')]"
      },
      "name": "[parameters('iothubname')]",
      "apiVersion": "2018-04-01",
      "location": "[resourceGroup().location]",
      "properties": {
        "eventHubEndpoints": {
          "events": {
            "retentionTimeInDays": "[parameters('endpoints.events.retention')]",
            "partitionCount": "[parameters('endpoints.events.partitions')]"
          },
          "operationsMonitoringEvents": {
            "retentionTimeInDays": "[parameters('endpoints.operationsMonitoringEvents.retention')]",
            "partitionCount": "[parameters('endpoints.operationsMonitoringEvents.partitions')]"
          }
        },
        "features": "[parameters('features')]"
      }
    },
    {
      "type": "providers/diagnosticSettings",
      "name": "[concat('Microsoft.Insights/', parameters('iotHub.diagnostics.settingName'))]",
      "dependsOn": [
        "[resourceId('Microsoft.Devices/IoTHubs', parameters('iothubname'))]"
      ],
      "apiVersion": "2017-05-01-preview",
      "properties": {
        "name": "[parameters('iotHub.diagnostics.settingName')]",
        "workspaceId": "[parameters('iotHub.diagnostics.workspaceId')]",
        "logs": [
          {
            "category": "Connections",
            "enabled": true,
            "retentionPolicy": {
              "days": 0,
              "enabled": false
            }
          },
          {
            "category": "Configurations",
            "enabled": true,
            "retentionPolicy": {
              "days": 0,
              "enabled": false
            }
          },
          {
            "category": "D2CTwinOperations",
            "enabled": true,
            "retentionPolicy": {
              "days": 0,
              "enabled": false
            }
          },
          {
            "category": "C2DTwinOperations",
            "enabled": true,
            "retentionPolicy": {
              "days": 0,
              "enabled": false
            }
          }
        ],
        "metrics": [
          {
            "category": "AllMetrics",
            "enabled": true,
            "retentionPolicy": {
              "days": 0,
              "enabled": false
            }
          }
        ]
      }
    }
  ]

非常感谢任何帮助!

【问题讨论】:

    标签: azure azure-resource-manager azure-iot-hub azure-diagnostics azure-template


    【解决方案1】:

    这需要是 IOT hub 的子资源,而不是单独的资源。

    {
        "type": "Microsoft.Devices/IotHubs",
        "sku": {
            "name": "[parameters('sku.name')]",
            "capacity": "[parameters('sku.units')]"
        },
        "name": "[parameters('iothubname')]",
        "apiVersion": "2018-04-01",
        "location": "[resourceGroup().location]",
        "properties": {
            xxx
        },
        "features": "[parameters('features')]",
        "resources": [
            {
                "type": "providers/diagnosticsSettings",
                xxx
            }
        ]
    }
    

    },

    【讨论】:

    • 我不敢相信我错过了。这就是他们试图用 “在要启用诊断日志的资源的资源数组中,添加类型为 [resource namespace]/providers/diagnosticSettings 的资源。” “[resource namespace]" 误导我诊断资源应该在定义 IoT 中心的数组中。非常感谢!
    • 现在部署成功完成,但是...这个"metrics": [ { "category": "AllMetrics", "enabled": true, "retentionPolicy": { .. . } } ] 未部署为启用 - 在门户中未将其检查为启用。多次尝试,作为新部署和更新。你对此有什么暗示吗?如果我在门户中手动启用它,它会在后续部署后保持启用状态。
    • 你能提出一个关于这个的新问题吗
    • 这似乎不再有效。部署失败。相关 ID:420685af-7810-4b41-90a0-e5c775d88baa。 { "error": { "code": "InvalidResourceNamespace", "message": "资源命名空间 'providers' 无效。" } }
    猜你喜欢
    • 2019-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多