Extracting Perf Data from Powershell Output
Posted: Tue Mar 27, 2018 10:17 am
Hello everyone,
A colleague recently provided me with a PowerShell script to determine if any outgoing emails are being blocked by Office 365 from our Exchange server. I was able to tweak the script to return Nagios exit codes and attempted to code to enable performance data for graphing. The script runs successfully in Nagios but I do not see any graphs or performance data when viewing the host from the XI webpage. I tried looking online for performance data guides but I did not find any that went into details for a beginner. I looked at another plugin that provides graphing and mimicked it to no success. It seems that I'm missing something but can not figure out the last piece. I have attached the PowerShell code and the NSClient config file for review. Any help would be greatly appreciated.
A colleague recently provided me with a PowerShell script to determine if any outgoing emails are being blocked by Office 365 from our Exchange server. I was able to tweak the script to return Nagios exit codes and attempted to code to enable performance data for graphing. The script runs successfully in Nagios but I do not see any graphs or performance data when viewing the host from the XI webpage. I tried looking online for performance data guides but I did not find any that went into details for a beginner. I looked at another plugin that provides graphing and mimicked it to no success. It seems that I'm missing something but can not figure out the last piece. I have attached the PowerShell code and the NSClient config file for review. Any help would be greatly appreciated.
Code: Select all
# Micrsoft Office 365 - Am I Blocked?
# NagiosXI Version 1.0
# Ovidiu Diaconeasa & Jose Lugo
if ( (Get-PSSnapin -Name Microsoft.Exchange.Management.PowerShell.SnapIn -ErrorAction:SilentlyContinue) -eq $null)
{
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.SnapIn
}
$NagiosStatus = "0"
$NagiosDescription = ""
$NagiosPerfData = ""
$failedlast15 = (get-messagetrackinglog -Start (Get-Date).AddMinutes(-15) -End (Get-Date) -eventid FAIL -result unlimited)
$failedcount = ($failedlast15 | Select EventId | Select-String -Pattern "FAIL" -AllMatches).count
$failedextern = ($failedlast15 | Select @{Name=’RecipientStatus’;Expression={[string]::join(“;”, ($_.RecipientStatus))}} | Select-String -Pattern "550 5.7.750" -AllMatches).count
# Query Blocked Emails - critical if greater than/equal to 5
if ($failedextern -ge "5" )
{
# Format the output for Nagios
if ($NagiosDescription -ne "")
{
$NagiosDescription = "Microsoft Office 365 has blocked $failedcount emails."
}
# Set Nagios Alert to Critical.
$NagiosStatus = "2"
# Query Blocked Emails - WARNING if over 1
}
elseif ($failedextern -ge "1")
{
# Format the output for Nagios
if ($NagiosDescription -ne "")
{
$NagiosDescription = "Microsoft Office 365 has blocked $failedcount emails."
}
}
# What alerts to return to NagiosXI?
$NagiosPerfData = "|Blocked Emails=" + $failedcount + ";10;20;0"
$NagiosPerfData = $NagiosPerfData -replace " ", ""
if ($NagiosStatus -eq "2")
{
Write-Host "CRITICAL: " $NagiosDescription" "$NagiosPerfData
}
elseif ($NagiosStatus -eq "1")
{
Write-Host "WARNING: " $NagiosDescription" "$NagiosPerfData
}
else
{
Write-Host "OK: All Microsoft Exchange Traffic Allowed."
}
exit $NagiosStatus