Update smart related munin plugins to handle all disks
authorTom Hughes <tom@compton.nu>
Fri, 13 Mar 2015 22:52:25 +0000 (22:52 +0000)
committerTom Hughes <tom@compton.nu>
Sat, 14 Mar 2015 00:16:17 +0000 (00:16 +0000)
cookbooks/hardware/recipes/default.rb
cookbooks/hardware/templates/default/munin.hddtemp.erb [new file with mode: 0644]
cookbooks/hardware/templates/default/munin.smart.erb [new file with mode: 0644]
cookbooks/munin/recipes/default.rb
cookbooks/munin/templates/default/hddtemp.erb [deleted file]
cookbooks/munin/templates/default/smart.erb [deleted file]

index 8655780367c2c5e332abfb6ce9c5f1513222851f..29a1fcd1eb3d2ce35a00cc76fe2a6573fbb58a93 100644 (file)
@@ -353,6 +353,22 @@ if tools_packages.include?("areca")
   end
 end
 
+disks.each do |disk|
+  if disk[:device] =~ /^cciss\/(.*)$/
+    id = File.read("/sys/bus/cciss/devices/#{Regexp.last_match[1]}/unique_id").chomp
+
+    disk[:munin] = "cciss-3#{id.downcase}"
+  else
+    disk[:munin] = disk[:device]
+  end
+
+  if disk[:id]
+    disk[:munin] = "#{disk[:munin]}-#{disk[:id].to_s.tr('/', ':')}"
+  end
+
+  disk[:hddtemp] = disk[:munin].tr("-:", "_")
+end
+
 if disks.count > 0
   package "smartmontools"
 
@@ -376,10 +392,36 @@ if disks.count > 0
   service "smartmontools" do
     action [:enable, :start]
   end
+
+  disks.each do |disk|
+    munin_plugin "smart_#{disk[:munin]}" do
+      target "smart_"
+      conf "munin.smart.erb"
+      conf_variables :disk => disk
+    end
+  end
+
+  munin_plugin "hddtemp_smartctl" do
+    conf "munin.hddtemp.erb"
+    conf_variables :disks => disks
+  end
 else
   service "smartmontools" do
     action [:stop, :disable]
   end
+
+  munin_plugin "hddtemp_smartctl" do
+    action :delete
+  end
+end
+
+plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } -
+          disks.map { |d| "smart_#{d[:munin_name]}" }
+
+plugins.each do |plugin|
+  munin_plugin plugin do
+    action :delete
+  end
 end
 
 if File.exist?("/etc/mdadm/mdadm.conf")
diff --git a/cookbooks/hardware/templates/default/munin.hddtemp.erb b/cookbooks/hardware/templates/default/munin.hddtemp.erb
new file mode 100644 (file)
index 0000000..330be06
--- /dev/null
@@ -0,0 +1,10 @@
+# DO NOT EDIT - This file is being maintained by Chef
+
+[hddtemp_smartctl]
+env.drives <%= @disks.map { |d| d[:hddtemp] }.sort.join(" ") %>
+<% @disks.sort_by { |d| d[:hddtemp] }.each do |disk| -%>
+<% if disk[:driver] -%>
+env.type_<%= disk[:hddtemp] %> <%= disk[:driver] %>,<%= disk[:id] %>
+<% end -%>
+env.dev_<%= disk[:hddtemp] %> <%= disk[:device] %>
+<% end -%>
diff --git a/cookbooks/hardware/templates/default/munin.smart.erb b/cookbooks/hardware/templates/default/munin.smart.erb
new file mode 100644 (file)
index 0000000..8a09c83
--- /dev/null
@@ -0,0 +1,8 @@
+# DO NOT EDIT - This file is being maintained by Chef
+
+[smart_<%= @disk[:munin] %>]
+<% if @disk[:driver] -%>
+env.smartargs -H -d <%= @disk[:driver] %>,<%= @disk[:id] %>
+<% else -%>
+env.smartargs -H
+<% end -%>
index 28c05006b0dad7a7404581f4f3875fe19e92ef48..36ddd96b44e0997439d5dd7b6ff77d5a0c22b4ad 100644 (file)
@@ -125,21 +125,6 @@ else
   end
 end
 
-disks = node[:block_device].select do |_, attributes|
-  ["ATA", "FUJITSU", "SEAGATE", "DELL", "COMPAQ", "IBM-ESXS"].include?(attributes[:vendor])
-end
-
-if disks.empty?
-  munin_plugin "hddtemp_smartctl" do
-    action :delete
-  end
-else
-  munin_plugin "hddtemp_smartctl" do
-    conf "hddtemp.erb"
-    conf_variables :disks => disks
-  end
-end
-
 if File.exist?("/sbin/hpasmcli")
   munin_plugin "hpasmcli2_temp" do
     target "hpasmcli2_"
@@ -317,20 +302,6 @@ else
   end
 end
 
-node[:block_device].each do |name, attributes|
-  if attributes[:vendor] == "ATA"
-    munin_plugin "smart_#{name}" do
-      target "smart_"
-      conf "smart.erb"
-      conf_variables :disk => name
-    end
-  else
-    munin_plugin "smart_#{name}" do
-      action :delete
-    end
-  end
-end
-
 munin_plugin "swap"
 munin_plugin "tcp"
 munin_plugin "threads"
diff --git a/cookbooks/munin/templates/default/hddtemp.erb b/cookbooks/munin/templates/default/hddtemp.erb
deleted file mode 100644 (file)
index 36a8bb5..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-# DO NOT EDIT - This file is being maintained by Chef
-
-[hddtemp_smartctl]
-env.drives <%= @disks.keys.sort.join(" ") %>
diff --git a/cookbooks/munin/templates/default/smart.erb b/cookbooks/munin/templates/default/smart.erb
deleted file mode 100644 (file)
index bcb813a..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-# DO NOT EDIT - This file is being maintained by Chef
-
-[smart_<%= @disk %>]
-env.smartargs -H