[英]Azure ARM template - using array variable
I am defining an alertrule inside my template.json with custom eMails which shall be alerted in case of an error. 我正在我的template.json中定义带有自定义电子邮件的Alertrule,如果发生错误,则将对其进行警告。 So the JSON snippet looks like this: 因此,JSON代码片段如下所示:
"resources": [
{
"type": "microsoft.insights/alertrules",
"properties": {
"action": {
"customEmails": [
"user01@contoso.com",
"user02@contoso.com"
]
}
}
}
]
Now I'd like to store these emails as an array-variable, something like this: 现在,我想将这些电子邮件存储为数组变量,如下所示:
"variables": {
"alertEmails": [
"user01@contoso.com",
"user02@contoso.com"
]
},
"resources": [
{
"type": "microsoft.insights/alertrules",
"properties": {
"action": {
"customEmails": "[variables('alertEmails')]"
}
}
}
]
This doesn't work, but I didn't found out what the correct syntax is. 这行不通,但是我没有发现正确的语法是什么。 Can someone tell me? 有人可以告诉我吗?
If you want to use array, maybe we can use json like this: 如果您想使用数组,也许我们可以像这样使用json:
"parameters": {
"customEmailAddresses": {
"type": "array",
"defaultValue": ["one@microsoft.com",
"two@microsoft.com",
"three@microsoft.com"]
}
},
and in action, like this: 并采取如下行动:
"customEmails": "[array(parameters('customEmailAddresses'))]"
This doesn't work, but I didn't found out what the correct syntax is. 这行不通,但是我没有发现正确的语法是什么。 Can someone tell me? 有人可以告诉我吗?
I test it with your supplied code, it works correctly on my side. 我用您提供的代码对其进行了测试,它可以正常工作。 The following is my used template. 以下是我使用的模板。 Please have a try to test with the following demo code. 请尝试使用以下演示代码进行测试。
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"serverFarmName": {
"type": "string",
"defaultValue": "serviceplan"
},
"resourceId": {
"type": "string",
"defaultValue": "/subscriptions/{subscriptionId}/resourceGroups/{resourceName}/providers/Microsoft.Web/sites/websiteName",
"metadata": {
"description": "Resource ID of the resource emitting the metric that will be used for the comparison."
}
},
"metricName": {
"type": "string",
"defaultValue": "BytesReceived",
"metadata": {
"description": "Name of the metric used in the comparison to activate the alert."
}
},
"operator": {
"type": "string",
"defaultValue": "GreaterThan",
"allowedValues": [
"GreaterThan",
"GreaterThanOrEqual",
"LessThan",
"LessThanOrEqual"
],
"metadata": {
"description": "Operator comparing the current value with the threshold value."
}
},
"threshold": {
"type": "string",
"defaultValue": "1",
"metadata": {
"description": "The threshold value at which the alert is activated."
}
},
"aggregation": {
"type": "string",
"defaultValue": "Average",
"allowedValues": [
"Average",
"Last",
"Maximum",
"Minimum",
"Total"
],
"metadata": {
"description": "How the data that is collected should be combined over time."
}
},
"windowSize": {
"type": "string",
"defaultValue": "PT5M",
"metadata": {
"description": "Period of time used to monitor alert activity based on the threshold. Must be between five minutes and one day. ISO 8601 duration format."
}
},
"sendToServiceOwners": {
"type": "bool",
"defaultValue": true,
"metadata": {
"description": "Specifies whether alerts are sent to service owners"
}
},
"webhookUrl": {
"type": "string",
"defaultValue": "",
"metadata": {
"description": "URL of a webhook that will receive an HTTP POST when the alert activates."
}
},
"serverFarmResourceGroup": {
"type": "string",
"defaultValue": "resourceGroup"
}
},
"variables": {
"alertEmails": [
"sunguiguan@hotmail.com",
"user02@contoso.com"
],
"TomARMtestName": "[concat('TomARMtest', uniqueString(resourceGroup().id))]"
},
"resources": [
{
"type": "Microsoft.Insights/alertRules",
"name": "newalert",
"location": "[resourceGroup().location]",
"apiVersion": "2016-03-01",
"properties": {
"name": "newalert",
"description": "newalert",
"isEnabled": true,
"condition": {
"odata.type": "Microsoft.Azure.Management.Insights.Models.ThresholdRuleCondition",
"dataSource": {
"odata.type": "Microsoft.Azure.Management.Insights.Models.RuleMetricDataSource",
"resourceUri": "[parameters('resourceId')]",
"metricName": "[parameters('metricName')]"
},
"operator": "[parameters('operator')]",
"threshold": "[parameters('threshold')]",
"windowSize": "[parameters('windowSize')]",
"timeAggregation": "[parameters('aggregation')]"
},
"actions": [
{
"customEmails": "[variables('alertEmails')]"
}
]
}
}
]
,
"outputs": {
"out": {
"type": "array",
"value": "[variables('alertEmails')]"
}
}
}
And I follow the azure document to use customEmails": "[split(parameters('customEmailAddresses'), ',')]"
code, it also works correctly on my side. 并且我遵循azure文档以使用customEmails": "[split(parameters('customEmailAddresses'), ',')]"
代码,它在我这一端也可以正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.