Skip to content

Instantly share code, notes, and snippets.

@liveaverage
Created July 29, 2014 13:48
Show Gist options
  • Save liveaverage/c09b3417e4a7fb1e46aa to your computer and use it in GitHub Desktop.
Save liveaverage/c09b3417e4a7fb1e46aa to your computer and use it in GitHub Desktop.
Local Check_MK: check_Exchange_SG_LogTruncate.ps1
$Host.UI.RawUI.BufferSize = New-Object Management.Automation.Host.Size(900,900)
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin
$check_name = "Exchange_SG_LogTrunc"
$OK = 0
$Warn = 1
$Crit = 2
$Unk = 3
$now = Get-Date
$deltac = -48.0
$deltaw = -36.0
$deltatc = $now.AddHours($deltac)
$deltatw = $now.AddHours($deltaw)
#Populate local domain name:
$dcs = [System.DirectoryServices.ActiveDirectory.Domain]::getCurrentDomain()
#Test for clustered mailbox server:
$cls = Get-ClusteredMailboxServerStatus -ErrorAction SilentlyContinue
#Populate local hostname or clustername if applicable:
$lhn = if ($cls -ne $null) { $cls.Identity.Name } else { [System.Net.Dns]::GetHostName() }
#Populate MB server info for user domain relative to local hostname (we're checking local storage paths):
$sgl = Get-ExchangeServer -Domain $dcs.Name | ?{$_.ServerRole -match "Mailbox" -and $_.Name -match $lhn} | %{Get-StorageGroup -Server $_.Identity}
if ($sgl -ne $null)
{
#Populate log files using SG storage info:
foreach ($s in $sgl)
{
$Check = $check_name+"_"+($s.Name).Replace(" ", "_")
$logitems = Get-ChildItem -Path $s.LogFolderPath -Filter *.log | Sort-Object -Property LastWriteTime
if ($logitems[0].LastWriteTime -lt $deltatw -and $logitems[0].LastWriteTime -gt $deltatc)
{
echo "$Warn $Check - WARN - $($s.Name) has oldest log: $($logitems[0].LastWriteTime)."
}
elseif ($logitems[0].LastWriteTime -lt $deltatw -and $logitems[0].LastWriteTime -lt $deltatc)
{
echo "$Crit $Check - CRIT - $($s.Name) has oldest log: $($logitems[0].LastWriteTime)."
}
elseif ($logitems[0].LastWriteTime -gt $deltatw -and $logitems[0].LastWriteTime -gt $deltatc)
{
echo "$Ok $Check - OK - $($s.Name) has oldest log: $($logitems[0].LastWriteTime)."
}
else
{
echo "$Unk $Check - UNKOWN - $($s.Name) can't enumerate oldest log: $($logitems[0].LastWriteTime)."
}
}
}
else
{
$Check = $check_name+"_PROBLEM"
echo "$Unk $Check - UNKOWN - $lhn can't enumerate oldest log. Is this a mailbox server?"
}
@liveaverage
Copy link
Author

Enumerates Exchange Storage Group logs and determines whether or not to alarm on "old" logs that have likely not been truncated following successful/unsuccessful bakcup.

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