sensu-plugins-disk-checks 2.3.0 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7ae84371b0313755e6f35d66f15a27c7fd3a5391
4
- data.tar.gz: 3a97790fc26b5d294325fec99d69a94a8c4d4cb4
3
+ metadata.gz: 5d69846d3e98c17975dccd7363228e869ac3b734
4
+ data.tar.gz: ddcb9c5ee9e02cca40778d1203a5544304a0dc52
5
5
  SHA512:
6
- metadata.gz: 335e15d42b7fbf28249abe3a7f817a6aab89438b963e962a38858c2226a43cb2eb8fca4c227ffe606b73d474e349043d13fd9ae064e0a13c63e755a17b2625e2
7
- data.tar.gz: c7c602682333821a181a5a06d6bf9d736898cb209542213311006193c45975547031def9759aca660232e28c75de1bde7136b4be03dd5c444e9218c4d144cadc
6
+ metadata.gz: 8313f14f4c20ca876ae5905cec5cef2fea5026c35d2c16f5bc27b2274005e9dc0f601b41818724a581b50d610e5b0484cfcb3e53d351bc5c6140ad01dfcd18cf
7
+ data.tar.gz: 293372a87d24a68f3e1d7f257ced4ecafd1657c6edd5f18e6afd6761112685e2a22be9fb157b0604d7df71814d305bd9e81a326d03b0a51619cf91738beefe18
data/CHANGELOG.md CHANGED
@@ -1,10 +1,14 @@
1
- #Change Log
1
+ # Change Log
2
2
  This project adheres to [Semantic Versioning](http://semver.org/).
3
3
 
4
4
  This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/)
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [2.4.0] - 2017-07-20
9
+ - check-smart.rb: Add path overrides via smart.json (@ArakniD)
10
+ - check-smart-status.rb: Add path overrides via smart.json (@ArakniD)
11
+
8
12
  ## [2.3.0] - 2017-07-03
9
13
  ### Added
10
14
  - travis testing on ruby 2.4.1 (@majormoses)
@@ -133,7 +137,9 @@ https://mathias-kettner.de/checkmk_filesystems.html
133
137
  ### Added
134
138
  - initial release
135
139
 
