3 Ohai.plugin(:Hardware) do
6 def read_sysctl_link(file)
7 File.basename(File.readlink(file))
11 def read_sysctl_file(file)
13 rescue Errno::ENOENT, Errno::EINVAL
16 def parse_memory_size(size)
17 if size =~ /^(\d+(?:\.\d+)?)\s*TB/i
18 Regexp.last_match(1).to_f * 2**30
19 elsif size =~ /^(\d+(?:\.\d+)?)\s*GB/i
20 Regexp.last_match(1).to_f * 2**20
21 elsif size =~ /^(\d+(?:\.\d+)?)\s*MB/i
22 Regexp.last_match(1).to_f * 2**10
26 def format_disk_size(kb)
30 kblog10 = Math.log10(kb).floor
32 kb = kb.to_f * 2 / 10**kblog10
33 kb = kb.round.to_f / 2
36 format "%gTB", kb * 10**(kblog10 - 9)
38 format "%dGB", kb * 10**(kblog10 - 6)
40 format "%dMB", kb * 10**(kblog10 - 3)
45 def memory_to_disk_size(size)
46 format_disk_size(parse_memory_size(size))
49 def find_sas_device(address)
50 file = Dir.glob("/sys/class/scsi_generic/sg*/device/sas_address").find do |file|
51 read_sysctl_file(file) == "0x#{address}"
55 dir = File.dirname(file)
56 device = Dir.glob("#{dir}/block/*").first ||
57 Dir.glob("#{dir}/scsi_generic/*").first
59 "/dev/#{File.basename(device)}"
67 IO.popen(["lspci", "-Dkvmm"]).each do |line|
68 if line =~ /^Slot:\s+((\h{4}):(\h{2}):(\h{2}).(\h))\s*$/
70 :slot => Regexp.last_match(1),
71 :domain => Regexp.last_match(2),
72 :bus => Regexp.last_match(3),
73 :device => Regexp.last_match(4),
74 :function => Regexp.last_match(5)
76 elsif device && line =~ /^([A-Z]+):\s+(.*)\s*$/i
77 case Regexp.last_match(1)
78 when "Class" then device[:class_name] = Regexp.last_match(2)
79 when "Vendor" then device[:vendor_name] = Regexp.last_match(2)
80 when "Device" then device[:device_name] = Regexp.last_match(2)
81 when "SVendor" then device[:subsystem_vendor_name] = Regexp.last_match(2)
82 when "SDevice" then device[:subsystem_device_name] = Regexp.last_match(2)
83 when "PhySlot" then device[:physical_slot] = Regexp.last_match(2)
84 when "Rev" then device[:revision] = Regexp.last_match(2)
85 when "ProgIf" then device[:programming_interface] = Regexp.last_match(2)
86 when "Driver" then device[:driver] = Regexp.last_match(2)
87 when "Module" then device[:modules] = Array(device[:modules]) << Regexp.last_match(2)
89 elsif device && line =~ /^\s*$/
90 devices[device[:slot]] = device
95 IO.popen(["lspci", "-Dkvmmn"]).each do |line|
96 if line =~ /^Slot:\s+((\h{4}):(\h{2}):(\h{2}).(\h))\s*$/
97 device = devices[Regexp.last_match(1)]
98 elsif device && line =~ /^([A-Z]+):\s+(.*)\s*$/i
99 case Regexp.last_match(1)
100 when "Class" then device[:class_id] = Regexp.last_match(2)
101 when "Vendor" then device[:vendor_id] = Regexp.last_match(2)
102 when "Device" then device[:device_id] = Regexp.last_match(2)
103 when "SVendor" then device[:subsystem_vendor_id] = Regexp.last_match(2)
104 when "SDevice" then device[:subsystem_device_id] = Regexp.last_match(2)
106 elsif device && line =~ /^\s*$/
115 Dir.glob("/sys/class/net/*").each_with_object(Mash.new) do |device, devices|
116 name = File.basename(device)
119 :device => read_sysctl_link("#{device}/device"),
120 :duplex => read_sysctl_file("#{device}/duplex"),
121 :speed => read_sysctl_file("#{device}/speed")
122 }.delete_if { |_, v| v.nil? }
129 IO.popen(["dmidecode", "-t", "memory"]).each_with_object([]) do |line, devices|
130 if line =~ /^Memory Device\s*$/
132 elsif device && line =~ /^\s+([A-Z ]+):\s+(.*)\s*$/i
133 device[Regexp.last_match(1).tr(" ", "_").downcase.to_sym] = Regexp.last_match(2).strip
134 elsif device && line =~ /^\s*$/
144 disk[:controllers] = []
148 find_direct_disks(disk)
149 find_nvme_disks(disk)
151 find_hp_disks(disk) if File.exist?("/usr/sbin/hpssacli")
152 find_megaraid_disks(disk) if File.exist?("/usr/sbin/megacli")
153 find_mpt_disks(disk) if File.exist?("/usr/sbin/sas2ircu")
154 find_adaptec_disks(disk) if File.exist?("/usr/sbin/arcconf")
155 find_areca_disks(disk) if File.exist?("/opt/areca/x86_64/cli64")
159 disk[:disks].each do |disk|
160 if disk[:vendor] =~ /^CVPR/ && disk[:model] == "INTEL"
161 disk[:model] = disk[:serial_number]
162 disk[:serial_number] = disk[:vendor]
163 disk[:vendor] = "INTEL"
166 if disk[:vendor].nil? && disk[:model] =~ /^ATA\s+(.*)$/
167 disk[:vendor] = "ATA"
168 disk[:model] = Regexp.last_match(1)
171 if disk[:vendor].nil? || disk[:vendor] == "ATA"
172 if disk[:model] =~ /^(\S+)\s+(.*)$/
173 disk[:vendor] = Regexp.last_match(1)
174 disk[:model] = Regexp.last_match(2)
175 elsif disk[:model] =~ /^ST/
176 disk[:vendor] = "SEAGATE"
177 elsif disk[:model] =~ /^C300-(.*)$/
178 disk[:vendor] = "CRUCIAL"
179 disk[:model] = Regexp.last_match(1)
183 disk[:model].sub!(/-.*$/, "")
189 def find_direct_disks(devices)
190 Dir.glob("/sys/class/scsi_host/host*") do |host|
191 driver = read_sysctl_file("#{host}/proc_name")
193 if %w(ahci mptsas sata_mv sata_nv).include?(driver)
194 bus = host.sub("/sys/class/scsi_host/host", "")
196 Dir.glob("/sys/bus/scsi/devices/#{bus}:0:*").each do |device|
197 next unless File.exist?("#{device}/scsi_disk")
199 block = Dir.glob("#{device}/block/*").first
200 size = read_sysctl_file("#{block}/size").to_f / 2
203 :id => devices[:disks].count,
204 :device => "/dev/#{File.basename(block)}",
205 :vendor => read_sysctl_file("#{device}/vendor"),
206 :model => read_sysctl_file("#{device}/model"),
207 :firmware_version => read_sysctl_file("#{device}/rev"),
208 :size => format_disk_size(size),
216 def find_nvme_disks(devices)
217 Dir.glob("/sys/class/misc/nvme*") do |device|
219 :id => devices[:controllers].count,
220 :pci_slot => File.basename(Pathname.new("#{device}/device").realpath),
225 devices[:controllers] << controller
227 IO.popen(["lspci", "-Dkvmm", "-s", controller[:pci_slot]]).each do |line|
228 if line =~ /^SVendor:\s+(\S.*\S)\s*$/
229 controller[:vendor] = Regexp.last_match(1)
230 elsif line =~ /^SDevice:\s+(\S.*\S)\s*$/
231 controller[:model] = Regexp.last_match(1)
235 Dir.glob("#{device}/device/block/*").each do |block|
236 size = read_sysctl_file("#{block}/size").to_f / 2
239 :id => devices[:disks].count,
240 :controller => controller[:id],
241 :device => "/dev/#{File.basename(block)}",
242 :vendor => controller[:vendor],
243 :model => controller[:model],
244 :size => format_disk_size(size),
248 devices[:disks] << disk
249 controller[:disks] << disk[:id]
254 def find_md_arrays(devices)
257 File.new("/proc/mdstat", "r").each do |line|
258 if line =~ /^(md\d+) : active raid(\d+)((?: (?:sd[a-z]|nvme\d+n\d+)\d*\[\d+\](?:\([A-Z]\))*)+)$/
260 :id => devices[:arrays].count,
261 :device => "/dev/#{Regexp.last_match(1)}",
262 :raid_level => Regexp.last_match(2),
266 Regexp.last_match(3).scan(/ (sd[a-z]+|nvme\d+n\d+)\d*\[\d+\](?:\([A-Z]\))*/).flatten.each do |device|
267 if disk = devices[:disks].find { |d| d[:device] == "/dev/#{device}" }
268 disk[:arrays] << array[:id]
269 array[:disks] << disk[:id]
273 devices[:arrays] << array
274 elsif array && line =~ /^\s+(\d+) blocks/
275 array[:size] = format_disk_size(Regexp.last_match(1).to_i)
280 def find_hp_disks(devices)
288 IO.popen(%w(hpssacli controller all show config detail)).each do |line|
289 if line =~ /^Smart Array (\S+) /
291 :id => devices[:controllers].count,
292 :model => Regexp.last_match(1),
297 devices[:controllers] << controller
299 controllers << controller
303 elsif controller && line =~ /^ (\S.*):\s+(.*)$/
304 case Regexp.last_match(1)
305 when "Serial Number" then controller[:serial_number] = Regexp.last_match(2)
306 when "Hardware Revision" then controller[:hardware_version] = Regexp.last_match(2)
307 when "Firmware Version" then controller[:firmware_version] = Regexp.last_match(2)
308 when "PCI Address (Domain:Bus:Device.Function)" then controller[:pci_slot] = Regexp.last_match(2)
310 elsif controller && line =~ /^ Logical Drive: (\d+)$/
312 :id => devices[:arrays].count,
313 :controller => controller[:id],
314 :number => Regexp.last_match(1),
318 devices[:arrays] << array
319 controller[:arrays] << array[:id]
322 elsif controller && line =~ /^ physicaldrive (\S+) /
323 disks << Regexp.last_match(1)
324 elsif array && line =~ /^ physicaldrive (\S+)$/
326 :id => devices[:disks].count,
327 :controller => controller[:id],
328 :arrays => [array[:id]],
329 :location => Regexp.last_match(1),
330 :smart_device => "cciss,#{disks.find_index(Regexp.last_match(1))}"
333 devices[:disks] << disk
334 controller[:disks] << disk[:id]
335 array[:disks] << disk[:id]
336 elsif disk && line =~ /^ (\S[^:]+):\s+(.*\S)\s*$/
337 case Regexp.last_match(1)
338 when "Interface Type" then disk[:interface] = Regexp.last_match(2)
339 when "Size" then disk[:size] = Regexp.last_match(2)
340 when "Rotational Speed" then disk[:rpm] = Regexp.last_match(2)
341 when "Firmware Revision" then disk[:firmware_version] = Regexp.last_match(2)
342 when "Serial Number" then disk[:serial_number] = Regexp.last_match(2)
343 when "Model" then disk[:model] = Regexp.last_match(2)
345 elsif array && line =~ /^ (\S[^:]+):\s+(.*\S)\s*$/
346 case Regexp.last_match(1)
347 when "Size" then array[:size] = Regexp.last_match(2)
348 when "Fault Tolerance" then array[:raid_level] = Regexp.last_match(2)
349 when "Disk Name" then array[:device] = Regexp.last_match(2).strip
350 when "Mount Points" then array[:mount_point] = Regexp.last_match(2).split.first
351 when "Unique Identifier" then array[:wwn] = Regexp.last_match(2)
356 controllers.each do |controller|
357 if device = Dir.glob("/sys/bus/pci/devices/#{controller[:pci_slot]}/cciss*").first
358 controller[:device] = File.basename(device).sub(/^cciss(\d+)$/, "/dev/cciss/c\\1d0")
359 elsif device = Dir.glob("/sys/bus/pci/devices/#{controller[:pci_slot]}/host*/target*:3:0/*:3:0:0/scsi_generic/sg*").first
360 controller[:device] = "/dev/#{File.basename(device)}"
361 elsif device = Dir.glob("/sys/bus/pci/devices/#{controller[:pci_slot]}/host*/target*:1:0/*:1:0:0/scsi_generic/sg*").first
362 controller[:device] = "/dev/#{File.basename(device)}"
367 def find_megaraid_disks(devices)
375 IO.popen(%w(megacli -AdpGetPciInfo -aAll -NoLog)).each do |line|
376 if line =~ /^PCI information for Controller (\d+)$/
378 :id => devices[:controllers].count,
383 devices[:controllers] << controller
385 controllers << controller
386 elsif line =~ /^Bus Number\s+:\s+(\d+)$/
387 controller[:pci_slot] = format "0000:%02x", Integer("0x#{Regexp.last_match(1)}")
388 elsif line =~ /^Device Number\s+:\s+(\d+)$/
389 controller[:pci_slot] = format "%s:%02x", controller[:pci_slot], Integer("0x#{Regexp.last_match(1)}")
390 elsif line =~ /^Function Number\s+:\s+(\d+)$/
391 controller[:pci_slot] = format "%s.%01x", controller[:pci_slot], Integer("0x#{Regexp.last_match(1)}")
395 IO.popen(%w(megacli -AdpAllInfo -aAll -NoLog)).each do |line|
396 if line =~ /^Adapter #(\d+)$/
397 controller = controllers[Regexp.last_match(1).to_i]
398 elsif line =~ /^(\S.*\S)\s*:\s+(\S.*)$/
399 case Regexp.last_match(1)
400 when "Product Name" then controller[:model] = Regexp.last_match(2)
401 when "Serial No" then controller[:serial_number] = Regexp.last_match(2)
402 when "FW Package Build" then controller[:firmware_version] = Regexp.last_match(2)
407 IO.popen(%w(megacli -LdPdInfo -aAll -NoLog)).each do |line|
408 if line =~ /^Adapter #(\d+)$/
409 controller = controllers[Regexp.last_match(1).to_i]
410 elsif controller && line =~ /^Virtual Drive: (\d+) \(Target Id: (\d+)\)$/
411 pci_slot = controller[:pci_slot]
412 target = Regexp.last_match(2)
413 device = Dir.glob("/sys/bus/pci/devices/#{pci_slot}/host*/target*:2:#{target}/*:2:#{target}:0/block/*").first
416 :id => devices[:arrays].count,
417 :controller => controller[:id],
418 :number => Regexp.last_match(1),
419 :device => "/dev/#{File.basename(device)}",
423 devices[:arrays] << array
424 controller[:arrays] << array[:id]
429 elsif array && line =~ /^PD: (\d+) Information$/
431 :id => devices[:disks].count,
432 :controller => controller[:id],
433 :arrays => [array[:id]]
436 devices[:disks] << disk
437 controller[:disks] << disk[:id]
438 array[:disks] << disk[:id]
439 elsif disk && line =~ /^Firmware state:\s+(.*\S)\s*$/
440 Regexp.last_match(1).split(/,\s*/).each do |state|
442 when "Online" then disk[:status] = "online"
443 when "Hotspare" then disk[:status] = "hotspare"
444 when "Spun Up" then disk[:spun_down] = false
445 when "Spun down" then disk[:spun_down] = true
448 elsif disk && line =~ /^(\S.*\S)\s*:\s+(\S.*)$/
449 case Regexp.last_match(1)
450 when "Device Id" then disk[:smart_device] = "megaraid,#{Regexp.last_match(2)}"
451 when "WWN" then disk[:wwn] = Regexp.last_match(2)
452 when "PD Type" then disk[:interface] = Regexp.last_match(2)
453 when "Raw Size" then disk[:size] = memory_to_disk_size(Regexp.last_match(2).sub(/\s*\[.*\]$/, ""))
454 when "Inquiry Data" then disk[:vendor], disk[:model], disk[:serial_number] = Regexp.last_match(2).split
456 elsif array && line =~ /^(\S.*\S)\s*:\s+(\S.*)$/
457 case Regexp.last_match(1)
458 when "RAID Level" then array[:raid_level] = Regexp.last_match(2).scan(/Primary-(\d+)/).first.first
459 when "Size" then array[:size] = Regexp.last_match(2)
464 IO.popen(%w(megacli -PDList -aAll -NoLog)).each do |line|
465 if line =~ /^Adapter #(\d+)$/
466 controller = controllers[Regexp.last_match(1).to_i]
467 elsif controller && line =~ /^Enclosure Device ID: \d+$/
469 :controller => controller[:id]
471 elsif disk && line =~ /^WWN:\s+(\S+)$/
472 unless devices[:disks].find { |d| d[:wwn] == Regexp.last_match(1) }
473 disk[:id] = devices[:disks].count
474 disk[:wwn] = Regexp.last_match(1)
476 devices[:disks] << disk
478 elsif disk && line =~ /^Firmware state:\s+(.*\S)\s*$/
479 Regexp.last_match(1).split(/,\s*/).each do |state|
481 when "Online" then disk[:status] = "online"
482 when "Hotspare" then disk[:status] = "hotspare"
483 when "Spun Up" then disk[:state] = "spun_up"
484 when "Spun down" then disk[:state] = "spun_down"
487 elsif disk && line =~ /^(\S.*\S)\s*:\s+(\S.*)$/
488 case Regexp.last_match(1)
489 when "Device Id" then disk[:smart_device] = "megaraid,#{Regexp.last_match(2)}"
490 when "PD Type" then disk[:interface] = Regexp.last_match(2)
491 when "Raw Size" then disk[:size] = memory_to_disk_size(Regexp.last_match(2).sub(/\s*\[.*\]$/, ""))
492 when "Inquiry Data" then disk[:vendor], disk[:model], disk[:serial_number] = Regexp.last_match(2).split
497 controllers.each do |controller|
498 if device = Dir.glob("/sys/bus/pci/devices/#{controller[:pci_slot]}/host*/target*:2:0/*/scsi_generic/sg*").first
499 controller[:device] = "/dev/#{File.basename(device)}"
504 def find_mpt_disks(devices)
507 IO.popen(%w(sas2ircu list)).each do |line|
508 next unless line =~ /^\s+(\d+)\s+(\S+)\s+\h+h\s+\h+h\s+(\S+)\s+\h+h\s+\h+h\s*$/
509 controllers[Regexp.last_match(1).to_i] = {
510 :id => devices[:controllers].count,
511 :model => Regexp.last_match(2),
512 :pci_slot => Regexp.last_match(3).sub(/^(\h{2})h:(\h{2})h:(\h{2})h:0(\h)h$/, "00\\1:\\2:\\3.\\4"),
517 devices[:controllers] << controllers[Regexp.last_match(1).to_i]
520 controllers.each_with_index do |controller, index|
527 IO.popen(["sas2ircu", index.to_s, "display"]).each do |line|
528 if line =~ /^IR volume (\d+)$/
530 :id => devices[:arrays].count,
531 :controller => controller[:id],
532 :number => Regexp.last_match(1),
536 devices[:arrays] << array
537 controller[:arrays] << array[:id]
540 elsif line =~ /^Device is a Hard disk$/
542 :id => devices[:disks].count,
543 :controller => controller[:id],
547 devices[:disks] << disk
548 controller[:disks] << disk[:id]
551 elsif disk && line =~ /^ (\S.*\S)\s+:\s+(.*\S)\s*$/
552 case Regexp.last_match(1)
553 when "Enclosure #" then disk[:location] = Regexp.last_match(2)
554 when "Slot #" then disk[:location] = "#{disk[:location]}:#{Regexp.last_match(2)}"
555 when "SAS Address" then disk[:device] = find_sas_device(Regexp.last_match(2).tr("-", ""))
556 when "Size (in MB)/(in sectors)" then disk[:size] = memory_to_disk_size("#{Regexp.last_match(2).split('/').first} MB")
557 when "Manufacturer" then disk[:vendor] = Regexp.last_match(2)
558 when "Model Number" then disk[:model] = Regexp.last_match(2)
559 when "Firmware Revision" then disk[:firmware_version] = Regexp.last_match(2)
560 when "Serial Number" then disk[:serial_number] = Regexp.last_match(2)
561 when "Protocol" then disk[:interface] = Regexp.last_match(2)
563 elsif array && line =~ /^ PHY\[\d+\] Enclosure#\/Slot#\s+:\s+(\d+:\d+)\s*$/
564 array[:disks] << Regexp.last_match(1)
565 elsif array && line =~ /^ (\S.*\S)\s+:\s+(.*\S)\s*$/
566 case Regexp.last_match(1)
567 when "Volume wwid" then array[:device] = find_sas_device(Regexp.last_match(2))
568 when "RAID level" then array[:raid_level] = Regexp.last_match(2).sub(/^RAID/, "")
569 when "Size (in MB)" then array[:size] = "#{Regexp.last_match(2)} MB"
571 elsif line =~ /^ (\S.*\S)\s+:\s+(.*\S)\s*$/
572 case Regexp.last_match(1)
573 when "BIOS version" then controller[:bios_version] = Regexp.last_match(2)
574 when "Firmware version" then controller[:firmware_version] = Regexp.last_match(2)
579 arrays.each do |array|
580 array[:disks].map! do |location|
581 disk = disks.find { |disk| disk[:location] == location }
583 disk[:arrays] << array[:id]
590 def find_adaptec_disks(devices)
591 controller_count = IO.popen(%w(arcconf getconfig 0)).first.scan(/^Controllers Found: (\d+)$/i).first.first.to_i
593 1.upto(controller_count).each do |controller_number|
595 :id => devices[:controllers].count,
596 :number => controller_number,
601 devices[:controllers] << controller
609 IO.popen(["arcconf", "getconfig", controller_number.to_s]).each do |line|
610 if line =~ /^Logical Device Number (\d+)$/i
612 :id => devices[:arrays].count,
613 :controller => controller[:id],
614 :number => Regexp.last_match(1).to_i,
618 devices[:arrays] << array
619 controller[:arrays] << array[:id]
622 elsif line =~ /^ Device #(\d+)$/
624 elsif line =~ /^ Device is a Hard drive$/
626 :id => devices[:disks].count,
627 :controller => controller[:id],
631 devices[:disks] << disk
632 controller[:disks] << disk[:id]
635 elsif disk && line =~ /^ Reported Channel,Device\(T:L\)\s*:\s+(\d+),(\d+)\(\d+:0\)\s*$/
636 disk[:channel_number] = Regexp.last_match(1)
637 disk[:device_number] = Regexp.last_match(2)
638 elsif disk && line =~ /^ (\S.*\S)\s*:\s+(\S.*\S)\s*$/
639 case Regexp.last_match(1)
640 when "Reported Location" then disk[:location] = Regexp.last_match(2)
641 when "Vendor" then disk[:vendor] = Regexp.last_match(2)
642 when "Model" then disk[:model] = Regexp.last_match(2)
643 when "Firmware" then disk[:firmware_version] = Regexp.last_match(2)
644 when "Serial number" then disk[:serial_number] = Regexp.last_match(2)
645 when "Serial Number" then disk[:serial_number] = Regexp.last_match(2)
646 when "World-wide name" then disk[:wwn] = Regexp.last_match(2)
647 when "World-wide Name" then disk[:wwn] = Regexp.last_match(2)
648 when "Total Size" then disk[:size] = memory_to_disk_size(Regexp.last_match(2))
649 when "Size" then disk[:size] = memory_to_disk_size(Regexp.last_match(2))
651 elsif array && line =~ / Present \(.*((?:Connector|Enclosure):\d+,\s*(?:Device|Slot):\d+)\) /
652 array[:disks] << Regexp.last_match(1).tr(":", " ").gsub(/,\s*/, ", ")
653 elsif array && line =~ /^ (\S.*\S)\s*:\s+(\S.*\S)\s*$/
654 case Regexp.last_match(1)
655 when "RAID level" then array[:raid_level] = Regexp.last_match(2)
656 when "RAID Level" then array[:raid_level] = Regexp.last_match(2)
657 when "Size" then array[:size] = memory_to_disk_size(Regexp.last_match(2))
659 elsif line =~ /^ (\S.*\S)\s*:\s+(\S.*\S)\s*$/
660 case Regexp.last_match(1)
661 when "Controller Model" then controller[:model] = Regexp.last_match(2)
662 when "Controller Serial Number" then controller[:serial_number] = Regexp.last_match(2)
663 when "Controller World Wide Name" then controller[:wwn] = Regexp.last_match(2)
664 when "BIOS" then controller[:bios_version] = Regexp.last_match(2)
665 when "Firmware" then controller[:firmware_version] = Regexp.last_match(2)
667 elsif line =~ /^ Serial Number\s*:\s+(\S.*\S)\s*$/
668 controller[:serial_number] = Regexp.last_match(1)
672 host = Dir.glob("/sys/class/scsi_host/host*").find do |host|
673 read_sysctl_file("#{host}/serial_number") == controller[:serial_number]
676 arrays.each do |array|
677 array_number = array[:number]
678 device = Dir.glob("#{host}/device/target*:0:#{array_number}/*:0:#{array_number}:0/block/*").first
680 array[:device] = "/dev/#{File.basename(device)}"
682 array[:disks].map! do |location|
683 disk = disks.find { |disk| disk[:location] == location }
685 device_number = disk[:device_number]
686 device = Dir.glob("#{host}/device/target*:1:#{device_number}/*:1:#{device_number}:0/scsi_generic/*").first
688 disk[:device] = "/dev/#{File.basename(device)}"
690 disk[:arrays] << array[:id]
697 def find_areca_disks(devices)
699 :id => devices[:controllers].count,
704 devices[:controllers] << controller
706 IO.popen(%w(/opt/areca/x86_64/cli64 sys info)).each do |line|
707 next unless line =~ /^(\S.*\S)\s+:\s+(.*\S)\s*$/
709 case Regexp.last_match(1)
710 when "Firmware Version" then controller[:firmware_version] = Regexp.last_match(2)
711 when "BOOT ROM Version" then controller[:bios_version] = Regexp.last_match(2)
712 when "Serial Number" then controller[:serial_number] = Regexp.last_match(2)
713 when "Controller Name" then controller[:model] = Regexp.last_match(2)
717 path = Dir.glob("/sys/bus/pci/devices/*/host*/scsi_host/host*/host_fw_model").find do |file|
718 read_sysctl_file(file) == controller[:model]
721 controller[:pci_slot] = File.basename(File.expand_path("#{path}/../../../.."))
722 controller[:device] = File.basename(Dir.glob(File.expand_path("#{path}/../../../target0:0:16/0:0:16:0/scsi_generic/*")).first)
726 IO.popen(%w(/opt/areca/x86_64/cli64 vsf info)).each do |line|
727 next unless line =~ /^\s+(\d+)\s+/
729 :id => devices[:arrays].count,
730 :number => Regexp.last_match(1),
731 :controller => controller[:id],
735 devices[:arrays] << array
736 controller[:arrays] << array[:id]
741 arrays.each do |array|
742 IO.popen(["/opt/areca/x86_64/cli64", "vsf", "info", "vol=#{array[:number]}"]).each do |line|
743 if line =~ /^SCSI Ch\/Id\/Lun\s+:\s+(\d+)\/(\d+)\/(\d+)\s*$/
744 pci_slot = controller[:pci_slot]
745 channel = Regexp.last_match(1).to_i
746 id = Regexp.last_match(2).to_i
747 lun = Regexp.last_match(3).to_i
749 device = Dir.glob("/sys/bus/pci/devices/#{pci_slot}/host*/target*:0:0/0:#{channel}:#{id}:#{lun}/block/*").first
751 array[:device] = "/dev/#{File.basename(device)}"
752 elsif line =~ /^(\S.*\S)\s+:\s+(.*\S)\s*$/
753 case Regexp.last_match(1)
754 when "Volume Set Name" then array[:volume_set] = Regexp.last_match(2)
755 when "Raid Set Name" then array[:raid_set] = Regexp.last_match(2)
756 when "Volume Capacity" then array[:size] = format_disk_size(Regexp.last_match(2).to_f * 1000 * 1000)
757 when "Raid Level" then array[:raid_level] = Regexp.last_match(2).sub(/^Raid/, "")
765 IO.popen(%w(/opt/areca/x86_64/cli64 disk info)).each do |line|
766 next unless line =~ /^\s+(\d+)\s+.*\s+\d+\.\d+GB\s+(\S.*\S)\s*$/
767 next if Regexp.last_match(2) == "N.A."
770 :id => devices[:disks].count,
771 :number => Regexp.last_match(1),
772 :controller => controller[:id],
776 devices[:disks] << disk
777 controller[:disks] << disk[:id]
779 if array = arrays.find { |array| array[:raid_set] == Regexp.last_match(2) }
780 disk[:arrays] << array[:id]
781 array[:disks] << disk[:id]
788 IO.popen(["/opt/areca/x86_64/cli64", "disk", "info", "drv=#{disk[:number]}"]).each do |line|
789 if line =~ /^IDE Channel\s+:\s+(\d+)\s*$/i
790 disk[:smart_device] = "areca,#{Regexp.last_match(1)}"
791 elsif line =~ /^Device Location\s+:\s+Enclosure#(\d+) Slot#?\s*0*(\d+)\s*$/i
792 disk[:smart_device] = "areca,#{Regexp.last_match(2)}/#{Regexp.last_match(1)}"
793 elsif line =~ /^(\S.*\S)\s+:\s+(.*\S)\s*$/
794 case Regexp.last_match(1)
795 when "Model Name" then disk[:vendor], disk[:model] = Regexp.last_match(2).split
796 when "Serial Number" then disk[:serial_number] = Regexp.last_match(2)
797 when "Disk Capacity" then disk[:size] = format_disk_size(Regexp.last_match(2).to_f * 1000 * 1000)
806 :pvs => find_lvm_pvs,
807 :vgs => find_lvm_vgs,
813 IO.popen(["pvdisplay", "-c"]).each_with_object({}) do |line, pvs|
814 fields = line.strip.split(":")
818 :pv_size => fields[2],
819 :pv_status => fields[4],
820 :pe_size => fields[7],
821 :pe_total => fields[8],
822 :pe_free => fields[9],
823 :pe_allocated => fields[10],
824 :pv_uuid => fields[11]
830 IO.popen(["vgdisplay", "-c"]).each_with_object({}) do |line, vgs|
831 fields = line.strip.split(":")
834 :vg_access => fields[1],
835 :vg_status => fields[2],
836 :lv_maximum => fields[4],
837 :lv_count => fields[5],
838 :lv_open => fields[6],
839 :pv_maximum => fields[8],
840 :pv_current => fields[9],
841 :pv_actual => fields[10],
842 :vg_size => fields[11],
843 :pe_size => fields[12],
844 :pe_total => fields[13],
845 :pe_allocated => fields[14],
846 :pe_free => fields[15],
847 :vg_uuid => fields[16]
853 IO.popen(["lvdisplay", "-c"]).each_with_object({}) do |line, lvs|
854 fields = line.strip.split(":")
858 :lv_access => fields[2],
859 :lv_status => fields[3],
860 :lv_open => fields[5],
861 :lv_size => fields[6],
862 :le_count => fields[7],
863 :lv_minor => fields[11],
864 :lv_major => fields[12]
872 IO.popen(["dmidecode", "-t", "39"]).each_with_object([]) do |line, devices|
873 if line =~ /^System Power Supply\s*$/
875 elsif device && line =~ /^\s+([A-Z ]+):\s+(.*)\s*$/i
876 device[Regexp.last_match(1).tr(" ", "_").downcase.to_sym] = Regexp.last_match(2).strip
877 elsif device && line =~ /^\s*$/
887 IO.popen(["ipmitool", "mc", "info"]).each_with_object([]) do |line, devices|
888 if line =~ /(Manufacturer [A-Z ]+[A-Z])\s*:\s+(.*\S)\s+\(.*\)\s*$/i
889 device[Regexp.last_match(1).tr(" ", "_").downcase.to_sym] = Regexp.last_match(2)
890 elsif line =~ /(Product [A-Z ]+[A-Z])\s*:\s+(.*\S)\s+\(.*\)\s*$/i
891 device[Regexp.last_match(1).tr(" ", "_").downcase.to_sym] = Regexp.last_match(2)
892 elsif line =~ /([A-Z ]+[A-Z])\s*:\s+(.*\S)\s*$/i
893 device[Regexp.last_match(1).tr(" ", "_").downcase.to_sym] = Regexp.last_match(2)
897 IO.popen(["ipmitool", "mc", "guid"]).each_with_object([]) do |line, devices|
898 if line =~ /^System GUID\s*:\s+(\S+)\s*$/
899 device[:system_guid] = Regexp.last_match(1)
906 collect_data(:default) do
909 hardware[:pci] = pci_devices
910 hardware[:network] = network_devices
911 hardware[:memory] = memory_devices
912 hardware[:disk] = disk_devices
913 hardware[:lvm] = lvm_devices
914 hardware[:psu] = psu_devices
915 hardware[:mc] = mc_device