It took me hours to get this running... This script counts all mails in all queues on a MS Exchange Server 2007 and returns the sum to PRTG. Tested with PRTG 8.4.2.2381.
Option Explicit ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Script by [email protected] 2011 ' Script to count mails in ALL queues on a Microsoft Exchange Server 2007. ' This script is designed to put the values back to PRTG for monitoring. ' ' 1) Copy this script to ' <PRTG Installation Path>\Custom Sensors\EXE on the target server ' where your devive is configured. ' 2) Create a new Custom Sensor (EXE/Script) on a device (most likely the ' device which is running the Microsoft Exchange Server 2007). ' 3) Give the Sensor a name ' 4) Under "EXE/Script" choose this script ' 5) Under "Parameters" type the following: SERVERNAME WARNING_VALUE_1 WARNING_VALUE_2 ' 6) Under "Channel Name" type for example "MS EXC Queue" ' 7) Under "Unit String" type for example "mails" ' 8) Save. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Dim objPing Dim objStatus Dim objShell Dim strComputer, strPSCommand, strShellCommand, intMessageCount, intOK, intWarning1, intWarning2 'Get the Parameters strComputer = Wscript.Arguments(0) intWarning1 = Wscript.Arguments(1) intWarning2 = Wscript.Arguments(2) 'Check if Server is online '(this block can be simply removed if you do not want to check the onlien state, 'but note that the Sensor remains OK (green) if the server goes offline) Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._ ExecQuery("select Replysize from Win32_PingStatus where address = '" & strComputer & "'") For Each objStatus in objPing If IsNull(objStatus.ReplySize) Then WScript.Echo "Server " & strComputer & " is offline!" WScript.Quit("4") End If Next Set objPing = Nothing Set objStatus = Nothing 'Run Powershell to count the messages strPSCommand = "Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin; $MessageCount = get-queue -server " & strComputer & " | foreach -begin {$total=0} -process {$total+=$_.messageCount} -end {$total}; exit $MessageCount" strShellCommand = "c:\windows\sysnative\windowspowershell\v1.0\powershell.exe -command " & strPSCommand Set objShell = CreateObject("WScript.Shell") intMessageCount = objShell.Run(strShellCommand, , True) Set objShell = Nothing 'Return values and messages to PRTG If intMessageCount < intWarning1 Then WScript.Echo intMessageCount & ":OK" WScript.Quit("0") ElseIf intMessageCount < intWarning2 Then WScript.Echo intMessageCount & ":Unlikely many mails in Queue" WScript.Quit("1") Else WScript.Echo intMessageCount & ":Too many mails in Queue, please check" WScript.Quit("1") End if
Enjoy, Mike
Add comment