3

I have an ARM template with a web app alerting rule, where I want to be able to configure which e-mails get the alerts.

The snippet for the e-mail alerting action is this:

"action": {
    "odata.type": "Microsoft.Azure.Management.Insights.Models.RuleEmailAction",
    "sendToServiceOwners": false,
    "customEmails": [
        "[email protected]",
        "[email protected]"
    ]
}

The same template is used for setting up production, test, and dev environments. So I would like to use a parameter for the e-mail alerting.

How can I generate an array to be used as the "customEmails" property based on either a comma separated string, or an array type parameter?

I have tried "customEmails": "[array(parameters('AlertEmailRecipients'))]", and also

"customEmails": [
    [array(parameters('AlertEmailRecipients'))]
]

but neither work. I don't know how to tell it that the "customEmails" property value should come from a parameter.

1
  • i dont understand the question, can you give an example? this should be fairly easy if you provide one Commented Nov 23, 2017 at 10:30

2 Answers 2

14

I used the following using an array parameter:

parameter declaration:

"customEmails": {
      "type": "array",
      "metadata": {
        "description": "alert email addressess"
      }
}

in the parameters file:

"customEmails": {
      "value": [
        "[email protected]",
        "[email protected]"     
      ]
    }

usage:

"customEmails": "[parameters('customEmails')]"
Sign up to request clarification or add additional context in comments.

Comments

3

I found a solution. The main problem was that my comma separated list of e-mail addresses had a space after each comma.

The way I have implemented it now is like this:

Define a string parameter with a comma separated list of e-mail addresses. Don't have spaces in the list.

Define a variable like this:

"customEmails" : "[split(parameters('AlertEmailRecipients'), ',')]"

and then reference that variable in the alerting action:

"action": {
    "odata.type": "Microsoft.Azure.Management.Insights.Models.RuleEmailAction",
    "sendToServiceOwners": false,
    "customEmails": "[variables('customEmails')]"
}

The example actually does this, but doesn't make it clear the the list of e-mails can't contain spaces.

1 Comment

Revisiting this with a couple of years more experience with ARM templates. There is also a replace function which can be used to remove the extra spaces: replace(parameters('AlertEmailRecipients'), ' ', '')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.