none
Creating Alert Rules and Action Groups in Azure Workspace RRS feed

  • Question

  • I am trying to create an ARM template that will :

    1. Create a Workspace

    2. Create Alert Rules.

    3. Create Action Groups.

    4. Configure the alert rules to send emails to the groupIDs.

    I have tried this creating the work space and the alert rule using a template which worked but the action group to send the emails was not included in the template. is there anyone that has done this before?

     


    Friday, January 24, 2020 11:54 AM

All replies

  • Thanks for reaching out! Here is a sample template which I have tried and it might fit for your requirement.

    {
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters":{
            "workspacename": {
                    "type": "string"
            },
            "alertname": {
                    "type": "string"
            },
            "workspacelocation": {
                    "type": "string"
            },
            "actiongroupname": {
                    "type": "string"
            },
            "groupShortName":{
                "type": "string"
            },
            "resourceGroupname":{
                "type":"string"
            }
    },
    "resources": [
        {
                "name": "[parameters('workspacename')]",
                "type": "Microsoft.OperationalInsights/workspaces",
                "apiVersion": "2015-11-01-preview",
                "location": "[parameters('workspacelocation')]",
                "tags": {},
                "properties": {
                    "sku": {
                        "name": "PerGB2018"
                    },
                "retentionInDays": 30
            }
        },
        {
                 "name": "[parameters('actiongroupname')]",
                 "type": "microsoft.insights/actionGroups",
                 "apiVersion": "2019-06-01",
                 "location": "Global",
                 "tags": {},
                 "properties": {
                     "groupShortName": "[parameters('groupShortName')]",
                     "enabled": "true",
                     "emailReceivers": [
                            {
                                "name": "xxxxxx",
                                "emailAddress": "xxxxxxx@microsoft.com",
                                "useCommonAlertSchema": "true"
                            }
                        ]
                    }
        },
        {  
             "name":"[parameters('alertname')]",
             "type":"Microsoft.Insights/activityLogAlerts",
             "location":"Global",
             "apiVersion":"2017-04-01",
             "properties":{  
                "enabled":true,
                "scopes":[  
                   "[concat('/subscriptions/', subscription().subscriptionid, '/resourceGroups/', resourceGroup().name)]"
    
                ],
                "condition":{  
                   "allOf":[  
                      {  
                         "field":"category",
                         "equals":"Administrative"
                      },
                      {  
                         "field":"resourceGroup",
                         "equals":"[parameters('resourceGroupname')]"
                      },
                      {  
                         "field":"resourceType",
                         "equals":"microsoft.web/serverfarms"
                      },
                      {  
                         "field":"operationName",
                         "equals":"microsoft.web/serverfarms/write"
                      },
                      {  
                         "field":"status",
                         "equals":"Succeeded"
                      }
                   ]
                },
                "actions":{  
                   "actionGroups":[  
                      {  
                         "actionGroupId":"[resourceId('Microsoft.insights/actionGroups/',parameters('actiongroupname'))]"
                      }
                   ]
                }
             },
             "dependsOn":[
                 "[concat('Microsoft.insights/actionGroups/', parameters('actiongroupname'))]"
             ]
          }
    ] 
    }

    Hope this helps!

    Monday, February 3, 2020 4:51 AM
    Moderator