Browse Source

Add Win 2012 plugins and group allrds files in one folder. Modify check file. Update man and install instructions.

George Mocanu 3 years ago
parent
commit
5d53d70f71

+ 15
- 0
README.md View File

@@ -1,2 +1,17 @@
1 1
 # check_mk-rds_licenses
2 2
 Monitor per user RDS licenses usage.
3
+
4
+The check for rds licenses usage is based on folowing plugins:
5
+        - rds_licenses_2008.ps1
6
+        - rds_licenses_2012.ps1
7
+        - elevate_shell.ps1
8
+If the Windows Server is 64 bit version the agent for x64 must be installed.
9
+
10
+Install procedure:
11
+        On Windows 2008 Server: copy the rds_licenses_2008.ps1 file in plugins
12
+directory of check_mk agent folder.
13
+        On Windows 2012 Server: copy the elevate_shell.ps1 into plugins directory
14
+of check_mk agent folder and the rds_licenses_2012.ps1 into check_mk agent folder.
15
+The elevate_shell.ps1 will elevate de privileges for running rds_licences_2012.ps1
16
+and the user which run check_mk agent must have the rights to "run as 
17
+administrator".

+ 42
- 0
agents/windows/plugins/rds_licenses/elevated_shell.ps1 View File

@@ -0,0 +1,42 @@
1
+# This code was published by Benjamin Armstrong on blogs.msdn.com
2
+# This script will open an elevated powershell terminal and will run the specified script
3
+# The script(s) that must be run with elevated privileges must be configured on the last lines
4
+
5
+# Get the ID and security principal of the current user account
6
+$myWindowsID=[System.Security.Principal.WindowsIdentity]::GetCurrent()
7
+$myWindowsPrincipal=new-object System.Security.Principal.WindowsPrincipal($myWindowsID)
8
+
9
+# Get the security principal for the Administrator role
10
+$adminRole=[System.Security.Principal.WindowsBuiltInRole]::Administrator
11
+
12
+# Check to see if we are currently running "as Administrator"
13
+if ($myWindowsPrincipal.IsInRole($adminRole))
14
+   {
15
+   # We are running "as Administrator" - so change the title and background color to indicate this
16
+   $Host.UI.RawUI.WindowTitle = $myInvocation.MyCommand.Definition + "(Elevated)"
17
+   $Host.UI.RawUI.BackgroundColor = "DarkBlue"
18
+   clear-host
19
+   }
20
+else
21
+   {
22
+   # We are not running "as Administrator" - so relaunch as administrator
23
+   
24
+   # Create a new process object that starts PowerShell
25
+   $newProcess = new-object System.Diagnostics.ProcessStartInfo "PowerShell";
26
+   
27
+   # Specify the current script path and name as a parameter
28
+   $newProcess.Arguments = $myInvocation.MyCommand.Definition;
29
+   
30
+   # Indicate that the process should be elevated
31
+   $newProcess.Verb = "runas";
32
+   
33
+   # Start the new process
34
+   [System.Diagnostics.Process]::Start($newProcess);
35
+   
36
+   # Exit from the current, unelevated, process
37
+   exit
38
+   }
39
+
40
+# Run your code that needs to be elevated here
41
+# Will run rds_licenses script from check_mk directory
42
+& "C:\Program Files (x86)\check_mk\rds_licenses_2012.ps1"

+ 14
- 0
agents/windows/plugins/rds_licenses/install.txt View File

@@ -0,0 +1,14 @@
1
+The check for rds licenses usage is based on folowing plugins:
2
+	- rds_licenses_2008.ps1
3
+	- rds_licenses_2012.ps1
4
+	- elevate_shell.ps1
5
+If the Windows Server is 64 bit version the agent for x64 must be installed.
6
+
7
+Install procedure:
8
+	On Windows 2008 Server: copy the rds_licenses_2008.ps1 file in plugins
9
+directory of check_mk agent folder.
10
+	On Windows 2012 Server: copy the elevate_shell.ps1 into plugins directory
11
+of check_mk agent folder and the rds_licenses_2012.ps1 into check_mk agent folder.
12
+The elevate_shell.ps1 will elevate de privileges for running rds_licences_2012.ps1
13
+and the user which run check_mk agent must ghave the rights to "run as 
14
+administrator".

agents/windows/plugins/rds_licenses.ps1 → agents/windows/plugins/rds_licenses/rds_licenses_2008.ps1 View File


+ 17
- 0
agents/windows/plugins/rds_licenses/rds_licenses_2012.ps1 View File

