Login Monitor Script & Check MK

Last night Paul Grevink posted a nice post about the basic setup for Check MK and i am really looking forward to the rest of the series. At my current customer we are also using Check MK so i decided to use the script I made for the VMware Login monitor fling to give output usable for Check MK. At first I was messing with the plugin folder in the check mk folder on the windows server hosting the txt files but a colleague pointed me at the local folder. The big difference is that with the local folder Check MK directly uses the output and the plugin monitor it needs another python file on the check mk server to use the data.

The script:

# This script was created by Wouter Kursten 
# contact: wouter.kursten@detron.nl or w.kursten@gmail.com or https://www.retouw.nl or @Magneet_NL on twitter
#
# Feel free to grab/copy/alter the script no need to mention me
# But if you create a better / more complete version please send me a mail so I can use that script also
#
# This script is meant to use with the VMware Logon Monitor FLing
# https://labs.vmware.com/flings/vmware-logon-monitor
# This awesome tools actually shows how long it takes to login to your systems
#
# And yes the info block is longer then the script itself
#
# There are only 5 variables you can set
#
# $filefolder for where the Logon Monitor Output files are stored
# $filefilter for when you want to filter what files are being read
# $fileage for how far back in time you want to go
# $warning for the warning value above wich Check MK will give a Warning.
# $critical Gues what, this is the value above wich Check MK will give a critical report.

#Region Variables
$filefolder= "d:\logonmonitor\"
$filefilter="*.txt"
$fileage="5"
$warning="20"
$critical="30"
#endregion

#region Run 

$filelocation="$filefolder"+"$filefilter"
$filelist=get-childitem "$filelocation" | where-object {$_.LastWriteTime -gt (get-date).addminutes(-$fileage)}
$count=($filelist).count
$timing=@()

foreach ($file in $filelist)
	{
	$duration=(get-content $file | select-string -pattern "LogSummary] Logon Time:" | %{$_ -split " "})[6]
	$timing += $duration
	}

$avg= $timing | measure-object -average  
$average = [System.Math]::Round($Avg.average,2)

if ($average -le "$warning")
	{
	write-output "0 VMware_Horizon_View_Logon_Time LogonTime=$average|Logons=$count Logon time : $average sec for $count logons in the last $fileage minutes."
	}
	elseif ($average -gt "$warning" -and $average -lt "$critical")
	{
	write-output "1 VMware_Horizon_View_Logon_Time LogonTime=$average|Logons=$count Logon time : $average sec for $count logons in the last $fileage minutes."
	}
	elseif ($average -ge "$critical")
	{
	write-output "2 VMware_Horizon_View_Logon_Time LogonTime=$average|Logons=$count Logon time : $average sec for $count logons in the last $fileage minutes."
	}
#endregion

As you can see I am not only using the average logontime as before, I also count the amount of logons in the time where we measure this time. Offcourse you can create lots more data to use in Check MK this way

The output I create:

"2 VMware_Horizon_View_Logon_Time LogonTime=$average|Logons=$count Logon time : $average sec for $count logons in the last $fileage minutes."
  • The first digit is the status, 0 for ok 1 for warning and 2 for critical.
  • After that the service name that shows in Check MK
  • The come the 2 numbers we created with their own description separated by | This is used by Check MK to create a diagram
  • then separated by a space (and after this you can use spaces) the text that wil show in Check MK.

The result:

2016-08-11 21_12_01-Beheerders Desktop

The diagram:

2016-08-11 21_14_01-Beheerders Desktop

Bookmark the permalink.

Comments are closed.