In Azure, how can you configure an alert or notifi

2019-08-28 18:21发布

问题:

In Azure, how can you configure an alert or notification when a SQL Server failover happened if you setup a SQL server with Failover groups and failover policy is set to automatic? If it can't be setup in Monitor can it be scripted elsewhere?

回答1:

Azure SQL database only support these alert metrics:

We could not using the alert when SQL Server failure happened. You can get this from this document: Create alerts for Azure SQL Database and Data Warehouse using Azure portal.

Hope this helps.



回答2:

Found a way to script this in Azure using Automation Accounts > Runbook > using Powershell. A simple script like this should do it. Just need to figure out the run as account and trigger it by schedule or alert.

function sendEmailAlert
{
    # Send email
}


function checkFailover
{
    $list = Get-AzSqlDatabaseFailoverGroup -ResourceGroupName "my-resourceGroup" -server "my-sql-server"

    if ( $list.ReplicationRole -ne 'Primary')
    { 
        sendEmailAlert
    }
}

checkFailover