QTip: Configure Azure SQL DB to receive alert when failover occurs in failover group or geo replica
Published Jan 16 2024 01:50 AM 3,193 Views

In Azure SQL DB is possible to configure alert to receive a notification when failover happens in failover group or geo replica

Basically you need to configure activity log to send data to some destination (mandatory) in this case workspace will be used

 

Azure Monitor activity log

https://learn.microsoft.com/en-us/azure/azure-monitor/essentials/activity-log?tabs=powershell#send-t...

 

Configure activity log to send results to a workspace (this configuration will be applied to all resources not only current resource)

 

In activity log select export activity logs

 

jaigarcimicrosoft_0-1705365109709.png

 

Select Add diagnostic setting

 

jaigarcimicrosoft_1-1705365152938.png

 

Provide diagnostic setting name , in this demo all categories will be used to be able to see all records at the beginning and save (for this type of alert only administrative category is needed)

 

jaigarcimicrosoft_2-1705365295391.png

 

Alert for failover group

 

Query data using kusto in log analytics

Go to workspace and run query below without filters to see results , sometimes time is needed to see data arriving

 

AzureActivity

 

jaigarcimicrosoft_1-1705433880668.png

 

In this demo some data is used but there is more information that can be used to create more complex filters

 

jaigarcimicrosoft_2-1705434277482.png

 

Now is possible filter data looking for failovergroup ...

 

AzureActivity
| where OperationNameValue contains("Microsoft.Sql/servers/failoverGroups/failover/action")

 

jaigarcimicrosoft_5-1705365766130.png

 

Finally is possible to filter for specific activity status to get more specific records

 

AzureActivity
| where OperationNameValue contains("Microsoft.Sql/servers/failoverGroups/failover/action") and ActivityStatusValue =="Start"

 

jaigarcimicrosoft_0-1705366009769.png

 

Creating alert ...

 

Based on the fact that is possible to create alert based on results of the query next step is to select option to create new alert rule

 

AzureActivity
| where OperationNameValue contains("Microsoft.Sql/servers/failoverGroups/failover/action") and ActivityStatusValue =="Start"

 

jaigarcimicrosoft_1-1705366094145.png

 

Now is possible to see that query is part of the alert (In this demo use basic configuration)

 

jaigarcimicrosoft_2-1705366212076.png

 

Alert logic configure that alert is fired when results are greater than 0

 

jaigarcimicrosoft_4-1705366370529.png

 

Next step is select action group ...

 

Action groups

https://learn.microsoft.com/en-us/azure/azure-monitor/alerts/action-groups

jaigarcimicrosoft_5-1705366543069.png

 

Select action group

 

jaigarcimicrosoft_6-1705366590277.png

 

Create alert rule

 

jaigarcimicrosoft_7-1705366692991.png

 

and finally create alert ...

 

jaigarcimicrosoft_8-1705366736409.png

 

Make failover in failover group 

 

jaigarcimicrosoft_9-1705366808746.png

 

Wait for failover ...

 

jaigarcimicrosoft_10-1705366897521.png

 

In some minutes email with alert will be received in email accounts defined in action group be patience because is not immediately ...

 

Finally email received ...

 

jaigarcimicrosoft_0-1705380694366.png

 

You can go to azure monitor and see alert sent ...

 

jaigarcimicrosoft_1-1705380794639.png

 

Sending activity log to workspace there are more actions or parameters that is possible to monitor now we can use same process to get alert when geodr failover is done only changing query

 

Alert for Geo replica

 

Change kusto query to look for different type of operation name value

 

AzureActivity
| where OperationNameValue contains("MICROSOFT.SQL/SERVERS/DATABASES/REPLICATIONLINKS/FAILOVER/ACTION") and ActivityStatusValue =="Start"

 

Create alert based on the result

 

jaigarcimicrosoft_2-1705381569509.png

 

jaigarcimicrosoft_3-1705381636776.png

 

jaigarcimicrosoft_4-1705381690976.png

 

jaigarcimicrosoft_5-1705381728802.png

 

jaigarcimicrosoft_6-1705381797089.png

 

jaigarcimicrosoft_7-1705381833506.png

 

Now is created then go to Azure SQL DB and make failover 

 

jaigarcimicrosoft_8-1705381915084.png

 

Now wait for email with alert remember that will take time is not live data  when is sent to workspace

 

Email received ...

 

jaigarcimicrosoft_0-1705383260474.png

 

 

1 Comment
Co-Authors
Version history
Last update:
‎Jan 16 2024 12:12 PM
Updated by: