Azure ARM模板json函数错误:使用问题

问题描述 投票:0回答:2

我正在部署时使用以下模板。

{

  "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "alertName": {
      "type": "string",
      "minLength": 1,
      "defaultValue": "{{alertinginsights.alert.alertName}}"
    },
    "alertDescription": {
      "type": "string",
      "minLength": 1,
      "defaultValue": "{{alertinginsights.alert.alertDescription}}"
    },
    "alertAppInsights": {
      "type": "string",
      "defaultValue": "{{alertinginsights.alertAppInsights}}"
    },
    "alertSourceQuery": {
      "type": "string",
      "defaultValue": "{{alertinginsights.alert.alertSourceQuery}}"
    },
    "alertTriggerThreshold": {
      "type": "string",
      "defaultValue": "{{alertinginsights.alert.alertTriggerThreshold}}"
    },
    "alertTriggerOperator": {
      "type": "string",
      "defaultValue": "{{alertinginsights.alert.alertTriggerOperator}}",
      "allowedValues": [
        "Equals",
        "NotEquals",
        "GreaterThan",
        "GreaterThanOrEqual",
        "LessThan",
        "LessThanOrEqual"
      ],
      "metadata": {
        "description": "Operator comparing the current value with the threshold value."
      }
    },
    "alertSeverity": {
      "type": "string",
      "defaultValue": "{{alertinginsights.alert.alertSeverity}}",
      "allowedValues": [
        "0",
        "1",
        "2",
        "3",
        "4"
      ],
      "metadata": {
        "description": "Severity of alert {0,1,2,3,4}"
      }
    },
    "alertScheduleFrequency": {
      "type": "string",
      "defaultValue": "{{alertinginsights.alert.alertScheduleFrequency}}",
      "metadata": {
        "description": "Select the frequency on how often the query should be run"
      }
    },
    "alertScheduleTime": {
      "type": "string",
      "defaultValue": "{{alertinginsights.alert.alertScheduleTime}}",
      "metadata": {
        "description": "Select a time span over which to execute the above query"
      }
    },
   "resource": {
      "type": "string",
      "defaultValue": "{{alertinginsights.resource}}"
    },
    "webhookPayload": {
      "type": "string",
      "defaultValue": "{{alertinginsights.webHookPayload}}",
      "metadata": {
        "description": "Webhook in JSON to be sent to action groups"
      }
    },
    "actionGroupName": {
      "type": "string",
      "defaultValue": "{{alertinginsights.alert.actionGroupName}}"
    },
    "isResultCount":{
      "type": "string",
      "defaultValue": "{{alertAppInsights.alert.isResultCount}}"
    },
    "triggerObject":{
      "type":"object",
      "defaultValue":"[json(alertAppInsights.alert.triggerObject)]"
    }
  },
  "variables": {
    "alertTagBase": "hidden-link:/subscriptions/<subscriptionId>/resourceGroups/",
    "alertTagMid": "/providers/microsoft.insights/components/",
    "alertTag": "[concat(variables('alertTagBase'),parameters('resource'),variables('alertTagMid'),parameters('alertAppInsights'))]",
    "alertSourceBaseId":<rgBase>,
    "alertSourceMidId": "/providers/microsoft.insights/components/",
    "alertSourceId": "[concat(variables('alertSourceBaseId'),parameters('resource'),variables('alertSourceMidId'),parameters('alertAppInsights'))]",
    "actionGroup": "[concat(<rgBase>, parameters('resource'),'/providers/microsoft.insights/actionGroups/',parameters('actionGroupName'))]",
    "alertStatus": "true"
  },
  "resources": [
    {
        "name": "[parameters('alertName')]",
        "type": "Microsoft.Insights/scheduledQueryRules",
        "location": "southcentralus",
        "apiVersion": "2018-04-16",
        "tags": {
          "[variables('alertTag')]": "Resource"
        },
        "properties": {
          "description": "[parameters('alertDescription')]",
          "enabled": "[variables('alertStatus')]",
          "source": {
            "query": "[parameters('alertSourceQuery')]",
            "dataSourceId": "[variables('alertSourceId')]"
          },
          "schedule": {
            "frequencyInMinutes": "[parameters('alertScheduleFrequency')]",
            "timeWindowInMinutes": "[parameters('alertScheduleTime')]"
          },
          "action": {
            "odata.type": "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.Microsoft.AppInsights.Nexus.DataContracts.Resources.ScheduledQueryRules.AlertingAction",
            "severity": "[parameters('alertSeverity')]",
            "aznsAction": {
              "actionGroup": [
                "[variables('actionGroup')]"
              ],
              "customWebhookPayload": "[parameters('webhookPayload')]"
            },
            "trigger":"[parameters('triggerObject')]"
          }
        }
    }
  ]
}

alertAppInsights.alert.triggerObject的价值是:"{\"thresholdOperator\":\"GreaterThan\",\"threshold\":0}"

但是我收到了这个错误:

{"code":"DeploymentFailed","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-debug for usage details.","details":[{"code":"BadRequest","message":"{\r\n \"error\": {\r\n \"code\": \"InvalidTemplate\",\r\n \"message\": \"Deployment template validation failed: 'The template resource 'triggerObject' at line '89' and column '21' is not valid: Unable to parse language expression 'json(alertAppInsights.alert.triggerObject)': expected token 'LeftParenthesis' and actual 'Dot'.. Please see https://aka.ms/arm-template-expressions for usage details.'.\"\r\n }\r\n}"}]
}

不确定json的使用是无效的还是我遗漏的东西。任何帮助,将不胜感激

azure devops azure-application-insights
2个回答
0
投票

好吧,我有点困惑你的模板,但任何函数都需要一个字符串\ int \ object输入,所以json()不是什么不同,它应该采取像这样的json('something')输入。如果要传入对象,则必须使用参数\ variable。你不能真正传递内联(至少我从未见过)。

此外,模板看起来非常奇怪,我会感到惊讶它会起作用......


0
投票

当我尝试验证您的JSON时,我收到以下错误:enter image description here

我将更正第99行的语法并在Visual Studio或任何其他JSON验证器中再次测试JSON,直到您没有错误,然后再次尝试部署。

© www.soinside.com 2019 - 2024. All rights reserved.