0

I have some alerts set up based on activity log - when certain resources are create/updated. I would like to disabled them for the deployment time (Azure DevOps, including ARM template) - to not be spammed with unnecessary emails.

So before each deployment (and after deploying ARM template) I would run code like this:

az monitor activity-log alert list --resource-group ${RESOURCE_GROUP_NAME} --query "[].[name, enabled]" -o tsv | while read ALERT_NAME ALERT_STATUS
do
    if [[ ${ALERT_STATUS} == "True" ]]
    then
        az monitor activity-log alert update --resource-group ${RESOURCE_GROUP_NAME} --name ${ALERT_NAME} --enabled false
    fi
done

And switch them on as a last step of deployment.

However this doesn't seem to suppress the alerts. My guess is that it need some time to refresh status somewhere. Any clue what it might be and how to fix/workaround it?

Marcin
  • 284
  • 1
  • 2
  • 14
  • Is the script correct? Do you see alerts being disabled in portal / activity logs? If yes, try adding a sleep command in the script for few minutes. – stackoverflowusrone Feb 27 '20 at 16:15
  • Yes the script is correct and the alerts are disabled, but the they are still fired for some time. Few minutes is to much for deployment which is running under 10 minutes. I have been trying 30 seconds sleep but that was not solving the problem. – Marcin Feb 28 '20 at 10:18
  • 1
    It can take up to 5 minutes for new alerts to become active. I would not be surprised if it takes around same time to disable the alerts as well - https://learn.microsoft.com/en-us/azure/azure-monitor/platform/alerts-activity-log – stackoverflowusrone Feb 28 '20 at 19:10
  • Thanks for pointing this out @stackoverflowuserone - I guess I will have to live with it. – Marcin Mar 02 '20 at 17:00

1 Answers1

0

You can use action rules to suppress alerts during deployments. See these docs on that: https://learn.microsoft.com/en-us/azure/azure-monitor/platform/alerts-action-rules

Yaniv Lavi
  • 41
  • 3
  • Thank you for this suggestion @yaniv-lavi! It would be a great solution, if not the fact that, so far, [powershell](https://learn.microsoft.com/en-us/powershell/module/az.alertsmanagement/set-azactionrule?view=azps-3.7.0) seems to be the only programmatically way of creating or enabling action rule. As we are mostly using linux/bash I would rather avoid powershell and wait until hopefully either rest API or az cli will support action rules. – Marcin Apr 01 '20 at 14:34
  • There is always an API to any Azure capability. There is an issue with the API reference we are working on, but this is the swagger of the action rules API: https://github.com/Azure/azure-rest-api-specs/blob/master/specification/alertsmanagement/resource-manager/Microsoft.AlertsManagement/preview/2019-05-05-preview/AlertsManagement.json – Yaniv Lavi Apr 06 '20 at 09:44