A simple way to send an alert if your Always On Availability Group fails over. You can run the t-sql below or set it up visually in SQL Agent.
USE [msdb] /* Sends an alert if the AG group fails over. I've limited the requests to one alert per group (by specifying the DB name in @event_description_keyword Let me know what you think of this approach, I found it better than multiple alerts for each DB in the Availability Group */ EXEC msdb.dbo.sp_add_alert @name=N'AG role change - AG1', @message_id=1480, @severity=0, @enabled=1, @delay_between_responses=0, @include_event_description_in=1, @database_name=N'', @event_description_keyword=N'PRD_DB1', @notification_message=N'There has been a failover of your Always On Availability Group AG1 - Please investigate.', @job_id=N'00000000-0000-0000-0000-000000000000' -- Add an operator if it doesn't already exist EXEC msdb.dbo.sp_add_operator @name=N'John McCormack', @enabled=1, @pager_days=0, @email_address=N'john.mccormack@example.com' -- Add a notification EXEC msdb.dbo.sp_add_notification @alert_name=N'AG role change - AG1', @operator_name=N'John McCormack', @notification_method = 1
Leave a Reply