@@ -0,0 +1,17 @@
1
+# SpearHead Systems george.mocanu@sphs.ro
2
+# Check for Windows 2012 Server
3
+
4
+Import-Module RemoteDesktopServices
5
+
6
+$path = "RDS:\LicenseServer\LicenseKeyPacks\"
7
+
8
+Write-Host "<<<rds_licenses>>>"
9
+foreach($pack in Get-ChildItem $path)
10
+    {
11
+        $checkName = $pack.Name -replace '\s',''
12
+        $newPath = Join-Path $path $pack
13
+        $total = (Get-Item $newPath\TotalLicenses).CurrentValue
14
+        $usage = (Get-Item $newPath\IssuedLicensesCount).CurrentValue        
15
+        Write-Host $checkName " " $total " " $usage
16
+    }
17
+exit

+ 9
- 4
checkman/rds_licenses View File

@@ -5,16 +5,21 @@ license: GPL
5 5
 distribution:
6 6
 description:
7 7
  This check return usage of RDS licenses. 
8
- You need to install the plugin {rds_licenses.ps1}
9
- into the {plugins} directory of your windows agent.  
8
+ You need to install the plugin {rds_licenses_2008.ps1}
9
+ into the {plugins} directory of your windows agent in 
10
+ case of Win 2008 Server. In case of Win 2012 Server
11
+ in plugin directory must be copied elevate_shell.ps1
12
+ and the rds_licenses_2008.ps1 must be copied into 
13
+ check_mk agent folder and the user which run the check_mk
14
+ service must be allowed to elevate privileges.   
10 15
  This check was tested with Windows 2008 Server  
11 16
  and must have PowerShell installed. On Windows x64 is 
12 17
  recommended to use x64 agent. As always you must set
13 18
  "set-executionpolicy remotesigned" on monitored host.
14 19
 
15 20
  The check gets critical if the usage percentage is above 
16
- 90 percents and warning if the usage percentage is above
17
- 80 percents.
21
+ 95 percents and warning if the usage percentage is above
22
+ 90 percents.
18 23
  Both limits are definable in Wato under "Parameters for 
19 24
  Inventorized Checks", "Applications, Processes & Services".
20 25
 

+ 15
- 9
checks/rds_licenses View File

@@ -3,10 +3,10 @@
3 3
 # SpearHead Systems
4 4
 
5 5
 # EXAMPLE DATA FROM: 
6
-# fomat: PerUserLicenses 20 15 
6
+# fomat: Win2k8_Pack_Name No_of_Installed_Licenses No_of_Used_Licenses
7 7
 #
8 8
 #<<<rds_licenses>>>
9
-#PerUserLicenses 20 15
9
+#Win2k8_Pack_Name 20 15
10 10
 
11 11
 factory_settings["rds_licenses_default_values"] = {
12 12
         "levels": (80, 90),
@@ -28,17 +28,23 @@ def check_rds_licenses(item, params, info):
28 28
         if line[0] == item:
29 29
             total = int(line[1])
30 30
             used = int(line[2])
31
-	    usedPerc = int(((used*100)/total))
32
-	    perfdata = [ ( "usage", usedPerc, warn, crit ) ]	
31
+            if total != 0:
32
+                usedPerc = int(((used*100)/total))
33
+            else:
34
+                usedPerc = int(((used*100)/1))
35
+            perfdata = [ ( "usage", usedPerc, warn, crit ) ]
33 36
             if total != 0:
34 37
                 if usedPerc > crit:
35
-                    return (2, "License use level: %d percents" %usedPerc, perfdata)
38
+                    return (2, "License use level: %d percents. %d licenses used out of %d installed." %(usedPerc, used, total), perfdata)
36 39
                 elif usedPerc > warn:
37
-                    return (1, "License use level: %d percents" %usedPerc, perfdata)
40
+                    return (1, "License use level: %d percents. %d licenses used out of %d installed." %(usedPerc, used, total), perfdata)
38 41
                 else:
39
-                    return (0, "License use level: %d percents" %usedPerc, perfdata)
40
-            else:
41
-                return (0, "No licenses installed")
42
+                    return (0, "License use level: %d percents. %d licenses used out of %d installed." %(usedPerc, used, total), perfdata)
43
+	    else:
44
+		if used == 0:
45
+                        return (0, "No licenses installed, none used", perfdata)
46
+                else:
47
+                        return (2, "No licenses installed, %d licenses used" %used, perfdata)
42 48
     return(3, "Plugin not running on host")
43 49
 
44 50
 check_info["rds_licenses"] = {

BIN
rds_licenses-1.0.mkp View File


BIN
rds_licenses-1.1.mkp View File


Loading…
Cancel
Save