Tag Archives: Monitoring

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!

New Nagios Plugin

Last Friday going into the weekend I ran across a snapshot on one of my VMware hosts almost 160 days old, OUCH. The right tool to keep that from happening is definitely Nagios. NagiosExchange didn’t really have a solution for my problem that I could find. Somebody has written a snapshot age tool in PowerShell but I’m not interested in having plugins run on hosts that aren’t my main Nagios server. I was given a fun project to work on.

The vSphere Command Line Interface (formerly the PERL toolkit if I’m not mistaken) was of little help. It didn’t really give me any interface into snapshot data at all. I decided the simplest solution would be to work right on the BusyBox console. I started Friday around noon and working on it here and there over a couple days came up with a usable product yesterday morning:

[jrdalrymple@nagios ~]$ /usr/local/nagios/libexec/check_snapshot.py
No password specified
usage: check_snapshot.py -H hostname [-U username] <-P password | -f PasswordFile>
[jrdalrymple@nagios ~]$ sudo /usr/local/nagios/libexec/check_snapshot.py -H 172.16.100.11 -U nagioschk -f /home/nagios/.check_esxi_hw.pw -w 10 -c 20

3 VMs are CRITICAL
Guest example1.domain.local has snapshot 24 days old!
Guest example2.domain.local has snapshot 28 days old!
Guest example3.domain.local has snapshot 26 days old!

Clipboard03

The results between my command line run and the Nagios GUI aren’t the same because I gave the Nagios check different thresholds.

I’ll probably put it up on Nagios Exhange at some point. For now I’ll just feel accomplished.