0
votes

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?

1
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
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
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 - docs.microsoft.com/en-us/azure/azure-monitor/platform/…stackoverflowusrone
Thanks for pointing this out @stackoverflowuserone - I guess I will have to live with it.Marcin

1 Answers

0
votes

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