sensu-plugins-windows 0.0.10 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +5 -13
  2. data/CHANGELOG.md +59 -29
  3. data/README.md +47 -8
  4. data/bin/check-windows-cpu-load.rb +3 -6
  5. data/bin/check-windows-disk.rb +10 -12
  6. data/bin/check-windows-process.rb +3 -4
  7. data/bin/check-windows-processor-queue-length.rb +47 -0
  8. data/bin/check-windows-ram.rb +4 -7
  9. data/bin/check-windows-service.rb +5 -12
  10. data/bin/{metrics-windows-cpu-load.rb → metric-windows-cpu-load.rb} +4 -10
  11. data/bin/{metrics-windows-disk-usage.rb → metric-windows-disk-usage.rb} +3 -9
  12. data/bin/{metrics-windows-network.rb → metric-windows-network.rb} +3 -5
  13. data/bin/metric-windows-processor-queue-length.rb +58 -0
  14. data/bin/{metrics-windows-ram-usage.rb → metric-windows-ram-usage.rb} +4 -9
  15. data/bin/{metrics-windows-uptime.rb → metric-windows-uptime.rb} +3 -5
  16. data/bin/powershell/check-windows-cpu-load.ps1 +49 -0
  17. data/bin/powershell/check-windows-disk-writeable.ps1 +89 -0
  18. data/bin/powershell/check-windows-disk.ps1 +81 -0
  19. data/bin/powershell/check-windows-http.ps1 +56 -0
  20. data/bin/powershell/check-windows-process.ps1 +42 -0
  21. data/bin/powershell/check-windows-processor-queue-length.ps1 +49 -0
  22. data/bin/powershell/check-windows-ram.ps1 +51 -0
  23. data/bin/powershell/check-windows-service.ps1 +48 -0
  24. data/bin/powershell/metric-windows-cpu-load.ps1 +35 -0
  25. data/bin/powershell/metric-windows-disk-usage.ps1 +45 -0
  26. data/bin/powershell/metric-windows-network.ps1 +35 -0
  27. data/bin/powershell/metric-windows-processor-queue-length.ps1 +35 -0
  28. data/bin/powershell/metric-windows-ram-usage.ps1 +35 -0
  29. data/bin/powershell/metric-windows-uptime.ps1 +34 -0
  30. data/lib/sensu-plugins-windows/version.rb +2 -2
  31. metadata +57 -71
  32. checksums.yaml.gz.sig +0 -0
  33. data.tar.gz.sig +0 -2
  34. metadata.gz.sig +0 -0
@@ -1,11 +1,10 @@
1
1
  #! /usr/bin/env ruby
2
2
  #
3
- # metrics-windows-cpu-load.rb
3
+ # metric-windows-cpu-load.rb
4
4
  #
5
5
  # DESCRIPTION:
6
- # This is metrics which outputs the CPU load in Graphite acceptable format.
7
- # To get the cpu stats for Windows Server to send over to Graphite.
8
- # It basically uses the typeperf to get the processor usage at a given particular time.
6
+ # This plugin collects and outputs the CPU load in a Graphite acceptable format.
7
+ # It uses Typeperf to get the processor usage.
9
8
  #
10
9
  # OUTPUT:
11
10
  # metric data
@@ -22,16 +21,11 @@
22
21
  #
23
22
  # LICENSE:
24
23
  # Copyright 2013 <jashishtech@gmail.com>
25
- # Released under the same terms as Sensu (the MIT license); see LICENSE
26
- # for details.
24
+ # Released under the same terms as Sensu (the MIT license); see LICENSE for details.
27
25
  #
28
-
29
26
  require 'sensu-plugin/metric/cli'
30
27
  require 'socket'
31
28
 
32
- #
33
- # Cpu metric
34
- #
35
29
  class CpuMetric < Sensu::Plugin::Metric::CLI::Graphite
36
30
  option :scheme,
37
31
  description: 'Metric naming scheme, text to prepend to .$parent.$child',
@@ -1,10 +1,9 @@
1
1
  #! /usr/bin/env ruby
2
2
  #
3
- # metrics-windows-disk-usage.rb
3
+ # metric-windows-disk-usage.rb
4
4
  #
5
5
  # DESCRIPTION:
6
- # This plugin collects disk capacity metrics.
7
- # Created to return values in same format as system/disk-usage-metric
6
+ # This plugin collects and outputs disk usage metrics in a Graphite acceptable format.
8
7
  #
9
8
  # OUTPUT:
