sensu-plugins-disk-checks 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 84f05a4a6178a02e5798248cd1c67eadcb6235e2
4
- data.tar.gz: fa409bbe0762c858f885127cb29633e397a57ca4
3
+ metadata.gz: 0a0594b4df04654a37e7b4d624dde2b98f05ddb0
4
+ data.tar.gz: 2d9517a0bfe0d24326eb36b8445227ad4081399d
5
5
  SHA512:
6
- metadata.gz: e66515d72f04a69716714af53fae709d47ad377f35f7fc2ebec35d8ce5d86f3602fc064f3a973e582374c1dc31323fcf04dbec6be7072c37cfe459c6702b90c0
7
- data.tar.gz: 6170411f699673da8e69ca097cd3df92224fedd8b76e68ce4b56fdb2572994ae15ffcf64e87e4e1fe575cbf305c78ee21bbc71d909c26f596b9bb7ed51e70fa5
6
+ metadata.gz: 58ad8ffee7a966ae83f9ac3665d0eb79c18d2f9fd03abd53559fa10103c84e52441aed239f4701d0839c6d2c7036a23a7c605863900ea4e671dd6405cddaaea0
7
+ data.tar.gz: c88d37c9f50bd289c288daaaa764742f2011ce5a3fcc46b3b01fe62852305eb4c84bc7a37962e825cfae189edbd98d15ba856e0b4dcf442a6f76a4a94a04f355
data/CHANGELOG.md CHANGED
@@ -4,6 +4,11 @@ This project adheres to [Semantic Versioning](http://semver.org/).
4
4
  This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/)
5
5
 
6
6
  ## [Unreleased]
7
+
8
+ ## [2.2.0] - 2017-06-24
9
+ ### Added
10
+ - check-smart-tests.rb: a plugin to check S.M.A.R.T. self tests status (@sndl)
11
+
7
12
  ## [2.1.0] - 2017-05-04
8
13
  ### Changed
9
14
  - check-disk-usage.rb: show the decimals for disk usage figures
@@ -119,7 +124,8 @@ https://mathias-kettner.de/checkmk_filesystems.html
119
124
  ### Added
120
125
  - initial release
121
126
 
