A short tutorial on extending the Dude using WMI.
We run a Citrix farm for publishing certain applications to our users. We used to run Citrix MetaFrame XP, which made quite a lot of information available via SNMP.
One of the metrics we quite liked as a measure of how busy each server was and whether the farm was balancing resources correctly, was the Citrix Active Sessions count. I had a Dude SNMP probe running and graphing the Active sessions count on all the servers.
Then we upgraded to Citrix XenServer and discovered that Citrix, in their wisdom, had removed most of the useful SNMP OIDs, but had extended the amount of information available via WMI, so I set out to enable the Dude to query WMI, and this is what I did:
I created a windows Console app using VB.NET v10. I am using the FREE Visual Basic 2010 Express edition.
Bear in mind that I am specifically creating a Citrix Active Sessions probe so if you are creating a probe to measure something else (number of people logged into your windows domain, for example), rename everything accordingly, and you will need to change the Windows System Management object query string to grab the correct data via WMI.
I created a very simple VB console App (DOS .EXE file for people over a certain age), which takes a single command line argument (The server name), and runs a WMI query that returns the number of logged-in users
1) Create a new Console Application project and call it Citrix Active Sessions
2) Add a reference to System management
a. Project->Add Reference
b. Select the .NET tab in the dialog
c. Scroll down the list and highlight System.Management
d. Click OK
3) Add a reference within the project to System Management
a. This is the ‘Imports System.Management’ line in the code listing below. Note that this has to be outside any Module in the project.
b. Create or Modify the Main() program directory and add in the following code.
c. Note that the Domain administrator account and password are hard-coded in this example, but you could always pass these in as command line arguments if you’re unhappy about setting them in stone.
' WMI Console App that takes WMI arguments via the command line, and
' passes back values.
' Richard R. Goodwin Mar 2012
Sub Main(ByVal sArgs() As String)
Dim co As ConnectionOptions
Dim query As ManagementObjectSearcher
Dim oq As System.Management.ObjectQuery
Dim ms As System.Management.ManagementScope
Dim queryCollection As ManagementObjectCollection
Dim mo As ManagementObject
Dim CommandLineArgs As System.Collections.ObjectModel.ReadOnlyCollection(Of String) = My.Application.CommandLineArgs
co = New ConnectionOptions
co.Impersonation = 3
co.Username = "MyDomain\MyDomainAdmin"
co.Password = "AdminPassword"
ms = New System.Management.ManagementScope("\\" & CommandLineArgs(0) & "\root\citrix", co)
oq = New System.Management.ObjectQuery("SELECT * FROM Metaframe_Server")
query = New ManagementObjectSearcher(ms, oq)
queryCollection = query.Get()
Catch e1 As Exception
'Probably need some better exception handling here.
'I am merely returning -1 as an error code
queryCollection = Nothing
For Each mo In queryCollection
' create child node
Build the .EXE file, then test it in a DOS Box. I keep all scripts such as this in a C:\Scripts directory on the Dude server (This is necessary so that the Dude can call it)
This shows the results of running the .EXE and passing both a non-existant and a real server name to it (however, nobody was logged into Citrix when I ran it!).
Continued in a new post, as you can only post 3 attachments!