Advertisement
Guest User

Exchange 2010 Queue Health

a guest
Jun 21st, 2012
1,398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Test Queue Health
  2. #
  3. # This script will look at each queue and determine the status of each.
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License
  7. # as published by the Free Software Foundation; either version 2
  8. # of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. #
  19. #
  20. #
  21. # History:
  22. #   Version 1.x
  23. #     Originally created by Joshua Kirkes (joshua@awesomejar.com)
  24. #     at AwesomeJar Consulting, LLC in San Francisco, CA
  25. #
  26. #   Revision 1.1
  27. #    Created by Marc Koene
  28. #
  29. #   Version 2.0 (with performance data)
  30. #    Created by Bastian W. [Bastian@gmx-ist-cool.de]
  31. #
  32. #
  33. # Revision History
  34. # 2011-05-23    Joshua Kirkes       Created 1.0
  35. # 2011-07-07    Marc Koene          Revision 1.1
  36. # 2011-09-19    Bastian W.          2.0:
  37. #                                     * Added variable for the hubserver
  38. #                                     * checked if PSSnapin is loaded
  39. #
  40. # 2012-02-24    Bastian W.          2.1:
  41. #                                     * added Nagios performance counters
  42. #
  43. #
  44. # To execute from within NSClient++
  45. #
  46. # [NRPE Handlers]
  47. # check_exchange_mailqueue=cmd /c echo C:\Scripts\Nagios\NagiosMonitoring_ExchangeQueueHealth.ps1 | PowerShell.exe -Command -
  48. #
  49. # On the check_nrpe command include the -t 30, since it takes some time to load the Exchange cmdlet's.
  50.  
  51. if ( (Get-PSSnapin -Name Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction:SilentlyContinue) -eq $null)
  52. {
  53.     Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
  54. }
  55.  
  56. $NagiosStatus = "0"
  57. $NagiosDescription = ""
  58. $NagiosPerfData = ""
  59.  
  60. ForEach ($Queue in Get-Queue -Server $env:computername)
  61. {
  62.  
  63.             # Look for lagged queues - critical if over 100
  64.                 if ($Queue.MessageCount -gt "100" )
  65.                 {
  66.                     # Format the output for Nagios
  67.                     if ($NagiosDescription -ne "")
  68.                     {
  69.                         # we already have a message queue description, so we will add a separator
  70.                         $NagiosDescription = $NagiosDescription + ", "  
  71.                     }
  72.                     $NagiosDescription = $NagiosDescription + $Queue.MessageCount + " messages to " + $Queue.NextHopDomain
  73.            
  74.                     # Set the status to failed.
  75.                     $NagiosStatus = "2"
  76.        
  77.                 # Look for lagged queues - warning if over 50
  78.                 }
  79.                 elseif ($Queue.MessageCount -gt "50")
  80.                 {
  81.                     # Format the output for Nagios
  82.                     if ($NagiosDescription -ne "")  
  83.                     {
  84.                         # we already have a message queue description, so we will add a separator
  85.                         $NagiosDescription = $NagiosDescription + ", "
  86.                     }
  87.                    
  88.                     $NagiosDescription = $NagiosDescription + $Queue.MessageCount + " messages to " + $Queue.NextHopDomain
  89.            
  90.                     # Don't lower the status level if we already have a critical event
  91.                     if ($NagiosStatus -ne "2")
  92.                     {
  93.                         $NagiosStatus = "1"
  94.                     }
  95.                 }
  96. }
  97.  
  98.  
  99. # Output, what level should we tell our caller?
  100. $NagiosPerfData = "|queue=" + $Queue.MessageCount + ";10;20;0"
  101. $NagiosPerfData = $NagiosPerfData -replace " ", ""
  102.  
  103. if ($NagiosStatus -eq "2")
  104. {
  105.     Write-Host "CRITICAL: " $NagiosDescription" "$NagiosPerfData
  106. }
  107. elseif ($NagiosStatus -eq "1")
  108. {
  109.     Write-Host "WARNING: " $NagiosDescription" "$NagiosPerfData
  110. }
  111. else
  112. {
  113.     Write-Host "OK: All mail queues within limits. "$NagiosPerfData
  114. }
  115.  
  116. exit $NagiosStatus
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement