What am I doing wrong with this ARM template?

Technical Question

I have been working on this all day. I can't quite seem to get the syntax right. I have been working on creating ARM templates for Metric Alerts. This is what I have. I am trying to create arrays of alert values.

alerts.json

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "alerts": {
            "type": "array",
            "metadata": {
                "test": "test"
            }
        }
    },
    "variables": {
        "subscription":  "/subscriptions/<sub>",
        "resourceGroup": "/resourceGroups/<RG>",
        "copy": [
            {
                "name": "alerts",
                "count": "[length(parameters('alerts'))]",
                "input": {
                    "description": "[parameters('alerts')[copyIndex('alerts')].alertDescription]",
                    "severity": "[parameters('alerts')[copyIndex('alerts')].alertSeverity]",
                    "enabled": "[parameters('alerts')[copyIndex('alerts')].isEnabled]",
                    "scopes": ["[concat(variables('subscription'), parameters('alerts')[copyIndex('alerts')].resourceId)]"],
                    "evaluationFrequency":"PT5M",
                    "windowSize": "PT5M",
                    "criteria": {
                        "odata.type": "Microsoft.Azure.Monitor.SingleResourceMultipleMetricCriteria",
                        "allOf": [
                            {
                                "name" : "1st criterion",
                                "metricName": "[parameters('alerts')[copyIndex('alerts')].metricName]",
                                "dimensions":[],
                                "operator": "[parameters('alerts')[copyIndex('alerts')].operator]",
                                "threshold" : "[parameters('alerts')[copyIndex('alerts')].threshold]",
                                "timeAggregation": "[parameters('alerts')[copyIndex('alerts')].timeAggregation]"
                            }
                        ]
                    },
                    "actions": [
                        {
                            "actionGroupId": "[concat(variables('resourceGroup'), parameters('alerts')[copyIndex('alerts')].actionGroupId)]"
                        }
                    ]
                }

            }
        ]
      },
    "resources": [
        {
            "name": "test",
            "type": "Microsoft.Insights/metricAlerts",
            "location": "global",
            "apiVersion": "2018-03-01",
            "tags": {},
            "properties": "[variables('alerts')]"
        }
    ]
}

​

alerts.parameters.json

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "alerts": {
            "value": [
                {
                    "alertName": "Http5xx",
                    "alertDescription": "This Application Service is experiencing server errors",
                    "alertSeverity": 4,
                    "isEnabled": true,
                    "resourceId": "/providers/Microsoft.Web/sites/az-devqa-ClientConfigurationService001",
                    "metricName": "Http5xx",
                    "operator": "GreaterThan",
                    "threshold": "4",
                    "timeAggregation": "Total",
                    "actionGroupId": "/providers/Microsoft.Insights/actionGroups/Test-Group"
                }
            ]
        }
    }
}

I am getting this error back despite this being valid JSON.

cli.azure.cli.core.util : Deployment failed. Correlation ID: 93bf0dc0-ec38-4009-8772-e8bc05302f20. {

"error": {

"code": "InvalidRequestContent",

"message": "The request content was invalid and could not be deserialized: 'Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'System.Collections.Generic.Dictionary`2[System.String,Newtonsoft.Json.Linq.JToken]' because the type requires a JSON object (e.g. {\"name\":\"value\"}) to deserialize correctly.\r\nTo fix this error either change the JSON to a JSON object (e.g. {\"name\":\"value\"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.\r\nPath 'properties'.'."

}

}

Any insight would be appreciated.

Posted Jun 4, 2020, 11:40 PM UTC

519
Loading comments…