10
9
  # metric data
@@ -21,16 +20,11 @@
21
20
  #
22
21
  # LICENSE:
23
22
  # Copyright 2014 <alex.slynko@wonga.com>
24
- # Released under the same terms as Sensu (the MIT license); see LICENSE
25
- # for details.
23
+ # Released under the same terms as Sensu (the MIT license); see LICENSE for details.
26
24
  #
27
-
28
25
  require 'sensu-plugin/metric/cli'
29
26
  require 'socket'
30
27
 
31
- #
32
- # Disk Usage Metric
33
- #
34
28
  class DiskUsageMetric < Sensu::Plugin::Metric::CLI::Graphite
35
29
  option :scheme,
36
30
  description: 'Metric naming scheme, text to prepend to .$parent.$child',
@@ -1,9 +1,9 @@
1
1
  #! /usr/bin/env ruby
2
2
  #
3
- # uptime-windows
3
+ # metric-windows-network.rb
4
4
  #
5
5
  # DESCRIPTION:
6
- # This is metrics which outputs the uptime in seconds in Graphite acceptable format.
6
+ # This plugin collects and outputs the uptime in seconds in a Graphite acceptable format.
7
7
  #
8
8
  # OUTPUT:
9
9
  # metric data
@@ -21,10 +21,8 @@
21
21
  #
22
22
  # LICENSE:
23
23
  # Copyright 2015 <miguelangel.garcia@gmail.com>
24
- # Released under the same terms as Sensu (the MIT license); see LICENSE
25
- # for details.
24
+ # Released under the same terms as Sensu (the MIT license); see LICENSE for details.
26
25
  #
27
-
28
26
  require 'rubygems' if RUBY_VERSION < '1.9.0'
29
27
  require 'sensu-plugin/metric/cli'
30
28
  require 'socket'
@@ -0,0 +1,58 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # metric-windows-processor-queue-length.rb
4
+ #
5
+ # DESCRIPTION:
6
+ # This plugin collects and outputs the Processor Queue Length.
7
+ # It uses Typeperf to get the processor usage.
8
+ #
9
+ # OUTPUT:
10
+ # metric data
11
+ #
12
+ # PLATFORMS:
13
+ # Windows
14
+ #
15
+ # DEPENDENCIES:
16
+ # gem: sensu-plugin
17
+ #
18
+ # USAGE:
19
+ #
20
+ # NOTES:
21
+ #
22
+ # LICENSE:
23
+ # Andy Royle <ajroyle@gmail.com>
24
+ # Released under the same terms as Sensu (the MIT license); see LICENSE for details.
25
+ #
26
+ require 'sensu-plugin/metric/cli'
27
+ require 'socket'
28
+
29
+ class CpuMetric < Sensu::Plugin::Metric::CLI::Graphite
30
+ option :scheme,
31
+ description: 'Metric naming scheme, text to prepend to .$parent.$child',
32
+ long: '--scheme SCHEME',
33
+ default: Socket.gethostname.to_s
34
+
35
+ def acquire_cpu_load
36
+ temp_arr = []
37
+ timestamp = Time.now.utc.to_i
38
+ IO.popen('typeperf -sc 1 "system\\processor queue length" ') { |io| io.each { |line| temp_arr.push(line) } }
39
+ temp = temp_arr[2].split(',')[1]
40
+ queue_metric = temp[1, temp.length - 3].to_f
41
+ [queue_metric, timestamp]
42
+ end
43
+
44
+ def run
45
+ values = acquire_cpu_load
46
+ metrics = {
47
+ cpu: {
48
+ queuelength: values[0]
49
+ }
50
+ }
51
+ metrics.each do |parent, children|
52
+ children.each do |child, value|
53
+ output [config[:scheme], parent, child].join('.'), value, values[1]
54
+ end
55
+ end
56
+ ok
57
+ end
58
+ end
@@ -1,13 +1,10 @@
1
1
  #! /usr/bin/env ruby
2
2
  #
3
- # ram-usage-windows.rb
3
+ # metric-windows-ram-usage.rb
4
4
  #
5
5
  # DESCRIPTION:
6
- # This is metrics which outputs the Ram usage in Graphite acceptable format.
7
- # To get the cpu stats for Windows Server to send over to Graphite.
8
- # It basically uses the typeperf(To get available memory) and wmic(Used to get the usable memory size)
9
- # to get the processor usage at a given particular time.
10
- #
6
+ # This plugin collects and outputs the RAM usage in a Graphite acceptable format.
7
+ # It uses Typeperf to get available memory and WMIC to get the usable memory size.
11
8
  #
