From: Tom Hughes Date: Sun, 2 Sep 2018 21:33:36 +0000 (+0100) Subject: Make disk monitoring more robust X-Git-Url: https://git.openstreetmap.org/chef.git/commitdiff_plain/535456508231fd5fd5e4c3d6671cb7a018b39771 Make disk monitoring more robust --- diff --git a/cookbooks/hardware/recipes/default.rb b/cookbooks/hardware/recipes/default.rb index 5dda7409a..1a9549d7c 100644 --- a/cookbooks/hardware/recipes/default.rb +++ b/cookbooks/hardware/recipes/default.rb @@ -358,16 +358,19 @@ disks = disks.map do |disk| if disk[:smart_device] controller = node[:hardware][:disk][:controllers][disk[:controller]] - device = controller[:device].sub("/dev/", "") - smart = disk[:smart_device] - - if device.start_with?("cciss/") && smart =~ /^cciss,(\d+)$/ - array = node[:hardware][:disk][:arrays][disk[:arrays].first] - munin = "cciss-3#{array[:wwn]}-#{Regexp.last_match(1)}" - elsif smart =~ /^.*,(\d+)$/ - munin = "#{device}-#{Regexp.last_match(1)}" - elsif smart =~ %r{^.*,(\d+)/(\d+)$} - munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}" + + if controller && controller[:device] + device = controller[:device].sub("/dev/", "") + smart = disk[:smart_device] + + if device.start_with?("cciss/") && smart =~ /^cciss,(\d+)$/ + array = node[:hardware][:disk][:arrays][disk[:arrays].first] + munin = "cciss-3#{array[:wwn]}-#{Regexp.last_match(1)}" + elsif smart =~ /^.*,(\d+)$/ + munin = "#{device}-#{Regexp.last_match(1)}" + elsif smart =~ %r{^.*,(\d+)/(\d+)$} + munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}" + end end elsif disk[:device] device = disk[:device].sub("/dev/", "")