Community discussions

 
Morphology
just joined
Topic Author
Posts: 21
Joined: Mon Jan 26, 2009 7:51 pm

Extending The Dude using WMI - a short tutorial

Tue Mar 19, 2013 1:22 pm

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
Image1.jpg
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
Image2.jpg
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.

Imports System.Management
Module Module1
' 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)
Try
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
Console.WriteLine("-1")
Exit Sub
End Try
For Each mo In queryCollection
' create child node
Console.WriteLine(mo("NumberOfActiveSessions").ToString())
Next
End Sub

End Module

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)
Image3.jpg
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!
You do not have the required permissions to view the files attached to this post.
 
Morphology
just joined
Topic Author
Posts: 21
Joined: Mon Jan 26, 2009 7:51 pm

Re: Extending The Dude using WMI - a short tutorial

Tue Mar 19, 2013 1:24 pm

Now. Over to the Dude to create a new Probe called Citrix Active sessions:
Image4.jpg
This simply calls the .EXE we created above, passing in the name of the device to which the probe has been applied (in my case a Citrix server).

Apply this probe to your Citrix server and you’re done. I now have a nice Dude chart of the number of Active sessions on my Citrix server.
Image5.jpg
Enjoy!


Morph.
You do not have the required permissions to view the files attached to this post.
 
lebowski
Forum Guru
Forum Guru
Posts: 1614
Joined: Wed Aug 27, 2008 5:17 pm

Re: Extending The Dude using WMI - a short tutorial

Tue Mar 19, 2013 7:23 pm

Nice work Morph!

Who is online

Users browsing this forum: No registered users and 17 guests