]> git.openstreetmap.org Git - chef.git/commitdiff
Make disk monitoring more robust
authorTom Hughes <tom@compton.nu>
Sun, 2 Sep 2018 21:33:36 +0000 (22:33 +0100)
committerTom Hughes <tom@compton.nu>
Sun, 2 Sep 2018 21:34:28 +0000 (22:34 +0100)
cookbooks/hardware/recipes/default.rb

index 5dda7409a164d251458f0b63f5bc6e3dc43bfd99..1a9549d7cd663bcaacbe4f09a74169038df5ca83 100644 (file)
@@ -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/", "")