# Test SMTP QUEUE ON EXCHANGE 2010 # # This script will execute the "Get-queue" command and look for how much e-mail are in the queue # # Example: # Identity DeliveryType Status MessageCount NextHopDomain # -------- ------------ ------ ------------ ------------- # SERVER\173821 MapiDelivery Ready 0 db01 # SERVER\173832 MapiDelivery Ready 0 db04 # SERVER\173833 SmartHost... Ready 0 [192.17.70.131],[192.17.70.132] # SERVER\173834 MapiDelivery Ready 0 db02 # SERVER\Submission Undefined Ready 0 Submission # SERVER\Unreachable Unreachable Ready 5 Unreachable Domain # SERVER\Shadow\173808 ShadowRed... Ready 1 EXTERNAL.domain.dom # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # # Revision History # 2014-08-07 Roberto C. [robertocaramia@hotmail.com] 1.0 code initial created # Thanks to Bastian W. (Bastian@gmx-ist-cool.de) for the plugin schema # # # To execute from within NSClient++ # [/settings/external scripts] # allow arguments = true # # [/settings/external scripts/wrapped scripts] # alias_check_queue = NagiosMonitoring_Exchange-queue.ps1 $ARG1$ $ARG2$ $ARG3$ # On the check_nrpe command include the -t 60, since it takes some time to load # the Exchange cmdlet's. # Check command on Nagios machine # /usr/lib/nagios/plugins/check_nrpe -H $HOSTADDRESS$ -t 60 -c alias_check_queue -a $ARG1$ $ARG2$ $ARG3$ #Parameters that you have to set for the check #$server is the fqdn of the CAS to check ($ARG1$) #$critical is the threshold you think is critical ($ARG2$) #$warning is the threshold you think is warning ($ARG3$) param($server="",$critical="",$warning="") #Check if the param are set if($server -eq "" -or $critical -eq "" -or $warning -eq "") { Write-Output "WARNING" Write-Output "You have to set the CAS-SERVER, the CRITICAL threshold, and WARNING threshold" exit } #Check and load Exchange Management PowerShell if ( (Get-PSSnapin -Name Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction:SilentlyContinue) -eq $null) { Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 } $NagiosStatus = "0" $NagiosDescription = "" ForEach ($Type in Get-Queue -Server $server ) { if ($Type.MessageCount -gt "$critical") { # Look for threshold critical if ($NagiosDescription -ne "") { # Format the output for Nagios $NagiosDescription = $NagiosDescription + ", " } $NagiosDescription = $NagiosDescription + $Type.Identity + " = " + $Type.MessageCount # Set the status to failed. $NagiosStatus = "2" } if ($Type.MessageCount -gt "$warning") { # Look for threshold warning if ($NagiosDescription -ne "") { # Format the output for Nagios $NagiosDescription = $NagiosDescription + ", " } $NagiosDescription = $NagiosDescription + $Type.Identity + " = " + $Type.MessageCount # Set the status to WARNING. $NagiosStatus = "1" } } # Output, which string should we write to Nagios? if ($NagiosStatus -eq "2") { Write-Host "CRITICAL:"$NagiosDescription } elseif ($NagiosStatus -eq "1") { Write-Host "WARNING:"$NagiosDescription } else { Write-Host "OK: all e-mail are gone!" } exit $NagiosStatus