LoginSignup
2
1

More than 3 years have passed since last update.

Azure Site Recoveryの同期ステータスを取得する

Posted at

Azure Site RecoveryでDRサイトへのレプリケーションを設定し、同期に異常があった場合、監視ツールで検知したい。
このような要望は良くあると思います。
Azure PowerShellを使用することで同期ステータスを取得してログ出力等が可能です。
ここではWindowsサーバのイベントログに出力するサンプルを記載します。

ASRのステータスを取得

まずはASRのステータスを取得します。

# Recover Servicesコンテナのコンテキストを設定
$RSCVault = Get-AzRecoveryServicesVault -Name "containername"
Set-ASRVaultContext -Vault $RSCVault

$fabrics = Get-AzRecoveryServicesAsrFabric
$items = $null

foreach($fabric in $fabrics) {
    $container = Get-AzRecoveryServicesAsrProtectionContainer -Fabric $fabric | Where-Object { $_.Role -eq "Primary"}
    $item = Get-AzRecoveryServicesAsrReplicationProtectedItem -ProtectionContainer $container
    if (!$item){
        continue
    }
    $items += $item
}

Windowsイベントログに出力

上記の処理でステータスが取得できましたので異常があった場合にイベントログに出力します。
イベントソースは事前に任意の名前で登録しておいてください。

foreach($item in $items) {
    $LogMessage = "$(${item}.FriendlyName) のASRステータス:$(${item}.ReplicationHealth)"
    Write-Host $LogMessage

    if ($item.ReplicationHealth -eq "Normal") {
        continue
    }
    # イベントログに出力
    Write-EventLog -LogName Application -Source "Azure-ASRStatus" -EventId 1 -EntryType Error -Message $LogMessage
}

結果

同期が正しく行われている場合はイベントログに出力されません。
ただし、仮想マシンが停止している場合でも異常と検知されますので夜間やメンテナンス時に停止する場合は注意が必要です。

xxxxxx ASRステータス:Critical

WindowsEventlog.png

最後に

これでステータスの取得とイベントログ出力が出来るようになりました。
あとは、ジョブスケジューラ等を使って定期的にステータスを取得すれば短い時間で異常が検知できるようになります。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1