Today I’ve written a simple powershell check for nagios to check if all the storage group scr replication is healthy.
Script
Param($sourceserver, $destinationserver)
$snapins = "Microsoft.Exchange.Management.Powershell.Admin"
$snapins | ForEach-Object {
if ( Get-PSSnapin -Registered $_ -ErrorAction SilentlyContinue ) {
Add-PSSnapin $_
}
}
$storagegroupcopystatus = Get-StorageGroupCopyStatus -Server $sourceserver -StandbyMachine $destinationserver
$status = 0;
$warning_array = @()
$perfdata_string_array = @();
foreach ($storagegroup in $storagegroupcopystatus)
{
if ($storagegroup.SummaryCopyStatus -ne 'Healthy')
{
$status = 2;
$warning_array += $storagegroup.StorageGroupName
}
$perfdata_string_array += "'Copy Queue Length - $($storagegroup.StorageGroupName)': " + $storagegroup.CopyQueueLength
$perfdata_string_array += "'Replay Queue Length - $($storagegroup.StorageGroupName)': " + $storagegroup.ReplayQueueLength
}
switch ($status)
{
0 {
$message = "OK - All storagegroups are correctly being replicated"
}
2 {
$warning_array_string = [string]::join(",", $warning_array)
$message = "ERROR - Storage Groups (" + $warning_array_string + ") are not correctly being replicated. Check replication!"
}
}
$perfdata_string = [string]::join(" ", $perfdata_string_array)
Write-Host "$($message) | $($perfdata_string)"
$host.SetShouldExit($status)
Entry in nsc.ini
check_exchange_scr=cmd /c echo scripts\check_exchange_scr.ps1 $ARG1$ $ARG2$ | powershell.exe -command -