12
9
  # OUTPUT:
13
10
  # metric data
@@ -24,10 +21,8 @@
24
21
  #
25
22
  # LICENSE:
26
23
  # Copyright 2013 <jashishtech@gmail.com>
27
- # Released under the same terms as Sensu (the MIT license); see LICENSE
28
- # for details.
24
+ # Released under the same terms as Sensu (the MIT license); see LICENSE for details.
29
25
  #
30
-
31
26
  require 'sensu-plugin/metric/cli'
32
27
  require 'socket'
33
28
 
@@ -1,9 +1,9 @@
1
1
  #! /usr/bin/env ruby
2
2
  #
3
- # uptime-windows
3
+ # metric-windows-uptime.rb
4
4
  #
5
5
  # DESCRIPTION:
6
- # This is metrics which outputs the uptime in seconds in Graphite acceptable format.
6
+ # This plugin collects and outputs the uptime in seconds in a Graphite acceptable format.
7
7
  #
8
8
  # OUTPUT:
9
9
  # metric data
@@ -21,10 +21,8 @@
21
21
  #
22
22
  # LICENSE:
23
23
  # Copyright 2015 <miguelangel.garcia@gmail.com>
24
- # Released under the same terms as Sensu (the MIT license); see LICENSE
25
- # for details.
24
+ # Released under the same terms as Sensu (the MIT license); see LICENSE for details.
26
25
  #
27
-
28
26
  require 'rubygems' if RUBY_VERSION < '1.9.0'
29
27
  require 'sensu-plugin/metric/cli'
30
28
  require 'socket'
