]> git.openstreetmap.org Git - chef.git/commitdiff
Gather information on MD RAID arrays
authorTom Hughes <tom@compton.nu>
Mon, 30 Nov 2015 09:47:51 +0000 (09:47 +0000)
committerTom Hughes <tom@compton.nu>
Mon, 30 Nov 2015 09:47:51 +0000 (09:47 +0000)
cookbooks/hardware/templates/default/ohai.rb.erb

index 6c83be31e7bffe8f88032fff2f32ef695f61a185..965a52af67d6cf8d62251928fc0ae027b71863a4 100644 (file)
@@ -86,11 +86,14 @@ Ohai.plugin(:Hardware) do
     disk[:disks] = []
 
     find_direct_disks(disk)
+
     find_hp_disks(disk) if File.exist?("/usr/sbin/hpssacli")
     find_megaraid_disks(disk) if File.exist?("/usr/sbin/megacli")
     # aacraid
     # areca (/opt/areca/x86_64/cli64)
 
+    find_md_arrays(disk)
+
     disk
   end
 
@@ -127,13 +130,36 @@ Ohai.plugin(:Hardware) do
             :vendor => vendor,
             :model => model,
             :firmware_version => read_sysctl_file("#{device}/rev"),
-            :size => size
+            :size => size,
+            :arrays => []
           }
         end
       end
     end
   end
 
+  def find_md_arrays(devices)
+    File.new("/proc/mdstat", "r").each do |line|
+      next unless line =~ /^(md\d+) : active raid(\d+)((?: [a-z]+\d+\[\d+\](?:\([A-Z]\))*)+)$/
+
+      array = {
+        :id => devices[:arrays].count,
+        :device => "/dev/#{Regexp.last_match(1)}",
+        :raid_level => Regexp.last_match(2),
+        :disks => []
+      }
+
+      Regexp.last_match(3).scan(/ ([a-z]+)\d+\[\d+\](?:\([A-Z]\))*/).flatten.each do |device|
+        if disk = devices[:disks].find { |d| d[:device] == "/dev/#{device}" }
+          disk[:arrays] << array[:id]
+          array[:disks] << disk[:id]
+        end
+      end
+
+      devices[:arrays] << array
+    end
+  end
+
   def find_hp_disks(devices)
     controllers = []
     disks = []
@@ -182,7 +208,7 @@ Ohai.plugin(:Hardware) do
         disk = {
           :id => devices[:disks].count,
           :controller => controller[:id],
-          :array => array[:id],
+          :arrays => [array[:id]],
           :location => Regexp.last_match(1),
           :smart_device => "cciss,#{disks.find_index(Regexp.last_match(1))}"
         }
@@ -280,7 +306,7 @@ Ohai.plugin(:Hardware) do
         disk = {
           :id => devices[:disks].count,
           :controller => controller[:id],
-          :array => array[:id]
+          :arrays => [array[:id]]
         }
 
         devices[:disks] << disk