]> git.openstreetmap.org Git - chef.git/blobdiff - cookbooks/hardware/templates/default/ohai.rb.erb
Fix monitoring of devices behind adaptec RAID cards
[chef.git] / cookbooks / hardware / templates / default / ohai.rb.erb
index 6fe38642e51ed009a6188247d6cc5615493fe97f..d223fa0c3c62e59fc69b80d7de2776eaa690c58c 100644 (file)
@@ -148,7 +148,7 @@ Ohai.plugin(:Hardware) do
     find_direct_disks(disk)
     find_nvme_disks(disk)
 
     find_direct_disks(disk)
     find_nvme_disks(disk)
 
-    find_hp_disks(disk) if File.exist?("/usr/sbin/hpssacli")
+    find_hp_disks(disk) if File.exist?("/usr/sbin/ssacli")
     find_megaraid_disks(disk) if File.exist?("/usr/sbin/megacli")
     find_mpt1_disks(disk) if File.exist?("/usr/sbin/lsiutil")
     find_mpt2_disks(disk) if File.exist?("/usr/sbin/sas2ircu")
     find_megaraid_disks(disk) if File.exist?("/usr/sbin/megacli")
     find_mpt1_disks(disk) if File.exist?("/usr/sbin/lsiutil")
     find_mpt2_disks(disk) if File.exist?("/usr/sbin/sas2ircu")
@@ -158,7 +158,7 @@ Ohai.plugin(:Hardware) do
     find_md_arrays(disk)
 
     disk[:disks].each do |disk|
     find_md_arrays(disk)
 
     disk[:disks].each do |disk|
-      if disk[:vendor] =~ /^CVPR/ && disk[:model] == "INTEL"
+      if disk[:vendor] =~ /^(BTWA|CVPR|PHDV)/ && disk[:model] == "INTEL"
         disk[:model] = disk[:serial_number]
         disk[:serial_number] = disk[:vendor]
         disk[:vendor] = "INTEL"
         disk[:model] = disk[:serial_number]
         disk[:serial_number] = disk[:vendor]
         disk[:vendor] = "INTEL"
@@ -286,7 +286,7 @@ Ohai.plugin(:Hardware) do
     array = nil
     disk = nil
 
     array = nil
     disk = nil
 