@@ -0,0 +1,49 @@
1
+ #
2
+ # check-windows-cpu-load.ps1
3
+ #
4
+ # DESCRIPTION:
5
+ # This plugin collects the CPU Usage and compares against the WARNING and CRITICAL thresholds.
6
+ #
7
+ # OUTPUT:
8
+ # plain text
9
+ #
10
+ # PLATFORMS:
11
+ # Windows
12
+ #
13
+ # DEPENDENCIES:
14
+ # Powershell
15
+ #
16
+ # USAGE:
17
+ # Powershell.exe -NonInteractive -NoProfile -ExecutionPolicy Bypass -NoLogo -File C:\\etc\\sensu\\plugins\\check-windows-cpu-load.ps1 90 95
18
+ #
19
+ # NOTES:
20
+ #
21
+ # LICENSE:
22
+ # Copyright 2016 sensu-plugins
23
+ # Released under the same terms as Sensu (the MIT license); see LICENSE for details.
24
+ #
25
+ [CmdletBinding()]
26
+ Param(
27
+ [Parameter(Mandatory=$True,Position=1)]
28
+ [int]$WARNING,
29
+
30
+ [Parameter(Mandatory=$True,Position=2)]
31
+ [int]$CRITICAL
32
+ )
33
+
34
+ $ThisProcess = Get-Process -Id $pid
35
+ $ThisProcess.PriorityClass = "BelowNormal"
36
+
37
+ $Value = [System.Math]::Round((Get-Counter '\processor(_total)\% processor time' -SampleInterval 1 -MaxSamples 1).CounterSamples.CookedValue)
38
+
39
+ If ($Value -gt $CRITICAL) {
40
+ Write-Host CheckWindowsCpuLoad CRITICAL: CPU at $Value%.
41
+ Exit 2 }
42
+
43
+ If ($Value -gt $WARNING) {
44
+ Write-Host CheckWindowsCpuLoad WARNING: CPU at $Value%.
45
+ Exit 1 }
46
+
47
+ Else {
48
+ Write-Host CheckWindowsCpuLoad OK: CPU at $Value%.
49
+ Exit 0 }
@@ -0,0 +1,89 @@
1
+ #
2
+ # check-windows-disk-writeable.ps1
3
+ #
4
+ # DESCRIPTION:
5
+ # This plugin collects the mounted logical disks and tests they are writeable.
6
+ #
7
+ # OUTPUT:
8
+ # plain text
9
+ #
10
+ # PLATFORMS:
11
+ # Windows
12
+ #
13
+ # DEPENDENCIES:
14
+ # PowerShell 2.0 or above
15
+ #
16
+ # USAGE:
17
+ # Powershell.exe -NonInteractive -NoProfile -ExecutionPolicy Bypass -NoLogo -File C:\\etc\\sensu\\plugins\\check-windows-disk-writeable.ps1
18
+ # Powershell.exe -NonInteractive -NoProfile -ExecutionPolicy Bypass -NoLogo -File C:\\etc\\sensu\\plugins\\check-windows-disk-writeable.ps1 -DriveType "3,5" -Ignore "A,B" -TestFile '\test.txt'
19
+ #
20
+ # NOTES:
21
+ #
22
+ # LICENSE:
23
+ # Copyright 2017 sensu-plugins
24
+ # Released under the same terms as Sensu (the MIT license); see LICENSE for details.
25
+ #
26
+
27
+ #Requires -Version 2.0
28
+
29
+ [CmdletBinding()]
30
+ Param(
31
+ # DriveType, see available options at https://msdn.microsoft.com/en-us/library/windows/desktop/aa364939(v=vs.85).aspx
32
+ # Specify multiple values as a comma separated string, e.g. "3,5"
33
+ [Parameter(Mandatory=$False)]
34
+ [string]$DriveType = "3",
35
+
36
+ # Disk letters to ignore
37
+ # Specify multiple values as a comma separated string, e.g. "C,D"
38
+ [Parameter(Mandatory=$False)]
39
+ [string]$Ignore = "None",
40
+
41
+ # Test file to create on each disk to test it is writeable
42
+ [Parameter(Mandatory=$False)]
43
+ [string]$TestFile = "\testfile.txt"
44
+ )
45
+
46
+ $ThisProcess = Get-Process -Id $pid
47
+ $ThisProcess.PriorityClass = "BelowNormal"
48
+
49
+ $crit = 0
50
+ $critDisks = ""
51
+
52
+ $AllDisks = @()
53
+ Foreach ($DT in $($DriveType -split(','))) {
54
+ Get-WMIObject Win32_LogicalDisk -Filter "DriveType = ${DT}" | Where-Object{ $_.DeviceID -notmatch "[$($Ignore.Replace(',',''))]:"} | %{ $AllDisks += $_ }
55
+ }
56
+
57
+ if ($AllDisks.count -eq 0) {
58
+ Write-Host "CheckDiskWriteable UNKNOWN: No logical disks of DriveType $($DriveType -Replace(',', ' or ')) found"
59
+ exit 3
60
+ }
61
+
62
+ foreach ($ObjDisk in $AllDisks) {
63
+
64
+ $ID = $ObjDisk.DeviceID
65
+ $TestPath = $ID + $TestFile
66
+
67
+ $Writeable = $True
68
+ Try {
69
+ [io.file]::OpenWrite($TestPath).close()
70
+ Remove-Item $TestPath
71
+ }
72
+ Catch {
73
+ Write-Verbose "Unable to write to output file $TestPath"
74
+ $Writeable = $False
75
+ }
76
+
77
+ if ($Writeable -eq $False) {
78
+ $crit += 1
79
+ $critDisks += "$ID is not writeable `n"
80
+ }
81
+ }
82
+
83
+ if ($crit -ne 0) {
84
+ Write-Host "CheckDiskWriteable CRITICAL: $crit disks in critical state: `n$critDisks"
85
+ exit 2
86
+ }
87
+
88
+ Write-Host "CheckDiskWriteable OK: All disks are writeable."
89
+ Exit 0
@@ -0,0 +1,81 @@
1
+ #
2
+ # check-windows-disk.ps1
3
+ #
4
+ # DESCRIPTION:
5
+ # This plugin collects the Disk Usage and and compares against the WARNING and CRITICAL thresholds.
6
+ #
7
+ # OUTPUT:
8
+ # plain text
9
+ #
10
+ # PLATFORMS:
11
+ # Windows
12
+ #
13
+ # DEPENDENCIES:
14
+ # Powershell
15
+ #
16
+ # USAGE:
17
+ # Powershell.exe -NonInteractive -NoProfile -ExecutionPolicy Bypass -NoLogo -File C:\\etc\\sensu\\plugins\\check-windows-disk.ps1 90 95 ab
18
+ #
19
+ # NOTES:
20
+ #
21
+ # LICENSE:
22
+ # Copyright 2016 sensu-plugins
23
+ # Released under the same terms as Sensu (the MIT license); see LICENSE for details.
24
+ #
25
+ [CmdletBinding()]
26
+ Param(
27
+ [Parameter(Mandatory=$True,Position=1)]
28
+ [int]$WARNING,
29
+
30
+ [Parameter(Mandatory=$True,Position=2)]
31
+ [int]$CRITICAL,
32
+
33
+ # Example "abz"
34
+ [Parameter(Mandatory=$False,Position=4)]
35
+ [string]$IGNORE
36
+ )
37
+
38
+ $ThisProcess = Get-Process -Id $pid
39
+ $ThisProcess.PriorityClass = "BelowNormal"
40
+
41
+ If ($IGNORE -eq "") {
42
+ $IGNORE = "ab"
43
+ }
44
+
45
+ $AllDisks = Get-WMIObject Win32_LogicalDisk -Filter "DriveType = 3" | Where-Object{ $_.DeviceID -notmatch "[$IGNORE]:"}
46
+
47
+ $crit = 0
48
+ $warn = 0
49
+ $critDisks = ""
50
+ $warnDisks = ""
51
+
52
+ foreach ($ObjDisk in $AllDisks) {
53
+
54
+ $UsedPercentage = [System.Math]::Round(((($ObjDisk.Size-$ObjDisk.Freespace)/$ObjDisk.Size)*100),2)
55
+ $Free = [math]::truncate($ObjDisk.Freespace / 1GB)
56
+ $Size = [math]::truncate($ObjDisk.Size / 1GB)
57
+ $ID = $ObjDisk.DeviceID
58
+
59
+ if ($UsedPercentage -ge $CRITICAL) {
60
+ $crit += 1
61
+ $critDisks += "($ID) $UsedPercentage%, FREE: $Free GB, SIZE: $Size GB `n"
62
+ } elseif ($UsedPercentage -ge $WARNING) {
63
+ $warn += 1
64
+ $warnDisks += "($ID) $UsedPercentage%, FREE: $Free GB, SIZE: $Size GB `n"
65
+ }
66
+ }
67
+
68
+ if ($crit -ne 0) {
69
+ if ($warn -ne 0 ){
70
+ Write-Host "CheckDisk CRITICAL: $crit disks in critical state `n$critDisks;`n$warn disks in warning state:`n$warnDisks"
71
+ } else {
72
+ Write-Host "CheckDisk CRITICAL: $crit disks in critical state `n$critDisks"
73
+ }
74
+ exit 2
75
+ } elseif ($warn -ne 0) {
76
+ Write-Host "CheckDisk WARNING: $warn disks in warning state `n$warnDisks"
77
+ exit 1
78
+ }
79
+
80
+ Write-Host "CheckDisk OK: All disk usage under $WARNING%."
81
+ Exit 0
@@ -0,0 +1,56 @@
1
+ #
2
+ # check-windows-http.ps1
3
+ #
4
+ # DESCRIPTION:
5
+ # This plugin checks availability of link provided as param
6
+ #
7
+ # OUTPUT:
8
+ # plain text
9
+ #
10
+ # PLATFORMS:
11
+ # Windows
12
+ #
13
+ # DEPENDENCIES:
14
+ # Powershell
15
+ #
16
+ # USAGE:
17
+ # Powershell.exe -NonInteractive -NoProfile -ExecutionPolicy Bypass -NoLogo -File C:\\etc\\sensu\\plugins\\check-windows-http.ps1 https://google.com
18
+ #
19
+ # NOTES:
20
+ #
21
+ # LICENSE:
22
+ # Copyright 2016 sensu-plugins
23
+ # Released under the same terms as Sensu (the MIT license); see LICENSE for details.
24
+ #
25
+
26
+ [CmdletBinding()]
27
+ Param(
28
+ [Parameter(Mandatory=$True,Position=1)]
29
+ [string]$CheckAddress
30
+ )
31
+
32
+ $ThisProcess = Get-Process -Id $pid
33
+ $ThisProcess.PriorityClass = "BelowNormal"
34
+
35
+ try {
36
+ $Avaliable = Invoke-WebRequest $CheckAddress -ErrorAction SilentlyContinue
37
+ }
38
+
39
+ catch {
40
+ $errorandler = $_.Exception.request
41
+ }
42
+
43
+ if (!$Avaliable) {
44
+ Write-Host CRITICAL: Could not connect $CheckAddress!
45
+ Exit 2
46
+ }
47
+
48
+ if ($Avaliable) {
49
+ if ($Avaliable.statuscode -eq 200) {
50
+ Write-Host OK: $CheckAddress is avaliable!
51
+ Exit 0
52
+ } else {
53
+ Write-Host CRITICAL: URL $CheckAddress is not accessable!
54
+ Exit 2
55
+ }
56
+ }