Scripts: MRTG

Some useful scripts mostly vbs/wmi for MRTG monitoring.

Usage: Test as you will but within your MRTG config file use in place of the SNMP OID’s example below.

Target[TS_SESSIONS]: `cscript //nologo c:\MRTG\scripts\TS-sessions.vbs SERVER_HOSTNAME`

Exchange

Reports back the number of mailboxes/items stored on the Exchange server.

On Error Resume Next

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

arrComputers = Array("EXCHANGE_SERVER")'Lets not forget to enter the host name of your exchange server
For Each strComputer In arrComputers
   Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\MicrosoftExchangeV2")
   Set colItems = objWMIService.ExecQuery("SELECT * FROM Exchange_Mailbox", "WQL", _
                                          wbemFlagReturnImmediately + wbemFlagForwardOnly)

i = 0
t = 0
	For Each objItem In colItems
		t = t + objItem.TotalItems
		i = i + 1
	Next
Next

WScript.echo t
WScript.echo i

System

MRTGSize.exe: Not just for MRTG but pass it 2 file paths as arguments and it will return there respective file sizes. My original use was to monitor the size of my Exchange EDB and STM files.

Use in your MRTG config something like below.

Target[edstsi]: `c:\MRTG\scripts\MRTGSize.exe \\UNC-PATH\d$\Exchsrvr\mdbdata\priv1.edb \\amsc-ex01\d$\Exchsrvr\mdbdata\priv1.stm`

You can download the executable Here

Terminal Services

Reports back the number of active/Total sessions on a Terminal Server grate for user trending.

On Error Resume Next

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

arrComputers = Array("SERVER_HOSTNAME")
For Each strComputer In arrComputers

   Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
   Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PerfFormattedData_TermService_TerminalServices", "WQL", _
                                          wbemFlagReturnImmediately + wbemFlagForwardOnly)

   For Each objItem In colItems
      WScript.Echo objItem.ActiveSessions
      WScript.Echo objItem.TotalSessions
   Next
Next

Thats all i have for now but feel frre to post request and questions.
No Comments

Leave a Reply

Spam Protection by WP-SpamFree

Using Gravatars in the comments - get your own and be recognized!

XHTML: These are some of the tags you can use: <a href=""> <b> <blockquote> <code> <em> <i> <strike> <strong>