diff --git a/README.md b/README.md index 75877c3..48aca27 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,17 @@ # check_mk-rds_licenses Monitor per user RDS licenses usage. + +The check for rds licenses usage is based on folowing plugins: + - rds_licenses_2008.ps1 + - rds_licenses_2012.ps1 + - elevate_shell.ps1 +If the Windows Server is 64 bit version the agent for x64 must be installed. + +Install procedure: + On Windows 2008 Server: copy the rds_licenses_2008.ps1 file in plugins +directory of check_mk agent folder. + On Windows 2012 Server: copy the elevate_shell.ps1 into plugins directory +of check_mk agent folder and the rds_licenses_2012.ps1 into check_mk agent folder. +The elevate_shell.ps1 will elevate de privileges for running rds_licences_2012.ps1 +and the user which run check_mk agent must have the rights to "run as +administrator". diff --git a/agents/windows/plugins/rds_licenses/elevated_shell.ps1 b/agents/windows/plugins/rds_licenses/elevated_shell.ps1 new file mode 100644 index 0000000..3b377ed --- /dev/null +++ b/agents/windows/plugins/rds_licenses/elevated_shell.ps1 @@ -0,0 +1,42 @@ +# This code was published by Benjamin Armstrong on blogs.msdn.com +# This script will open an elevated powershell terminal and will run the specified script +# The script(s) that must be run with elevated privileges must be configured on the last lines + +# Get the ID and security principal of the current user account +$myWindowsID=[System.Security.Principal.WindowsIdentity]::GetCurrent() +$myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID) + +# Get the security principal for the Administrator role +$adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator + +# Check to see if we are currently running "as Administrator" +if ($myWindowsPrincipal.IsInRole($adminRole)) + { + # We are running "as Administrator" - so change the title and background color to indicate this + $Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + "(Elevated)" + $Host.UI.RawUI.BackgroundColor = "DarkBlue" + clear-host + } +else + { + # We are not running "as Administrator" - so relaunch as administrator + + # Create a new process object that starts PowerShell + $newProcess = new-object System.Diagnostics.ProcessStartInfo "PowerShell"; + + # Specify the current script path and name as a parameter + $newProcess.Arguments = $myInvocation.MyCommand.Definition; + + # Indicate that the process should be elevated + $newProcess.Verb = "runas"; + + # Start the new process + [System.Diagnostics.Process]::Start($newProcess); + + # Exit from the current, unelevated, process + exit + } + +# Run your code that needs to be elevated here +# Will run rds_licenses script from check_mk directory +& "C:\Program Files (x86)\check_mk\rds_licenses_2012.ps1" diff --git a/agents/windows/plugins/rds_licenses/install.txt b/agents/windows/plugins/rds_licenses/install.txt new file mode 100644 index 0000000..068d616 --- /dev/null +++ b/agents/windows/plugins/rds_licenses/install.txt @@ -0,0 +1,14 @@ +The check for rds licenses usage is based on folowing plugins: + - rds_licenses_2008.ps1 + - rds_licenses_2012.ps1 + - elevate_shell.ps1 +If the Windows Server is 64 bit version the agent for x64 must be installed. + +Install procedure: + On Windows 2008 Server: copy the rds_licenses_2008.ps1 file in plugins +directory of check_mk agent folder. + On Windows 2012 Server: copy the elevate_shell.ps1 into plugins directory +of check_mk agent folder and the rds_licenses_2012.ps1 into check_mk agent folder. +The elevate_shell.ps1 will elevate de privileges for running rds_licences_2012.ps1 +and the user which run check_mk agent must ghave the rights to "run as +administrator". diff --git a/agents/windows/plugins/rds_licenses.ps1 b/agents/windows/plugins/rds_licenses/rds_licenses_2008.ps1 similarity index 100% rename from agents/windows/plugins/rds_licenses.ps1 rename to agents/windows/plugins/rds_licenses/rds_licenses_2008.ps1 diff --git a/agents/windows/plugins/rds_licenses/rds_licenses_2012.ps1 b/agents/windows/plugins/rds_licenses/rds_licenses_2012.ps1 new file mode 100644 index 0000000..15977d1 --- /dev/null +++ b/agents/windows/plugins/rds_licenses/rds_licenses_2012.ps1 @@ -0,0 +1,17 @@ +# SpearHead Systems george.mocanu@sphs.ro +# Check for Windows 2012 Server + +Import-Module RemoteDesktopServices + +$path = "RDS:\LicenseServer\LicenseKeyPacks\" + +Write-Host "<<>>" +foreach($pack in Get-ChildItem $path) + { + $checkName = $pack.Name -replace '\s','' + $newPath = Join-Path $path $pack + $total = (Get-Item $newPath\TotalLicenses).CurrentValue + $usage = (Get-Item $newPath\IssuedLicensesCount).CurrentValue + Write-Host $checkName " " $total " " $usage + } +exit diff --git a/checkman/rds_licenses b/checkman/rds_licenses index ed985fc..510bb33 100644 --- a/checkman/rds_licenses +++ b/checkman/rds_licenses @@ -5,16 +5,21 @@ license: GPL distribution: description: This check return usage of RDS licenses. - You need to install the plugin {rds_licenses.ps1} - into the {plugins} directory of your windows agent. + You need to install the plugin {rds_licenses_2008.ps1} + into the {plugins} directory of your windows agent in + case of Win 2008 Server. In case of Win 2012 Server + in plugin directory must be copied elevate_shell.ps1 + and the rds_licenses_2008.ps1 must be copied into + check_mk agent folder and the user which run the check_mk + service must be allowed to elevate privileges. This check was tested with Windows 2008 Server and must have PowerShell installed. On Windows x64 is recommended to use x64 agent. As always you must set "set-executionpolicy remotesigned" on monitored host. The check gets critical if the usage percentage is above - 90 percents and warning if the usage percentage is above - 80 percents. + 95 percents and warning if the usage percentage is above + 90 percents. Both limits are definable in Wato under "Parameters for Inventorized Checks", "Applications, Processes & Services". diff --git a/checks/rds_licenses b/checks/rds_licenses index aee26f7..0248e80 100644 --- a/checks/rds_licenses +++ b/checks/rds_licenses @@ -3,10 +3,10 @@ # SpearHead Systems # EXAMPLE DATA FROM: -# fomat: PerUserLicenses 20 15 +# fomat: Win2k8_Pack_Name No_of_Installed_Licenses No_of_Used_Licenses # #<<>> -#PerUserLicenses 20 15 +#Win2k8_Pack_Name 20 15 factory_settings["rds_licenses_default_values"] = { "levels": (80, 90), @@ -28,17 +28,23 @@ def check_rds_licenses(item, params, info): if line[0] == item: total = int(line[1]) used = int(line[2]) - usedPerc = int(((used*100)/total)) - perfdata = [ ( "usage", usedPerc, warn, crit ) ] + if total != 0: + usedPerc = int(((used*100)/total)) + else: + usedPerc = int(((used*100)/1)) + perfdata = [ ( "usage", usedPerc, warn, crit ) ] if total != 0: if usedPerc > crit: - return (2, "License use level: %d percents" %usedPerc, perfdata) + return (2, "License use level: %d percents. %d licenses used out of %d installed." %(usedPerc, used, total), perfdata) elif usedPerc > warn: - return (1, "License use level: %d percents" %usedPerc, perfdata) + return (1, "License use level: %d percents. %d licenses used out of %d installed." %(usedPerc, used, total), perfdata) else: - return (0, "License use level: %d percents" %usedPerc, perfdata) - else: - return (0, "No licenses installed") + return (0, "License use level: %d percents. %d licenses used out of %d installed." %(usedPerc, used, total), perfdata) + else: + if used == 0: + return (0, "No licenses installed, none used", perfdata) + else: + return (2, "No licenses installed, %d licenses used" %used, perfdata) return(3, "Plugin not running on host") check_info["rds_licenses"] = { diff --git a/rds_licenses-1.0.mkp b/rds_licenses-1.0.mkp deleted file mode 100644 index ccf20a2..0000000 Binary files a/rds_licenses-1.0.mkp and /dev/null differ diff --git a/rds_licenses-1.1.mkp b/rds_licenses-1.1.mkp new file mode 100644 index 0000000..671fc78 Binary files /dev/null and b/rds_licenses-1.1.mkp differ