]> git.openstreetmap.org Git - chef.git/blobdiff - cookbooks/hardware/templates/default/ohai.rb.erb
Merge remote-tracking branch 'tigerfell/pr257'
[chef.git] / cookbooks / hardware / templates / default / ohai.rb.erb
index 8c7d633ab166705bc274568e552e5cdd3a033703..c7d245b94e555abf1d2978f2f786eae19e9eb359 100644 (file)
@@ -253,19 +253,10 @@ Ohai.plugin(:Hardware) do
   end
 
   def find_md_arrays(devices)
-    controller = {
-      :id => devices[:controllers].count,
-      :type => "md",
-      :arrays => [],
-      :disks => []
-    }
-
-    devices[:controllers] << controller
-
     array = nil
 
     File.new("/proc/mdstat", "r").each do |line|
-      if line =~ /^(md\d+) : active raid(\d+)((?: (?:sd[a-z]|nvme\d+n\d+)\d*\[\d+\](?:\([A-Z]\))*)+)$/
+      if line =~ /^(md\d+) : active raid(\d+)((?: (?:sd[a-z]\d*|nvme\d+n\d+(?:p\d+)?)\[\d+\](?:\([A-Z]\))*)+)$/
         array = {
           :id => devices[:arrays].count,
           :device => "/dev/#{Regexp.last_match(1)}",
@@ -294,7 +285,6 @@ Ohai.plugin(:Hardware) do
         end
 
         devices[:arrays] << array
-        controller[:arrays] << array[:id]
       elsif array && line =~ /^\s+(\d+) blocks.*(?:\[([U_]+)\])?/
         array[:size] = format_disk_size(Regexp.last_match(1).to_i)
         array[:status] = "degraded" if Regexp.last_match(2) =~ /_/
@@ -317,6 +307,8 @@ Ohai.plugin(:Hardware) do
     disk = nil
 
     IO.popen(%w(ssacli controller all show config detail)).each do |line|
+      next unless line.valid_encoding?
+
       if line =~ /^Smart (?:Array|HBA) (\S+) /
         controller = {
           :id => devices[:controllers].count,
@@ -377,6 +369,7 @@ Ohai.plugin(:Hardware) do
       elsif array && line =~ /^         Status:\s+(.*\S)\s*$/
         case Regexp.last_match(1)
         when "OK" then array[:status] = "optimal"
+        when "Interim Recovery Mode" then array[:status] = "degraded"
         else array[:status] = "unknown"
         end
       elsif array && line =~ /^         (\S[^:]+):\s+(.*\S)\s*$/
@@ -414,10 +407,14 @@ Ohai.plugin(:Hardware) do
 
       if disk[:status] == "Failed"
         disk[:status] = "failed"
+      elsif disk[:status] == "Predictive Failure"
+        disk[:status] = "failed"
       elsif disk[:status] == "OK" && disk[:drive_type] == "Data Drive"
         disk[:status] = "online"
       elsif disk[:status] == "OK" && disk[:drive_type] == "Spare Drive"
         disk[:status] = "hotspare"
+      elsif disk[:drive_type] == "Unassigned Drive"
+        disk[:status] = "unconfigured"
       else
         disk[:status] = "unknown"
       end
@@ -499,8 +496,9 @@ Ohai.plugin(:Hardware) do
         devices[:disks] << disk
         controller[:disks] << disk[:id]
         array[:disks] << disk[:id]
-      elsif disk && line =~ /^Firmware state:\s+(.*\S),\s*(.*\S)\s*$/
-        case Regexp.last_match(1)
+      elsif disk && line =~ /^Firmware state:\s+(\S.*)$/
+        status, state = Regexp.last_match(1).split(/,\s*/)
+        case status
         when "Unconfigured(good)" then disk[:status] = "unconfigured"
         when "Unconfigured(bad)" then disk[:status] = "unconfigured"
         when "Hotspare" then disk[:status] = "hotspare"
@@ -511,7 +509,7 @@ Ohai.plugin(:Hardware) do
         when "Copyback" then disk[:status] = "rebuilding"
         else disk[:status] = "unknown"
         end
-        case Regexp.last_match(2)
+        case state
         when "Spun Up" then disk[:state] = "spun_up"
         when "Spun down" then disk[:state] = "spun_down"
         else disk[:state] = "unknown"
@@ -557,8 +555,9 @@ Ohai.plugin(:Hardware) do
 
           devices[:disks] << disk
         end
-      elsif disk && line =~ /^Firmware state:\s+(.*\S),\s*(.*\S)\s*$/
-        case Regexp.last_match(1)
+      elsif disk && line =~ /^Firmware state:\s+(\S.*)$/
+        status, state = Regexp.last_match(1).split(/,\s*/)
+        case status
         when "Unconfigured(good)" then disk[:status] = "unconfigured"
         when "Unconfigured(bad)" then disk[:status] = "unconfigured"
         when "Hotspare" then disk[:status] = "hotspare"
@@ -569,7 +568,7 @@ Ohai.plugin(:Hardware) do
         when "Copyback" then disk[:status] = "rebuilding"
         else disk[:status] = "unknown"
         end
-        case Regexp.last_match(2)
+        case state
         when "Spun Up" then disk[:state] = "spun_up"
         when "Spun down" then disk[:state] = "spun_down"
         else disk[:state] = "unknown"