I have a script I want to share. There is already a German topic (https://kb.paessler.com/en/topic/2493-how-can-i-monitor-flexlm-lizenzdienste), but I fine-tuned the script so you can read all licenses at once.
You will need the lmutil.exe from the FlexLM tools util folder and put it together with this script in the EXEXML PRTG folder. In the parameters you can define the server and which licenses you want to monitor.
Script:
# ********************************************************************************** # * SCRIPT INFORMATION * # * ================== * # * * # * NAME : FlexLM_LicenseMonitor.ps1 * # * DESCRIPTION : FlexLM_LicenseMonitor for PRTG (EXEXML Sensor) * # * Lookup the number of licenses used with lmutil * # * * # * EXT. SOFT. : - lmutil.exe * # * --> Search for it in the FlexLM util folder * # * * # ********************************************************************************** # ********************************************************************************** # * CHANGE LOG * # * ========== * # * * # * DATE USER DESCRIPTION * # * ------------------------------------------------------------------------------ * # * * # * * # ********************************************************************************** # ********************************************************************************** # * USAGE * # * ===== * # * * # * Script.ps1 -PortServer 1234@ServerName -Features F1,F2, ... * # * * # * PortServer: Port and Servername to connect to the FlexLM License Manager * # * Features: Name of the License (Run the lmutil to see available features) * # * * # ********************************************************************************** # Parameters # ========== param( [Parameter(Mandatory=$True)] [string] $PortServer, [Parameter(Mandatory=$True)] [array] $Features ) # Set static variables # ==================== $LMUtilPath = "C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXEXML\lmutil.exe" $TempXMLFile = "C:\Windows\Temp\LMUtil_" + $PortServer.Replace("@","") + ".xml" # Set other variables # =================== $FeaturesTotalMax = 0 $FeaturesTotalValue = 0 # Functions # ========= function AddXMLResult { param( [string] $Channel, [string] $Val, [string] $Unit ) $xmlWriter.WriteStartElement("Result") $xmlWriter.WriteStartElement("Channel") $xmlWriter.WriteString($Channel) $xmlWriter.WriteEndElement() # Close Channel $xmlWriter.WriteStartElement("Value") $xmlWriter.WriteString($Val) $xmlWriter.WriteEndElement() # Close Value switch($Unit) { "Lic" { $xmlWriter.WriteStartElement("CustomUnit"); $xmlWriter.WriteString("Lic"); $xmlWriter.WriteEndElement() # close CustomUnit } "Percent" { $xmlWriter.WriteStartElement("Unit"); $xmlWriter.WriteString("Percent"); $xmlWriter.WriteEndElement() # close Unit } } $xmlWriter.WriteEndElement() # close Result } # Start Script # ============ # Open XML Doc # ------------ $xmlWriter = New-Object System.Xml.XmlTextWriter($TempXMLFile,$null) $xmlWriter.Formatting = "Indented" $xmlWriter.Indentation = "2" $xmlWriter.WriteStartDocument() $xmlWriter.WriteStartElement("PRTG") # Lookup Features # --------------- ForEach ($Feature in $Features) { $ReadLicense = &$LMUtilPath lmstat -a -c $PortServer | Select-String -Pattern ("Users of " + $Feature + ":") $FindNumbers = [RegEx]"\b [0-9]+ \b" $ValuesFound = $FindNumbers.Matches($ReadLicense) $FeatureMax = $ValuesFound[0].Value.Trim() $FeatureValue = $ValuesFound[1].Value.Trim() $FeaturesTotalMax = $FeaturesTotalMax + $FeatureMax $FeaturesTotalValue = $FeaturesTotalValue + $FeatureValue $FeaturePerc = [math]::Round($FeatureValue / $FeatureMax * 100) # Provide License Name When Known # ------------------------------- $FeatureName = $Feature switch($Feature) { "dwgeditor" { $FeatureName = "DWG Editor"} "solidworks" { $FeatureName = "SolidWorks Standard"} "swofficepro" { $FeatureName = "SolidWorks Professional"} "swofficepremium" { $FeatureName = "SolidWorks Premium"} "swepdm_viewer" { $FeatureName = "PDM Viewer"} "swepdm_cadeditorandweb" { $FeatureName = "PDM Editor"} "swepdm_contributorandweb" { $FeatureName = "PDM Contributor"} } # Add to XML # ---------- AddXMLResult $FeatureName $FeatureValue "Lic" AddXMLResult ($FeatureName + " Perc") $FeaturePerc "Percent" } # Calc totals & Add to XML # ------------------------ $FeaturesTotalPerc = [math]::Round($FeaturesTotalValue / $FeaturesTotalMax * 100) AddXMLResult "Total Licenses Used" $FeaturesTotalValue "Lic" AddXMLResult "Total Licenses Used Perc" $FeaturesTotalPerc "Percent" # Close XML Doc # ------------- $xmlWriter.WriteEndElement() # Close root element (PRTG) $xmlWriter.WriteEndDocument() $xmlWriter.Flush() $xmlWriter.Close() # Write-Output XML Doc # -------------------- Write-Output (Get-Content $TempXMLFile)
Add comment