-    IO.popen(%w(hpssacli controller all show config detail)).each do |line|
+    IO.popen(%w(ssacli controller all show config detail)).each do |line|
       if line =~ /^Smart Array (\S+) /
         controller = {
           :id => devices[:controllers].count,
       if line =~ /^Smart Array (\S+) /
         controller = {
           :id => devices[:controllers].count,
@@ -359,7 +359,7 @@ Ohai.plugin(:Hardware) do
         controller[:device] = File.basename(device).sub(/^cciss(\d+)$/, "/dev/cciss/c\\1d0")
       elsif device = Dir.glob("/sys/bus/pci/devices/#{controller[:pci_slot]}/host*/target*:3:0/*:3:0:0/scsi_generic/sg*").first
         controller[:device] = "/dev/#{File.basename(device)}"
         controller[:device] = File.basename(device).sub(/^cciss(\d+)$/, "/dev/cciss/c\\1d0")
       elsif device = Dir.glob("/sys/bus/pci/devices/#{controller[:pci_slot]}/host*/target*:3:0/*:3:0:0/scsi_generic/sg*").first
         controller[:device] = "/dev/#{File.basename(device)}"
-      elsif device = Dir.glob("/sys/bus/pci/devices/#{controller[:pci_slot]}/host*/target*:1:0/*:1:0:0/scsi_generic/sg*").first
+      elsif device = Dir.glob("/sys/bus/pci/devices/#{controller[:pci_slot]}/host*/target*:1:0/*:1:0:*/scsi_generic/sg*").first
         controller[:device] = "/dev/#{File.basename(device)}"
       end
     end
         controller[:device] = "/dev/#{File.basename(device)}"
       end
     end
@@ -440,10 +440,12 @@ Ohai.plugin(:Hardware) do
       elsif disk && line =~ /^Firmware state:\s+(.*\S)\s*$/
         Regexp.last_match(1).split(/,\s*/).each do |state|
           case state
       elsif disk && line =~ /^Firmware state:\s+(.*\S)\s*$/
         Regexp.last_match(1).split(/,\s*/).each do |state|
           case state
+          when "Unconfigured(bad)" then disk[:status] = "unconfigured"
           when "Online" then disk[:status] = "online"
           when "Hotspare" then disk[:status] = "hotspare"
           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
+          when "Failed" then disk[:status] = "failed"
+          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.*)$/
           end
         end
       elsif disk && line =~ /^(\S.*\S)\s*:\s+(\S.*)$/
@@ -479,8 +481,10 @@ Ohai.plugin(:Hardware) do
       elsif disk && line =~ /^Firmware state:\s+(.*\S)\s*$/
         Regexp.last_match(1).split(/,\s*/).each do |state|
           case state
       elsif disk && line =~ /^Firmware state:\s+(.*\S)\s*$/
         Regexp.last_match(1).split(/,\s*/).each do |state|
           case state
+          when "Unconfigured(bad)" then disk[:status] = "unconfigured"
           when "Online" then disk[:status] = "online"
           when "Hotspare" then disk[:status] = "hotspare"
           when "Online" then disk[:status] = "online"
           when "Hotspare" then disk[:status] = "hotspare"
+          when "Failed" then disk[:status] = "failed"
           when "Spun Up" then disk[:state] = "spun_up"
           when "Spun down" then disk[:state] = "spun_down"
           end
           when "Spun Up" then disk[:state] = "spun_up"
           when "Spun down" then disk[:state] = "spun_down"
           end
@@ -525,8 +529,7 @@ Ohai.plugin(:Hardware) do
           :controller => controller[:id],
           :vendor => Regexp.last_match(4),
           :model => Regexp.last_match(5),
           :controller => controller[:id],
           :vendor => Regexp.last_match(4),
           :model => Regexp.last_match(5),
-          :bus =>  Regexp.last_match(1),
-          :target =>  Regexp.last_match(2),
+          :sas_address => Regexp.last_match(6),
           :arrays => []
         }
 
           :arrays => []
         }
 
@@ -570,11 +573,14 @@ Ohai.plugin(:Hardware) do
 
     disks.each do |disk|
       slot = controllers[disk[:controller]][:pci_slot]
 
     disks.each do |disk|
       slot = controllers[disk[:controller]][:pci_slot]
-      bus = disk[:bus]
-      target = disk[:target]
+      sas_address = "0x#{disk[:sas_address]}"
 
 
-      if device = Dir.glob("/sys/bus/pci/devices/#{slot}/host*/port-*:*/end_device-*:*/target*:#{bus}:#{target}/*:#{bus}:#{target}:0/scsi_generic/sg*").first
-        disk[:device] = "/dev/#{File.basename(device)}"
+      Dir.glob("/sys/bus/pci/devices/#{slot}/host*/port-*:*/end_device-*:*/sas_device/end_device-*:*").each do |sas_device|
+        if read_sysctl_file("#{sas_device}/sas_address") == sas_address
+          if device = Dir.glob("#{sas_device}/device/target*:0:*/*:0:*:0/scsi_generic/sg*").first
+            disk[:device] = "/dev/#{File.basename(device)}"            
+          end
+        end
       end
     end
   end
       end
     end
   end
@@ -760,10 +766,11 @@ Ohai.plugin(:Hardware) do
         array[:disks].map! do |location|
           disk = disks.find { |disk| disk[:location] == location }
 
         array[:disks].map! do |location|
           disk = disks.find { |disk| disk[:location] == location }
 
+          controller_number = controller[:number] - 1
           device_number = disk[:device_number]
           device_number = disk[:device_number]
-          device = Dir.glob("#{host}/device/target*:1:#{device_number}/*:1:#{device_number}:0/scsi_generic/*").first
 
           disk[:device] = "/dev/#{File.basename(device)}"
 
           disk[:device] = "/dev/#{File.basename(device)}"
+          disk[:smart_device] = "aacraid,#{controller_number},0,#{device_number}"
 
           disk[:arrays] << array[:id]
           disk[:id]
 
           disk[:arrays] << array[:id]
           disk[:id]