Monitor Citrix License Usage with Cacti on Linux

There is this:

http://forums.cacti.net/about25193.html

It’s useless if your Cacti host is running on a non-Windows host. The suggestion to use wmic is alright, but for some reason the Linux wmic binary doesn’t query properly:

bash-4.1$ /usr/bin/wmic --namespace='root\CitrixLicensing' --authentication-file='/etc/cacti/cactiwmi.pw' //hostname.domain.local 'SELECT Count FROM Citrix_GT_License_Pool'
CLASS: Citrix_GT_License_Pool
Count|DUP_GROUP|FLOAT_OK|HOST_BASED|HOSTID|PLATFORMS|PLD|Subscriptionate|USER_BASED|VendorString6|8|False|0|||MPS_ADV_CCU|20141216000000.000000+000|0|;LT=Retail;GP=720;CL=ADV,STD,AST;SA=1;ODP=0

I haven’t the foggiest why, nor did I care to dig into the source when I’m such a pro at spaghetti stringing weird crap together to achieve a goal. The answer is the ability to run Powershell scripts natively on Linux, but it hasn’t happened yet.

Without describing the thought process that got me there I’ll just describe the final product. In Cacti it you start with a “Data Input Method,” this is what it looks like:

The script is a simple bash script that looks like this:

#!/bin/sh
ssh $1 -l $2 "powershell.exe -inputformat none -noprofile -File \"C:\cygwin64\home\sshd\ctx_license_check.ps1\""

The reason I didn’t run ssh directly from cacti is because passing the parameters isn’t really easy/possible after Cacti does all of its munging on the script. In case it isn’t obvious the script ssh’s to the host specified by argument 1 using the username specified by argument 2 and then runs a Powershell script. Since this script is run by the cacti user I had to configure passwordless (shared key) logon for that user from my Linux host to my license server. In order for ANY of this to work I had to install Cygwin and sshd on my license server, the tutorial I followed is here:

http://www.howtogeek.com/howto/41560/how-to-get-ssh-command-line-access-to-windows-7-using-cygwin/

I created a local user on my Windows box, sshd. That user needed administrative privileges, which sucks but since it’s a local account I don’t care too much as the password for the account can be shredded at this point. Also I did have to go into the WMI security properties for the WMI namespace “root\CitrixLicensing” and grant enable rights for that user there:

The last part to get the data out of the host is the Powershell script. I’m not a Powershell expert, or even a rookie really. This is what I wrote to get the data:

$inuse = Get-WmiObject -namespace root\citrixlicensing -class Citrix_GT_License_Pool | Select-Object -ExpandProperty InUseCount
$total = Get-WmiObject -namespace root\citrixlicensing -class Citrix_GT_License_Pool | Select-Object -ExpandProperty Count
Write-host "inuse:$inuse total:$total"

Suggestions are welcome, it works.

Cacti’s expected return values are something like this:

value_name1:value value_name2:value

My actual output looked like this:

inuse:2 total:6

This isn’t going to be a how to build graphs in Cacti tutorial, so with that I’m happy to attach my graph template and all this. You can import it on your end to see what I did. This is what the final result looks like:

 

Edit:

After installing some more licenses the check broke. My PS1 started returning results like

inuse:0 4 total:5 6

which is representative of 2 seperate license files. It was simple enough to fix as the results from the WMI query com reliably through as arrays – no string manipulation necessary:

$inuse = Get-WmiObject -namespace root\citrixlicensing -class Citrix_GT_License_Pool | Select-Object -ExpandProperty InUseCount
$total = Get-WmiObject -namespace root\citrixlicensing -class Citrix_GT_License_Pool | Select-Object -ExpandProperty Count
$suminuse = 0
$sumtotal = 0
foreach ($c in $inuse)
{$suminuse += $c}
foreach ($c in $total)
{$sumtotal += $c}
Write-host "inuse:$suminuse total:$sumtotal"

Back in business!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>