]> git.openstreetmap.org Git - chef.git/commitdiff
Improve disk state parsing for megaraid controllers
authorTom Hughes <tom@compton.nu>
Sun, 24 Jul 2022 23:26:40 +0000 (00:26 +0100)
committerTom Hughes <tom@compton.nu>
Sun, 24 Jul 2022 23:26:40 +0000 (00:26 +0100)
cookbooks/hardware/templates/default/ohai.rb.erb

index 97a8823c2c97d26e3e58dbb3e98a827db78bc7c2..343b095a4d7c6c29c5e1f6b580a6f4e45dc5dff2 100644 (file)
@@ -496,8 +496,9 @@ Ohai.plugin(:Hardware) do
         devices[:disks] << disk
         controller[:disks] << disk[:id]
         array[:disks] << disk[:id]
         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"
         when "Unconfigured(good)" then disk[:status] = "unconfigured"
         when "Unconfigured(bad)" then disk[:status] = "unconfigured"
         when "Hotspare" then disk[:status] = "hotspare"
@@ -508,7 +509,7 @@ Ohai.plugin(:Hardware) do
         when "Copyback" then disk[:status] = "rebuilding"
         else disk[:status] = "unknown"
         end
         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"
         when "Spun Up" then disk[:state] = "spun_up"
         when "Spun down" then disk[:state] = "spun_down"
         else disk[:state] = "unknown"
@@ -554,8 +555,9 @@ Ohai.plugin(:Hardware) do
 
           devices[:disks] << disk
         end
 
           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"
         when "Unconfigured(good)" then disk[:status] = "unconfigured"
         when "Unconfigured(bad)" then disk[:status] = "unconfigured"
         when "Hotspare" then disk[:status] = "hotspare"
@@ -566,7 +568,7 @@ Ohai.plugin(:Hardware) do
         when "Copyback" then disk[:status] = "rebuilding"
         else disk[:status] = "unknown"
         end
         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"
         when "Spun Up" then disk[:state] = "spun_up"
         when "Spun down" then disk[:state] = "spun_down"
         else disk[:state] = "unknown"