bin/check-smart-status.rb in sensu-plugins-disk-checks-1.1.2 vs bin/check-smart-status.rb in sensu-plugins-disk-checks-1.1.3

- old
+ new

@@ -70,10 +70,17 @@ long: '--binary /usr/sbin/smartctl', description: 'smartctl binary to use, in case you hide yours', required: false, default: 'smartctl' + option :json, + short: '-j path/to/smart.json', + long: '--json path/to/smart.json', + description: 'Path to SMART attributes JSON file', + required: false, + default: File.dirname(__FILE__) + '/smart.json' + option :defaults, short: '-d 0,0,0,0', long: '--defaults 0,0,0,0', description: 'default threshold for crit_min,warn_min,warn_max,crit_max', required: false, @@ -118,11 +125,11 @@ required: false # Main function # def run - @smart_attributes = JSON.parse(IO.read(File.dirname(__FILE__) + '/smart.json'), symbolize_names: true)[:smart][:attributes] + @smart_attributes = JSON.parse(IO.read(config[:json]), symbolize_names: true)[:smart][:attributes] @smart_debug = config[:debug] == 'on' # Set default threshold default_threshold = config[:defaults].split(',') fail 'Invalid default threshold parameter count' unless default_threshold.size == 4 @@ -239,10 +246,14 @@ # Search for devices without number devices = [] all.each do |line| partition = line.scan(/\w+/).last.scan(/^\D+$/).first - devices << partition unless partition.nil? + next if partition.nil? + output = `sudo #{config[:binary]} -i /dev/#{partition}` + available = !output.scan(/SMART support is: Available/).empty? + enabled = !output.scan(/SMART support is: Enabled/).empty? + devices << partition if available && enabled end devices end