122
- [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-disk-checks/compare/2.1.0...HEAD
127
+ [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-disk-checks/compare/2.2.0...HEAD
128
+ [2.2.0]: https://github.com/sensu-plugins/sensu-plugins-disk-checks/compare/2.1.0...2.2.0
123
129
  [2.1.0]: https://github.com/sensu-plugins/sensu-plugins-disk-checks/compare/2.0.1...2.1.0
124
130
  [2.0.1]: https://github.com/sensu-plugins/sensu-plugins-disk-checks/compare/2.0.0...2.0.1
125
131
  [2.0.0]: https://github.com/sensu-plugins/sensu-plugins-disk-checks/compare/1.1.3...2.0.0
data/README.md CHANGED
@@ -52,11 +52,16 @@ Check the SMART status of hardrives and alert based upon a given set of threshol
52
52
 
53
53
  Check the health of a disk using `smartctl`
54
54
 
55
+ **check-smart-tests**
56
+
57
+ Check the status of SMART offline tests and optionally check if tests were executed in a specified interval
58
+
55
59
  ## Files
56
60
  * bin/check-disk-usage.rb
57
61
  * bin/check-fstab-mounts.rb
58
62
  * bin/check-smart-status.rb
59
63
  * bin/check-smart.rb
64
+ * bin/check-smart-tests.rb
60
65
  * bin/metrics-disk.rb
61
66
  * bin/metrics-disk-capacity.rb
62
67
  * bin/metrics-disk-usage.rb
@@ -0,0 +1,179 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-smart-tests.rb
4
+ #
5
+ # DESCRIPTION:
6
+ # This script checks S.M.A.R.T. self-tests status and optionally time of last
7
+ # test run
8
+ #
9
+ # OUTPUT:
10
+ # plain text
11
+ #
12
+ # PLATFORMS:
13
+ # Linux
14
+ #
15
+ # DEPENDENCIES:
16
+ # gem: sensu-plugin
17
+ #
18
+ # USAGE:
19
+ # check-smart-tests.rb # Use default options
20
+ # check-smart-tests.rb -d /dev/sda,/dev/sdb -l 24 -t 336 # Check smart tests status for
21
+ # /dev/sda and /dev/sdb devices, also check if short tests were run in last 24 hours and
22
+ # extended tests were run in last 14 days(336 hours)
23
+ #
24
+ # NOTES:
25
+ # The plugin requires smartmontools to be installed and smartctl utility in particular.
26
+ #
27
+ # smartctl requires root rights to run, so you should allow sensu to execute
28
+ # this command as root without password by adding following line to /etc/sudoers:
29
+ #
30
+ # sensu ALL=(ALL) NOPASSWD: /usr/sbin/smartctl
31
+ #
32
+ # Tested only on Debian.
33
+ #
34
+ # LICENSE:
35
+ # Stanislav Sandalnikov <s.sandalnikov@gmail.com>
36
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
37
+ # for details.
38
+
39
+ require 'sensu-plugin/check/cli'
40
+
41
+ class Device
42
+ attr_accessor :name, :pwh, :str
43
+
44
+ def initialize(name, smartctl_executable)
45
+ @name = name
46
+ @exec = smartctl_executable
47
+ @pwh = poweron_hours
48
+ @str = selftest_results
49
+ end
50
+
51
+ def poweron_hours
52
+ `sudo #{@exec} -A #{@name}`.split("\n").each do |line|
53
+ columns = line.split
54
+ if columns[1] == 'Power_On_Hours'
55
+ return columns[9]
56
+ end
57
+ end
58
+ end
59
+
60
+ def selftest_results
61
+ results = []
62
+ headers = %w(num test_description status remaining lifetime lba_of_first_error)
63
+
64
+ `sudo #{@exec} -l selftest #{@name}`.split("\n").grep(/^#/).each do |test|
65
+ test = test.gsub!(/\s\s+/m, "\t").split("\t")
66
+ res = {}
67
+
68
+ headers.each_with_index do |v, k|
69
+ res[v] = test[k]
70
+ end
71
+
72
+ results << res
73
+ end
74
+
75
+ results
76
+ end
77
+ end
78
+
79
+ class CheckSMARTTests < Sensu::Plugin::Check::CLI
80
+ option :executable,
81
+ long: '--executable EXECUTABLE',
82
+ short: '-e EXECUTABLE',
83
+ default: '/usr/sbin/smartctl',
84
+ description: 'Path to smartctl executable'
85
+ option :devices,
86
+ long: '--devices *DEVICES',
87
+ short: '-d *DEVICES',
88
+ default: 'all',
89
+ description: 'Comma-separated list of devices to check, i.e. "/dev/sda,/dev/sdb"'
90
+ option :short_test_interval,
91
+ long: '--short_test_interval INTERVAL',
92
+ short: '-s INTERVAL',
93
+ description: 'If more time then this value passed since last short test run, then warning will be raised'
94
+ option :long_test_interval,
95
+ long: '--long_test_interval INTERVAL',
96
+ short: '-l INTERVAL',
97
+ description: 'If more time then this value passed since last extedned test run, then warning will be raised'
98
+
99
+ def initialize
100
+ super
101
+ @devices = []
102
+ @warnings = []
103
+ @criticals = []
104
+ set_devices
105
+ end
106
+
107
+ def set_devices
108
+ if config[:devices] == 'all'
109
+ `lsblk -plnd -o NAME`.split.each do |name|
110
+ unless name =~ /\/dev\/loop.*/
111
+ dev = Device.new(name, config[:executable])
112
+ @devices.push(dev)
113
+ end
114
+ end
115
+ else
116
+ config[:devices].split(',').each do |name|
117
+ dev = Device.new(name, config[:executable])
118
+ @devices.push(dev)
119
+ end
120
+ end
121
+ end
122
+
123
+ def check_tests(dev)
124
+ if dev.str.empty?
125
+ @warnings << "#{dev.name}: No self-tests have been logged."
126
+ return
127
+ end
128
+
129
+ unless dev.str[0]['status'] == 'Completed without error' || dev.str[0]['status'] =~ /Self-test routine in progress/
130
+ @criticals << "#{dev.name}: Last test failed - #{dev.str[0]['status']}"
131
+ end
132
+
133
+ unless config[:short_test_interval].nil?
134
+ dev.str.each_with_index do |t, i|
135
+ if t['test_description'] != 'Short offline'
136
+ if i == dev.str.length - 1
137
+ @warnings << "#{dev.name}: No short tests were run for this device in last #{dev.str.length} executions"
138
+ end
139
+ next
140
+ else
141
+ if dev.pwh.to_i - t['lifetime'].to_i > config[:short_test_interval].to_i
142
+ @warnings << "#{dev.name}: More than #{config[:short_test_interval]} hours passed since the last short test"
143
+ end
144
+ break
145
+ end
146
+ end
147
+ end
148
+
149
+ unless config[:long_test_interval].nil?
150
+ dev.str.each_with_index do |t, i|
151
+ if t['test_description'] != 'Extended offline'
152
+ if i == dev.str.length - 1
153
+ @warnings << "#{dev.name}: No extended tests were run for this device in last #{dev.str.length} executions"
154
+ end
155
+ next
156
+ else
157
+ if dev.pwh.to_i - t['lifetime'].to_i > config[:long_test_interval].to_i
158
+ @warnings << "#{dev.name}: More than #{config[:long_test_interval]} hours passed since the last extended test"
159
+ end
160
+ break
161
+ end
162
+ end
163
+ end
164
+ end
165
+
166
+ def run
167
+ @devices.each do |device|
168
+ check_tests(device)
169
+ end
170
+
171
+ if @criticals.any?
172
+ critical @criticals.join(' ')
173
+ elsif @warnings.any?
174
+ warning @warnings.join(' ')
175
+ else
176
+ ok 'All devices are OK'
177
+ end
178
+ end
179
+ end
@@ -1,7 +1,7 @@
1
1
  module SensuPluginsDiskChecks
2
2
  module Version
3
3
  MAJOR = 2
4
- MINOR = 1
4
+ MINOR = 2
5
5
  PATCH = 0
6
6
 
7
7
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-disk-checks
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sensu-Plugins and contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-04 00:00:00.000000000 Z
11
+ date: 2017-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sensu-plugin
@@ -173,6 +173,7 @@ executables:
173
173
  - check-disk-usage.rb
174
174
  - check-fstab-mounts.rb
175
175
  - check-smart-status.rb
176
+ - check-smart-tests.rb
176
177
  - check-smart.rb
177
178
  - metrics-disk-capacity.rb
178
179
  - metrics-disk-usage.rb
@@ -186,6 +187,7 @@ files:
186
187
  - bin/check-disk-usage.rb
187
188
  - bin/check-fstab-mounts.rb
188
189
  - bin/check-smart-status.rb
190
+ - bin/check-smart-tests.rb
189
191
  - bin/check-smart.rb
190
192
  - bin/metrics-disk-capacity.rb
191
193
  - bin/metrics-disk-usage.rb