From 018ce9265a768289d996a26276977bf9819563af Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Wed, 23 Dec 2015 00:35:31 +0000 Subject: [PATCH] Don't do SMART checks on spun down disks --- cookbooks/hardware/recipes/default.rb | 2 ++ .../hardware/templates/default/ohai.rb.erb | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/cookbooks/hardware/recipes/default.rb b/cookbooks/hardware/recipes/default.rb index 0b7b3e6f3..d929bbf57 100644 --- a/cookbooks/hardware/recipes/default.rb +++ b/cookbooks/hardware/recipes/default.rb @@ -298,6 +298,8 @@ end end disks = node[:hardware][:disk][:disks].map do |disk| + next if disk[:state] == "spun_down" + if disk[:smart_device] controller = node[:hardware][:disk][:controllers][disk[:controller]] device = controller[:device].sub("/dev/", "") diff --git a/cookbooks/hardware/templates/default/ohai.rb.erb b/cookbooks/hardware/templates/default/ohai.rb.erb index 6d5e49fb1..b2d56c7d8 100644 --- a/cookbooks/hardware/templates/default/ohai.rb.erb +++ b/cookbooks/hardware/templates/default/ohai.rb.erb @@ -434,6 +434,15 @@ Ohai.plugin(:Hardware) do devices[:disks] << disk controller[:disks] << disk[:id] array[:disks] << disk[:id] + elsif disk && line =~ /^Firmware state:\s+(.*\S)\s*$/ + Regexp.last_match(1).split(/,\s*/).each do |state| + case state + when "Online" then disk[:status] = "online" + when "Hotspare" then disk[:status] = "hotspare" + when "Spun Up" then disk[:spun_down] = false + when "Spun down" then disk[:spun_down] = true + end + end elsif disk && line =~ /^(\S.*\S)\s*:\s+(\S.*)$/ case Regexp.last_match(1) when "Device Id" then disk[:smart_device] = "megaraid,#{Regexp.last_match(2)}" @@ -464,10 +473,18 @@ Ohai.plugin(:Hardware) do devices[:disks] << disk end + elsif disk && line =~ /^Firmware state:\s+(.*\S)\s*$/ + Regexp.last_match(1).split(/,\s*/).each do |state| + case state + when "Online" then disk[:status] = "online" + when "Hotspare" then disk[:status] = "hotspare" + when "Spun Up" then disk[:state] = "spun_up" + when "Spun down" then disk[:state] = "spun_down" + end + end elsif disk && line =~ /^(\S.*\S)\s*:\s+(\S.*)$/ case Regexp.last_match(1) when "Device Id" then disk[:smart_device] = "megaraid,#{Regexp.last_match(2)}" - when "WWN" then disk[:wwn] = Regexp.last_match(2) when "PD Type" then disk[:interface] = Regexp.last_match(2) when "Raw Size" then disk[:size] = memory_to_disk_size(Regexp.last_match(2).sub(/\s*\[.*\]$/, "")) when "Inquiry Data" then disk[:vendor], disk[:model], disk[:serial_number] = Regexp.last_match(2).split -- 2.43.2