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

时间:2018-09-10 12:15:43

标签: azure devops azure-application-insights

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

{

  "$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的用法是否无效或缺少什么。任何帮助将不胜感激

2 个答案:

答案 0 :(得分:0)

好的,我对您的模板有些困惑,但是任何函数都希望有字符串\ int \ object输入,因此library(ggplot2) library(ggrepel) df = data.frame( status = c("Oak", "maple", "walnut", "Pine"), value = c( 47.54, 37.70, 11.48, 3.28)) ggplot(df, aes(x = "" , y = value, fill = fct_inorder(status))) + geom_bar(width = 1, stat = "identity") + coord_polar(theta = "y", start = 0 ) + scale_fill_brewer(palette = "Set3", direction = -4) + geom_label_repel(aes(label = paste0(value, "%")), size=4, show.legend = F, nudge_x = 1) + guides(fill = guide_legend(title = "Status")) + theme_void() 并没有什么不同,它应该使用类似json()的输入。如果要传递对象,则必须为此使用参数\变量。您无法真正通过内联传递它(至少我从未见过)。

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

答案 1 :(得分:0)

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

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