136
- [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-disk-checks/compare/2.2.0...HEAD
140
+ [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-disk-checks/compare/2.4.0...HEAD
141
+ [2.4.0]: https://github.com/sensu-plugins/sensu-plugins-disk-checks/compare/2.3.0...2.4.0
142
+ [2.3.0]: https://github.com/sensu-plugins/sensu-plugins-disk-checks/compare/2.2.0...2.3.0
137
143
  [2.2.0]: https://github.com/sensu-plugins/sensu-plugins-disk-checks/compare/2.1.0...2.2.0
138
144
  [2.1.0]: https://github.com/sensu-plugins/sensu-plugins-disk-checks/compare/2.0.1...2.1.0
139
145
  [2.0.1]: https://github.com/sensu-plugins/sensu-plugins-disk-checks/compare/2.0.0...2.0.1
data/README.md CHANGED
@@ -68,7 +68,7 @@ Check the status of SMART offline tests and optionally check if tests were execu
68
68
 
69
69
  ## Usage
70
70
 
71
- This is a sample input file used by check-smart-status, see the script for further details.
71
+ This is a sample input file used by check-smart-status and check-smart, see the script for further details.
72
72
  ```json
73
73
  {
74
74
  "smart": {
@@ -89,6 +89,12 @@ This is a sample input file used by check-smart-status, see the script for furth
89
89
  { "id": 201, "name": "Unc_Soft_read_Err_Rate", "read": "left16bit" },
90
90
  { "id": 230, "name": "Life_Curve_Status", "crit_min": 100, "warn_min": 100, "warn_max": 100, "crit_max": 100 }
91
91
  ]
92
+ },
93
+ "hardware": {
94
+ "devices": [
95
+ { "path": "sda", "ignore" : [ 187 ] },
96
+ { "path": "sdb", "override": "/dev/twa0 -d 3ware,0" }
97
+ ]
92
98
  }
93
99
  }
94
100
  ```
@@ -61,6 +61,33 @@
61
61
  require 'sensu-plugin/check/cli'
62
62
  require 'json'
63
63
 
64
+ class Disk
65
+ # Setup variables
66
+ #
67
+ def initialize(name, override, ignore)
68
+ @device_path = "/dev/#{name}"
69
+ @override_path = override
70
+ @att_ignore = ignore
71
+ end
72
+
73
+ # Is the device SMART capable and enabled
74
+ #
75
+ def device_path
76
+ if @override_path.nil?
77
+ @device_path
78
+ else
79
+ @override_path
80
+ end
81
+ end
82
+
83
+ def smart_ignore?(num)
84
+ return if @att_ignore.nil?
85
+ @att_ignore.include? num
86
+ end
87
+
88
+ public :device_path, :smart_ignore?
89
+ end
90
+
64
91
  #
65
92
  # Smart Check Status
66
93
  #
@@ -130,6 +157,9 @@ class SmartCheckStatus < Sensu::Plugin::Check::CLI
130
157
  @smart_attributes = JSON.parse(IO.read(config[:json]), symbolize_names: true)[:smart][:attributes]
131
158
  @smart_debug = config[:debug] == 'on'
132
159
 
160
+ # Load in the device configuration
161
+ @hardware = JSON.parse(IO.read(config[:json]), symbolize_names: true)[:hardware][:devices]
162
+
133
163
  # Set default threshold
134
164
  default_threshold = config[:defaults].split(',')
135
165
  raise 'Invalid default threshold parameter count' unless default_threshold.size == 4
@@ -160,7 +190,7 @@ class SmartCheckStatus < Sensu::Plugin::Check::CLI
160
190
  att_check_list = find_attributes
161
191
 
162
192
  # Devices to check
163
- devices = config[:debug_file].nil? ? find_devices : ['sda']
193
+ devices = config[:debug_file].nil? ? find_devices : [Disk.new('sda', nil, nil)]
164
194
 
165
195
  # Overall health and attributes parameter
166
196
  parameters = '-H -A'
@@ -174,10 +204,10 @@ class SmartCheckStatus < Sensu::Plugin::Check::CLI
174
204
  warnings = []
175
205
  criticals = []
176
206
  devices.each do |dev|
177
- puts "#{config[:binary]} #{parameters} /dev/#{dev}" if @smart_debug
207
+ puts "#{config[:binary]} #{parameters} #{dev.device_path}" if @smart_debug
178
208
  # check if debug file specified
179
209
  if config[:debug_file].nil?
180
- output[dev] = `sudo #{config[:binary]} #{parameters} /dev/#{dev}`
210
+ output[dev] = `sudo #{config[:binary]} #{parameters} #{dev.device_path}`
181
211
  else
182
212
  test_file = File.open(config[:debug_file], 'rb')
183
213
  output[dev] = test_file.read
@@ -186,13 +216,13 @@ class SmartCheckStatus < Sensu::Plugin::Check::CLI
186
216
 
187
217
  # check overall helath status
188
218
  if config[:overall] == 'on' && !output[dev].include?('SMART overall-health self-assessment test result: PASSED')
189
- criticals << "Overall health check failed on #{dev}"
219
+ criticals << "Overall health check failed on #{dev.name}"
190
220
  end
191
221
 
192
222
  # #YELLOW
193
223
  output[dev].split("\n").each do |line|
194
224
  fields = line.split
195
- if fields.size == 10 && fields[0].to_i != 0 && att_check_list.include?(fields[0].to_i)
225
+ if fields.size == 10 && fields[0].to_i != 0 && att_check_list.include?(fields[0].to_i) && (dev.smart_ignore?(fields[0].to_i) == false)
196
226
  smart_att = @smart_attributes.find { |att| att[:id] == fields[0].to_i }
197
227
  att_value = fields[9].to_i
198
228
  att_value = send(smart_att[:read], att_value) unless smart_att[:read].nil?
@@ -235,24 +265,40 @@ class SmartCheckStatus < Sensu::Plugin::Check::CLI
235
265
  # find all devices from /proc/partitions or from parameter
236
266
  #
237
267
  def find_devices
268
+ # Search for devices without number
269
+ devices = []
270
+
238
271
  # Return parameter value if it's defined
239
- return config[:devices].split(',') unless config[:devices] == 'all'
272
+ if config[:devices] != 'all'
273
+ config[:devices].split(',').each do |dev|
274
+ devices << Disk.new(dev.to_s, '', nil)
275
+ end
276
+ return devices
277
+ end
240
278
 
241
- # List all device and split it by new line
242
- all = `cat /proc/partitions`.split("\n")
279
+ `lsblk -nro NAME,TYPE`.each_line do |line|
280
+ name, type = line.split
243
281
 
244
- # Delete first two row (header and empty line)
245
- (1..2).each { all.delete_at(0) }
282
+ if type == 'disk'
283
+ jconfig = @hardware.find { |h1| h1[:path] == name }
246
284
 
247
- # Search for devices without number
248
- devices = []
249
- all.each do |line|
250
- partition = line.scan(/\w+/).last.scan(/^\D+$/).first
251
- next if partition.nil?
252
- output = `sudo #{config[:binary]} -i /dev/#{partition}`
253
- available = !output.scan(/SMART support is: Available/).empty?
254
- enabled = !output.scan(/SMART support is: Enabled/).empty?
255
- devices << partition if available && enabled
285
+ if jconfig.nil?
286
+ override = nil
287
+ ignore = nil
288
+ else
289
+ override = jconfig[:override]
290
+ ignore = jconfig[:ignore]
291
+ end
292
+
293
+ device = Disk.new(name, override, ignore)
294
+
295
+ output = `sudo #{config[:binary]} -i #{device.device_path}`
296
+
297
+ # Check if we can use this device or not
298
+ available = !output.scan(/SMART support is:\+sAvailable/).empty?
299
+ enabled = !output.scan(/SMART support is:\+sEnabled/).empty?
300
+ devices << device if available && enabled
301
+ end
256
302
  end
257
303
 
258
304
  devices
data/bin/check-smart.rb CHANGED
@@ -37,6 +37,7 @@
37
37
  #
38
38
 
39
39
  require 'sensu-plugin/check/cli'
40
+ require 'json'
40
41
 
41
42
  #
42
43
  # Disk
@@ -44,11 +45,13 @@ require 'sensu-plugin/check/cli'
44
45
  class Disk
45
46
  # Setup variables
46
47
  #
47
- def initialize(name)
48
+ def initialize(name, override, binary)
48
49
  @device_path = "/dev/#{name}"
49
50
  @smart_available = false
50
51
  @smart_enabled = false
51
52
  @smart_healty = nil
53
+ @smart_binary = binary
54
+ @override_path = override
52
55
  check_smart_capability!
53
56
  check_health! if smart_capable?
54
57
  end
@@ -61,10 +64,20 @@ class Disk
61
64
  @smart_available && @smart_enabled
62
65
  end
63
66
 
67
+ # Is the device SMART capable and enabled
68
+ #
69
+ def device_path
70
+ if @override_path.nil?
71
+ @device_path
72
+ else
73
+ @override_path
74
+ end
75
+ end
76
+
64
77
  # Check for SMART cspability
65
78
  #
66
79
  def check_smart_capability!
67
- output = `sudo smartctl -i #{@device_path}`
80
+ output = `sudo #{@smart_binary} -i #{@device_path}`
68
81
  @smart_available = !output.scan(/SMART support is:\s+Available/).empty?
69
82
  @smart_enabled = !output.scan(/SMART support is:\s+Enabled/).empty?
70
83
  @capability_output = output
@@ -73,7 +86,7 @@ class Disk
73
86
  # Check the SMART health
74
87
  #
75
88
  def check_health!
76
- output = `sudo smartctl -H #{@device_path}`
89
+ output = `sudo #{@smart_binary} -H #{@device_path}`
77
90
  @smart_healthy = !output.scan(/PASSED|OK$/).empty?
78
91
  @health_output = output
79
92
  end
@@ -89,11 +102,29 @@ class CheckSMART < Sensu::Plugin::Check::CLI
89
102
  proc: proc(&:to_sym),
90
103
  default: :unknown
91
104
 
105
+ option :binary,
106
+ short: '-b path/to/smartctl',
107
+ long: '--binary /usr/sbin/smartctl',
108
+ description: 'smartctl binary to use, in case you hide yours',
109
+ required: false,
110
+ default: 'smartctl'
111
+
112
+ option :json,
113
+ short: '-j path/to/smart.json',
114
+ long: '--json path/to/smart.json',
115
+ description: 'Path to SMART attributes JSON file',
116
+ required: false,
117
+ default: File.dirname(__FILE__) + '/smart.json'
118
+
92
119
  # Setup variables
93
120
  #
94
121
  def initialize
95
122
  super
96
123
  @devices = []
124
+
125
+ # Load in the device configuration
126
+ @hardware = JSON.parse(IO.read(config[:json]), symbolize_names: true)[:hardware][:devices]
127
+
97
128
  scan_disks!
98
129
  end
99
130
 
@@ -102,7 +133,22 @@ class CheckSMART < Sensu::Plugin::Check::CLI
102
133
  def scan_disks!
103
134
  `lsblk -nro NAME,TYPE`.each_line do |line|
104
135
  name, type = line.split
105
- @devices << Disk.new(name) if type == 'disk'
136
+
137
+ if type == 'disk'
138
+ jconfig = @hardware.find { |h1| h1[:path] == name }
139
+
140
+ override = !jconfig.nil? ? jconfig[:override] : nil
141
+
142
+ device = Disk.new(name, override, config[:binary])
143
+
144
+ output = `sudo #{config[:binary]} -i #{device.device_path}`
145
+
146
+ # Check if we can use this device or not
147
+ available = !output.scan(/SMART support is:\s+Available/).empty?
148
+ enabled = !output.scan(/SMART support is:\s+Enabled/).empty?
149
+
150
+ @devices << device if available && enabled
151
+ end
106
152
  end
107
153
  end
108
154
 
@@ -1,7 +1,7 @@
1
1
  module SensuPluginsDiskChecks
2
2
  module Version
3
3
  MAJOR = 2
4
- MINOR = 3
4
+ MINOR = 4
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.3.0
4
+ version: 2.4.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-07-03 00:00:00.000000000 Z
11
+ date: 2017-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sensu-plugin
@@ -220,7 +220,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
220
220
  version: '0'
221
221
  requirements: []
222
222
  rubyforge_project:
223
- rubygems_version: 2.4.5
223
+ rubygems_version: 2.6.11
224
224
  signing_key:
225
225
  specification_version: 4
226
226
  summary: Sensu plugins for disk checks