monitors:lsmon

no way to compare when less than two revisions

Differences

This shows you the differences between two versions of the page.


monitors:lsmon [2010/04/28 06:45] (current) – created - external edit 127.0.0.1
Line 1: Line 1:
 +====== lsmon.vbs ======
 +
 +^ Author | [[ goldfndr@gmail.com | Richard Finegold ]] |
 +^ Compatibility | Xymon or Big Brother |
 +^ Requirements | VBScript and BBWin and lsmon.exe on client |
 +^ Download | None |
 +^ Last Update | 2010-02-25 |
 +
 +===== Description =====
 +This reports (and optionally graphs) licenses used by Sentinel RMS (formerly known as SentinelLM). For example, [[http://www.csiberkeley.com/products_SAP.html|SAP2000]], [[http://www.structurepoint.org/soft/soft_profile.asp?l_family_id=38/|spColumn]] and its predecessor PCAColumn, some versions of Eagle Point, old versions of Haestad Methods (pre-Bentley).
 +  * Simple check for server: ''lservnt.exe'' is present
 +  * Simple check for client: ''lshost'' or ''lsforcehost'' environment variable on client that points to server
 +  * Simple software check: ''WlmAdmin.exe'' is present on server or client
 +
 +===== Installation =====
 +=== Client side ===
 +  * Check for presence of ''lsmon.exe'', it might be in ''C:\Program Files\Rainbow Technologies\SentinelLM\7.2.0\English\Delivery\Admin.net\Win32\'' or it might be elsewhere. If you can't find it, contact the vendor responsible for WlmAdmin or lservnt.
 +  * Copy lsmon.vbs (below) to your BBWin's ''ext'' folder and customize the path to ''lsmon.exe''.
 +  * Edit your BBWin's ''etc/bbwin.cfg'' file:
 +    * Add a line in the ''externals'' section:<code xml>
 + <load value="cscript.exe ..\ext\lsmon.vbs" />
 +</code>
 +    * If the externals agent was disabled in the ''bbwin'' section (e.g. commented out or deleted), enable:<code xml>
 +        <load name="externals" value="externals.dll" />
 +</code>
 +
 +=== Server side ===
 +<hidden onHidden="Show optional Graphing instructions ⇲" onVisible="Hide optional Graphing instructions ⇱">
 +  * Add the following to $BBHOME/etc/hobbitgraph.sh<code>
 +[lsmon]
 +        FNPATTERN lsmon.(.*).rrd
 +        TITLE SafeNet Utilization
 +        YAXIS Percent Used
 +        DEF:in@RRDIDX@=@RRDFN@:pct:AVERAGE
 +        LINE1:in@RRDIDX@#@COLOR@:@RRDPARAM@ Percent
 +        GPRINT:in@RRDIDX@:LAST: \: %5.1lf (cur)
 +        GPRINT:in@RRDIDX@:MAX: \: %5.1lf (max)
 +        GPRINT:in@RRDIDX@:MIN: \: %5.1lf (min)
 +        GPRINT:in@RRDIDX@:AVERAGE: \: %5.2lf (avg)\n
 +[lsmon1]
 +        FNPATTERN lsmon.(.*).rrd
 +        TITLE SafeNet Utilization
 +        YAXIS Used
 +        DEF:in@RRDIDX@=@RRDFN@:used:AVERAGE
 +        LINE1:in@RRDIDX@#@COLOR@:@RRDPARAM@ Used
 +        GPRINT:in@RRDIDX@:LAST: %3.1lf (cur)
 +        GPRINT:in@RRDIDX@:MAX: %3.1lf (max)
 +        GPRINT:in@RRDIDX@:MIN: %3.1lf (min)
 +        GPRINT:in@RRDIDX@:AVERAGE: %3.2lf (avg)\n
 +</code>
 +  * In $BBHOME/etc/hobbitserver.cfg, add the following to the existing ''TEST2RRD'' and ''GRAPHS'' lines:<code>
 +TEST2RRD="[...],lsmon"
 +GRAPHS="[...],lsmon:lsmon|lsmon1"
 +</code>
 +  * In $BBHOME/etc/hobbitlaunch.cfg, in the ''[rrdstatus]'' section:
 +    * If it has ''--extra-tests'' and ''--extra-script'', add '',lsmon'' to the ''--extra-tests'' parameter, and merge the following code with your --extra-script's script.
 +    * If it doesn't have ''--extra-tests'' or ''--extra-script'', use the following ''extra-rrd.sh'' script and add the following to the CMD:<code bash>
 +--extra-tests=lsmon --extra-script=$BBHOME/ext/extra-rrd.sh
 +</code>
 +
 +<code bash>
 +#!/bin/sh
 +# extra-rrd.sh
 +
 +# Input parameters: Hostname, testname (column), and messagefile
 +HOSTNAME="$1"
 +TESTNAME="$2"
 +FNAME="$3"
 +
 +if [ "$TESTNAME" = "lsmon" ]; then
 +#echo "$HOSTNAME $TESTNAME $FNAME" >> /tmp/extra-rrd-run.log
 +        #go with disk ordering: percent then used
 +        echo "DS:pct:GAUGE:600:0:100"
 +        echo "DS:used:GAUGE:600:0:U"
 +        sed -n '/Feature/p;/nreserved/p' $FNAME \
 +          | sed 's/.*: //;s/\"//g;s/ *$//' \
 +          | sed '$!N;$!N;$!N;s/\n/:/g'\
 +          | while read line; do
 +                #Not sure why, but on my machine there are hidden characters after feature name
 +                #feature here is name-version
 +                feature=`echo "$line" | sed 's/:[0-9]*:[0-9]*$//' | sed 's/[[:space:]]*:/-/'``
 +                used=`echo "$line" | sed 's/^[^:]*:[^:]*://;s/:.*//'`
 +                avail=`echo "$line" | sed 's/.*://'`
 +                total=$(( used + avail ))
 +                pct=$(( used * 100 / total ))
 +                echo "$TESTNAME.$feature.rrd"
 +                echo "$pct:$used"
 +        done
 +fi
 +</code>
 +
 +</hidden>
 +
 +===== Source =====
 +==== lsmon.vbs ====
 +
 +<hidden onHidden="Show Code ⇲" onVisible="Hide Code ⇱">
 +<code vb>
 +Option Explicit
 +
 +const LSMONEXE="C:\Program Files\BBWin\ext\lsmon.exe"
 +
 +Dim TimerStart : TimerStart = Timer
 +Dim FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
 +Dim WSH : Set WSH = CreateObject("WScript.Shell")
 +const dbg=False
 +
 +Phase 1
 +WSH.Run "cmd.exe /c echo . | """ & LSMONEXE & """ > lsmon.txt", 0, 1
 +
 +Phase 2
 +With FSO.OpenTextFile("lsmon.txt", 1)
 + Dim a : a = .ReadLine : a = Split(.ReadAll, vbCRLF)
 + .Close
 +End With
 +
 +Phase 3
 +'These are filtering from the first part (overall license characteristics).
 +'Note that 8.x and 7.2 have a space in front of each line, 7.0 does not.
 +Dim i : for each i in Array("License type", " License Version" _
 + , " Able to issue", " commuter licenses", "Additive/exclusive" _
 + , " Application-server locking", "App-server locking" _
 + , "Held licenses", "Soft limit on users" _
 + , "License start", "Sharing limit")
 + a = Filter(a, i, False)
 +next
 +for each i in Array(" locking code", " Local request")
 + a = Filter(a, i, False)
 +next
 +
 +Phase 4
 +'These are filtering from the details (each user token)
 +for each i in Array("Reserved tokens", "Reserved Tokens", "Available reserv" _
 + , "X display name", ": DefaultGrp")
 + a = Filter(a, i, False)
 +next
 +
 +Phase 5
 +'This strips the last line
 +for each i in Array("Press Enter", "Hit Enter to continue")
 + a = Filter(a, i, False)
 +next
 +
 +Phase 6
 +'These change the output on a 7.0 lsmon.exe from combined lines to pure NCV
 +'And compensate for 7.2's tab
 +for i = 0 to UBound(a) - 1
 + Dim n : n = Instr(a(i), "Feature version")
 + If n > 5 Then
 + a(i) = Left(a(i), n - 3) & vbCRLF & Mid(a(i), n)
 + a(i) = Replace(a(i), vbTab & ":", vbTab & " :")
 + End If
 + n = Instr(a(i), "Available unreserved")
 + If n > 5 Then
 + a(i) = Left(a(i), n - 3) & vbCRLF & Mid(a(i), n)
 + a(i) = Replace(a(i), vbTab & ":", vbTab & " :")
 + End If
 + n = Instr(a(i), "Feature name " & vbTab & vbTab)
 + if n = 2 then
 + a(i) = Replace(a(i), " :", ":")
 + end if
 +
 +next
 +
 +Phase 7
 +'This concatenates the output, putting an <HR> between each feature
 +'Note that 8.x outputs "Feature name" at top, 7.x outputs "Commuter License Allowed"
 +a = Replace(Join(a, vbCRLF), vbCRLF & " ", vbCRLF) 'Strip space at 8.x's line beginning
 +
 +a = Replace(a, vbCRLF & vbCRLF & "Feature name  " _
 + , vbCRLF & "<hr>" & vbCRLF & vbCRLF & "Feature name  ")
 +a = Replace(a, vbCRLF & vbCRLF & "Commuter License Allowed " _
 + , vbCRLF & "<hr>" & vbCRLF & vbCRLF & "Commuter License Allowed ")
 +
 +WriteStatus "lsmon", "green", "lsmon", a
 +
 +
 +'######################################################################
 +'Write out the status; depends on FSO and WSH; will use TimerStart if available for duration
 +Sub WriteStatus(column, color, quickie, line)
 +'Why so long? Assume that client might collect file while writing, so make temp file and rename it.
 +'######################################################################
 + Dim FSO : Set FSO = CreateObject("Scripting.FileSystemObject")
 + Dim WSH : Set WSH = CreateObject("WScript.Shell")
 + Dim HKLMSoft : HKLMSoft="HKLM\SOFTWARE"
 + if WSH.Environment("SYSTEM")("PROCESSOR_ARCHITECTURE") <> "x86" then HKLMSoft = HKLMSoft & "\Wow6432Node"
 + Const LEAKYMAX = 8500, BBWinreg = "\BBWin\tmpPath"
 + Const Questreg = "\Quest Software\BigBrother\bbnt\ExternalPath\"
 + 'On error resume next
 + 'Assume that, if BBWin is installed, they're using it; if not then they're using Quest BB client.
 + Dim colfn, src : colfn = "" : colfn = WSH.RegRead(HKLMSoft & BBWinreg) : src = "bbwin"
 + If "" = colfn then : colfn = WSH.RegRead(HKLMSoft & Questreg) : src = "" : end if
 + If "" = colfn then Exit Sub 'Abort if nothing in the registry for location.
 + colfn = colfn & "\" & column 'Add the column name to make it a real colfile.
 + Dim tmpfn : tmpfn = colfn & ".$$$" 'Temporary file; use temporary name for safety!
 + If FSO.FileExists(tmpfn) Then WScript.Quit 183 'Bail out if already there (i.e. previous stuck)
 + Phase "Status1"
 + On Error Resume Next
 + With FSO.CreateTextFile(tmpfn, True)
 + if err then WScript.Quit err 'Bail out if unable to create file.
 + if Len(line) > LEAKYMAX and src = "bbwin" then _
 + .Write "status " & WSH.RegRead(HKLMSoft & "\BBWin\hostname") & "." & column & " "
 + .WriteLine color & " " & WeekdayName(Weekday(Now),True) & " " _
 + & Mid(Now,1,InStr(Now," ")-1) & " " & TimeValue(Now) _
 + & " [" & WSH.Environment("Process")("COMPUTERNAME") & "] " & quickie
 + .WriteLine line
 + .Write "<center><small>" & WScript.ScriptName & " (modified " & CDate(CLng( _
 + FSO.GetFile(WScript.ScriptFullName).DateLastModified))
 + if not IsNull(TimerStart) then .Write "; run time " & Timer - TimerStart & "s" 'midnight bug
 + .Write ")</small></center>"
 + .Close
 + End With
 + '***********************************************************
 + 'Rename file so client will see it (taking care to remove any unprocessed file first)
 + 'Or send directly with bbwincmd.exe if over 8kB
 + '***********************************************************
 + Phase "Status2"
 + on error goto 0
 +'wscript.echo len(line)
 + if Len(line) > LEAKYMAX and src = "bbwin" then
 + Dim XML : Set XML = CreateObject("Microsoft.XMLDOM") 'Requires MSIE 5 or later
 + If XML.Load(WSH.RegRead(HKLMSoft & "\BBWin\etcPath") & "\bbwin.cfg") then
 + Phase "Status2XML"
 + Dim x : for each x in XML.SelectNodes("//configuration/bbwin/setting[@name='bbdisplay']")
 + WSH.Run "..\bin\bbwincmd.exe " & x.Attributes.GetNamedItem("value").Value _
 + & " uploadmessage """ & tmpfn & """", 1, True
 + next
 + Else
 + WScript.Echo "Error parsing " & WSH.RegRead(HKLMSoft & "\BBWin\etcPath") & "\bbwin.cfg"
 + End If
 + FSO.DeleteFile tmpfn
 + else
 + if FSO.FileExists(colfn) then FSO.DeleteFile(colfn)
 + FSO.MoveFile tmpfn, colfn
 + end if
 +End Sub
 +
 +'######################################################################
 +'If the script gets stuck, we can use Process Explorer to examine its environment
 +'######################################################################
 +Sub Phase(n)
 + if dbg then wscript.echo n
 + CreateObject("WScript.Shell").Environment("Process")("P-" & WScript.ScriptName) = n
 +End Sub
 +</code>
 +</hidden>
 +
 +===== Known  Bugs and Issues =====
 +  * This filters out a lot of lines from the lsmon output that I felt weren't valuable. Customize the array(s) as you see fit.
 +  * It leaves behind a ''lsmon.txt'' file. I felt this was easier if troubleshooting is needed, but feel free to tidy up.
 +  * I have it working with lsmon.exe 8.0.5 and 7.2.0 and 7.0.0. Each formats somewhat differently (7.0 combines some lines; 7.2 and 8.0 use leading spaces; 7.2 uses a tab in Feature name, 8.0 does not) so there might be other versions that doesn't behave as expected.
 +
 +===== To Do =====
 +  * Change color to clear if "No licensed features"
 +  * Change color for expiration: yellow if already expired (presume don't care), red if near expiration
 +
 +===== Credits =====
 +
 +===== Changelog =====
 +  * **2010-04-28**
 +    * WriteStatus: If lengthy status (over 8500) and using BBWin, run via BBWinCmd to avoid handle leak
 +    * WriteStatus: If TimerStart is set at beginning of script, report run time at bottom
 +  * **2010-03-01**
 +    * Modified for lsmon.exe version 7.0 and 7.2
 +    * Minor code improvements: setting for lsmon.exe, lessened long lines
 +  * **2010-02-25**
 +    * Initial release
  
  • monitors/lsmon.txt
  • Last modified: 2010/04/28 06:45
  • by 127.0.0.1