Custom WMI - Monitor Terminal Server Sessions

Custom WMI - Monitor Terminal Server Sessions

I've created a custom WMI script to monitor terminal server sessions and thought I would share it with the opmanager community.

VBScript (goes in [...]\conf\application\scripts directory):

' Check command line parameters

On Error Goto 0
Set objWbemLocator = CreateObject("WbemScripting.SWbemLocator")
'On Error Resume Next
Select Case WScript.Arguments.Count
Case 1
strComputer = Wscript.Arguments(0)
Set wbemServices = objWbemLocator.ConnectServer(strComputer,"Root\CIMV2")

Case 3
strComputer = Wscript.Arguments(0)
strUsername = Wscript.Arguments(1)
strPassword = Wscript.Arguments(2)
Set wbemServices = objWbemLocator.ConnectServer(strComputer,"Root\CIMV2",strUsername,strPassword)

Case Else
strMsg = "Error # in parameters passed"
WScript.Echo strMsg
WScript.Quit(0)

End Select

if Err.Number Then
WScript.Echo vbCrLf & "Error # " & _
" " & Err.Description
End If
On Error GoTo 0

'On Error Resume Next
Set colItems = wbemServices.ExecQuery("Select * from Win32_PerfFormattedData_TermService_TerminalServices",,48)
if Err.Number Then
WScript.Echo vbCrLf & "Error # " & _
" " & Err.Description
End If
On Error GoTo 0

For Each objItem in colItems
WScript.Echo "TotalSessions" & vbTab & objItem.TotalSessions
WScript.Echo "ActiveSessions" & vbTab & objItem.ActiveSessions
WScript.Echo "InactiveSessions" & vbTab & objItem.InactiveSessions
Next

WScript.Quit(0)














































Addition to HostResource.xml:

<CATEGORY ID="Terminal Services Sessions" command="TSSessions.vbs" parseAll="false" description="Terminal Services Session Totals">
<ENTITY ID="TotalSessions" storeValue="Value2" storeHistory="true" units="Sessions">
<PARSE line="3" token="2" name="Value2"/>
</ENTITY>
<ENTITY ID="ActiveSessions" storeValue="Value3" storeHistory="true" units="Sessions">
<PARSE line="4" token="2" name="Value3"/>
</ENTITY>
<ENTITY ID="InactiveSessions" storeValue="Value4" storeHistory="true" units="Sessions">
<PARSE line="5" token="2" name="Value4"/>
</ENTITY>
</CATEGORY>













addition to opmanager_graphinfo.xml:

<DEFAULTGRAPH Name="Terminal Services Sessions">
<YAXISTEXT>Sessions</YAXISTEXT>
<DISPLAYNAME>Terminal Services Sessions</DISPLAYNAME>
<name>Terminal Services Sessions</name>
<Vendor>WMI</Vendor>
<Description>Monitors Terminal Servies Sessions</Description>
<oid>Terminal Services Sessions</oid>
<Provider>WMI</Provider>
<Monitor>Resource</Monitor>
<type>multiple</type>
<interval>600</interval>
<THRESHOLDENABLED>false</THRESHOLDENABLED>
</DEFAULTGRAPH>















This WMI monitor works, but I'm open to improvements or a better way to do it.

I'd love to see some sort of wizard for creating custom scripts built into OpManager. The scripts always follow the same basic template, so something that lets you select the WMI class and counters and also sets up the necessary changes to the hostresource and graphinfo files would be really slick.












                  New to ADSelfService Plus?