Skip to content

Instantly share code, notes, and snippets.

@liveaverage
Created July 29, 2014 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save liveaverage/a042417f78e84a6d0259 to your computer and use it in GitHub Desktop.
Save liveaverage/a042417f78e84a6d0259 to your computer and use it in GitHub Desktop.
Local Check_MK: check_Exchange_StorageGroups.ps1
$Host.UI.RawUI.BufferSize = New-Object Management.Automation.Host.Size(900,900)
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin
$check_name = "Exchange_SG_CopyStatus"
$OK = 0
$Warn = 1
$Crit = 2
$Unk = 3
$now = Get-Date
$deltac = -1.0
$deltaw = -0.5
$deltatc = $now.AddHours($deltac)
$deltatw = $now.AddHours($deltaw)
#Populate SG's to check based on current domain (obtained from calling user). Make sure these are SG's that should be replicating by checking target node:
[array]$SGS = Get-ExchangeServer -Domain ([System.DirectoryServices.ActiveDirectory.Domain]::getCurrentDomain()).Name | ?{$_.ServerRole -eq "Mailbox"} | Get-StorageGroupCopyStatus | ?{$_.CCRTargetNode -ne $null}
#echo $deltatc
#echo $deltatw
Function get-epochdate ($epochdate) { [timezone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddSeconds($epochdate)) }
$statustxt = ""
$retw = 0
$retc = 0
$reto = 0
foreach ($s in $SGS)
{
#Generate dynamic check names for inventory based on SG Name:
$Check = $check_name+"_"+($s.StorageGroupName).Replace(" ", "_")
#Check Output
echo "`<`<`<local`>`>`>"
#If healthy and inspection time is within CRIT and WARN delta thresholds, then we're good:
if ($s.SummaryCopyStatus -eq "Healthy" -and ($s.LastInspectedLogTime -gt $deltatc -and $s.LastInspectedLogTime -gt $deltatw))
{
echo "$Ok $Check - OK - $($s.StorageGroupName) is $($s.SummaryCopyStatus). LastInspected $($s.LastInspectedLogTime)"
}
#If healthy but inspection time is stale (WARN):
elseif ($s.SummaryCopyStatus -eq "Healthy" -and ($s.LastInspectedLogTime -gt $deltatc -and $s.LastInspectedLogTime -lt $deltatw))
{
echo "$Warn $Check - WARN - Stale time. $($s.StorageGroupName) is $($s.SummaryCopyStatus). LastInspected $($s.LastInspectedLogTime)"
}
#If healthy but inspection time is stale (CRIT):
elseif ($s.SummaryCopyStatus -eq "Healthy" -and ($s.LastInspectedLogTime -gt $deltatc -and $s.LastInspectedLogTime -lt $deltatw))
{
echo "$Crit $Check - CRIT - Stale time. $($s.StorageGroupName) is $($s.SummaryCopyStatus). LastInspected $($s.LastInspectedLogTime)"
}
#If not healthy, disregard inspection time and alarm CRIT:
elseif ($s.SummaryCopyStatus -ne "Healthy")
{
echo "$Crit $Check - CRIT - $($s.StorageGroupName) is $($s.SummaryCopyStatus). LastInspected $($s.LastInspectedLogTime)"
}
else
{
echo "$Unk $Check - UNKNOWN - Problem evaluating health. $($s.StorageGroupName) is $($s.SummaryCopyStatus). LastInspected $($s.LastInspectedLogTime)"
}
}
@liveaverage
Copy link
Author

Checks the replication health of each Storage Group that has a CCRTargetNode defined. Also checks the "freshness" of the LastInspectedLogTime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment