azure - 模板参数 JToken 类型在 Azure 中无效(预期 'String, Uri' 。实际 'Integer' )

标签 azure templates

我尝试使用 Powershell 部署许多 Azure 警报规则,但结果是:

New-AzResourceGroupDeployment : 9:27:32 AM - Error: Code=InvalidTemplate; Message=Deployment template validation failed: 'Template parameter JToken type is not valid. Expected 'String, Uri'. Actual 'Integer'. Please see https://aka.ms/resource-manager-parameter-files for usage details.'.

在我的模板中,我没有发现问题出在哪里。模板中没有任何“整数”。 当我将模板粘贴到 Ui 中以创建新的部署时,我的模板在 Visual Studio 和 Azure 中得到验证。

模板:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "actionGroup": {
      "defaultValue": "",
      "metadata": {
        "description": "The ID of the action group that is triggered when the alert is activated or deactivated"
      },
      "type": "string"
    },
    "alertDescription": {
      "defaultValue": "This is a metric alert",
      "metadata": {
        "description": "Description of alert"
      },
      "type": "string"
    },
    "alertName": {
      "metadata": {
        "description": "Name of the alert"
      },
      "type": "string"
    },
    "alertSeverity": {
      "allowedValues": [
        0,
        1,
        2,
        3,
        4
      ],
      "defaultValue": 3,
      "metadata": {
        "description": "Severity of alert {0,1,2,3,4}"
      },
      "type": "string"
    },
    "consecutiveBreachTrigger": {
      "defaultValue": "",
      "metadata": {
        "description": ""
      },
      "type": "string"
    },
    "isEnabled": {
      "defaultValue": true,
      "metadata": {
        "description": "Specifies whether the alert is enabled"
      },
      "type": "bool"
    },
    "metricColumn": {
      "defaultValue": "",
      "metadata": {
        "description": "Metric type of trigger"
      },
      "type": "string"
    },
    "metricTriggerTypeMetricTrigger": {
      "defaultValue": "",
      "metadata": {
        "description": "Metric type of trigger"
      },
      "type": "string"
    },
    "metricTriggerTypeTrigger": {
      "defaultValue": "",
      "metadata": {
        "description": "Metric type of trigger"
      },
      "type": "string"
    },
    "operatorMetricTrigger": {
      "allowedValues": [
        "Equals",
        "NotEquals",
        "GreaterThan",
        "GreaterThanOrEqual",
        "LessThan",
        "LessThanOrEqual"
      ],
      "defaultValue": "GreaterThan",
      "metadata": {
        "description": "Operator comparing the current value with the threshold value."
      },
      "type": "string"
    },
    "operatorTrigger": {
      "allowedValues": [
        "Equals",
        "NotEquals",
        "GreaterThan",
        "GreaterThanOrEqual",
        "LessThan",
        "LessThanOrEqual"
      ],
      "defaultValue": "GreaterThan",
      "metadata": {
        "description": "Operator comparing the current value with the threshold value."
      },
      "type": "string"
    },
    "PfrequencyInMin": {
      "defaultValue": "",
      "metadata": {
        "description": "Time along the query is running"
      },
      "type": "string"
    },
    "PtimeWindowFrequency": {
      "defaultValue": "",
      "metadata": {
        "description": "Frequency of often should be run the alert"
      },
      "type": "string"
    },
    "query": {
      "defaultValue": "",
      "metadata": {
        "description": "Query to use for this alert"
      },
      "type": "string"
    },
    "queryType": {
      "defaultValue": "",
      "metadata": {
        "description": "Type of the query"
      },
      "type": "string"
    },
    "region": {
      "defaultValue": "",
      "metadata": {
        "description": "Region of the workspace"
      },
      "type": "string"
    },
    "resourceId": {
      "metadata": {
        "description": "Full Resource ID of the resource emitting the metric that will be used for the comparison. For example /subscriptions/00000000-0000-0000-0000-0000-00000000/resourceGroups/ResourceGroupName/providers/Microsoft.compute/virtualMachines/VM_xyz"
      },
      "minLength": 1,
      "type": "string"
    },
    "thresholdMetricTrigger": {
      "defaultValue": "0",
      "metadata": {
        "description": "The threshold value at which the alert is activated."
      },
      "type": "string"
    },
    "thresholdTrigger": {
      "defaultValue": "0",
      "metadata": {
        "description": "The threshold value at which the alert is activated."
      },
      "type": "string"
    }
  },
  "resources": [
    {
      "apiVersion": "2018-04-16",
      "location": "[parameters('region')]",
      "name": "[parameters('alertName')]",
      "properties": {
        "action": {
          "aznAction": {
            "actionGroup": "[parameters('actionGroup')]"
          },
          "metricTrigger": {
            "metricColumn": "[parameters('metricColumn')]",
            "metricTriggerType": "[parameters('metricTriggerTypeMetricTrigger')]",
            "threshold": "[parameters('thresholdMetricTrigger')]",
            "thresholdOperator": "[parameters('operatorMetricTrigger')]"
          },
          "odata.type": "Microsoft.WindowsAzure.Management.Monitoring.Alerts.Models.Microsoft.AppInsights.Nexus.DataContracts.Resources.ScheduledQueryRules.AlertingAction",
          "severity": "[parameters('alertSeverity')]",
          "trigger": {
            "consecutiveBreach": "[parameters('consecutiveBreachTrigger')]",
            "metricTriggerType": "[parameters('metricTriggerTypeTrigger')]",
            "threshold": "[parameters('thresholdTrigger')]",
            "thresholdOperator": "[parameters('operatorTrigger')]"
          }
        },
        "description": "[parameters('alertDescription')]",
        "displayname": "[parameters('alertName')]",
        "enabled": "[parameters('isEnabled')]",
        "schedule": {
          "frequencyInMinutes": "[parameters('PfrequencyInMin')]",
          "timeWindowInMinutes": "[parameters('PtimeWindowFrequency')]"
        },
        "source": {
          "datasourceID": "[parameters('resourceId')]",
          "query": "[parameters('query')]",
          "queryType": "[parameters('queryType')]"
        }
      },
      "tags": {},
      "type": "microsoft.insights/scheduledqueryrules"
    }
  ],
  "variables": {}
}

我使用这个 Powershell 命令:

New-AzResourceGroupDeployment -Name "AlertRule-VM-CPU-Percent" -ResourceGroupName Gizmo-hosted-logs -TemplateFile .\template.json -TemplateParameterFile .\parameters.json

感谢您的帮助。

问候

最佳答案

问题出在您的“alertSeverity”参数上。该参数的类型应该是整数, 不是字符串。以下代码有效:

  "alertSeverity": {
    "allowedValues": [
      0,
      1,
      2,
      3,
      4
    ],
    "defaultValue": 3,
    "type": "int"
  }

关于azure - 模板参数 JToken 类型在 Azure 中无效(预期 'String, Uri' 。实际 'Integer' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60753492/

相关文章:

C++1z - 如果在模板展开期间出现条件,则抛出编译错误

Azure Web 作业 - 同一 Web 作业中的多个函数和/或同一 Web 应用程序中的多个 Web 作业对性能有何影响?

Azure EventHub 事件格式

c# - 如何用C#连接kusto数据库?

javascript - 服务器端的 jQuery 模板

c++ - 如何为类型列表中的每个继承类型调用非默认构造函数?

C++:通过模板传递参数与通过函数参数传递参数

azure - 新-AzureRmResourceGroupDeployment : A parameter cannot be found that matches parameter name '_artifactsLocationSasToken'

c# - 如何复制 Azure 容器和 Blob

c++ - 为什么模板参数替换的顺序很重要?