+package "haveged"
+service "haveged" do
+ action [:enable, :start]
+end
+
+if node[:kernel][:modules].include?("ipmi_si")
+ package "ipmitool"
+ package "freeipmi-tools"
+
+ template "/etc/prometheus/ipmi_local.yml" do
+ source "ipmi_local.yml.erb"
+ owner "root"
+ group "root"
+ mode "644"
+ end
+
+ prometheus_exporter "ipmi" do
+ port 9290
+ options "--config.file=/etc/prometheus/ipmi_local.yml"
+ subscribes :restart, "template[/etc/prometheus/ipmi_local.yml]"
+ end
+end
+
+package "irqbalance"
+
+service "irqbalance" do
+ action [:start, :enable]
+ supports :status => false, :restart => true, :reload => false
+end
+
+package "lldpd"
+
+service "lldpd" do
+ action [:start, :enable]
+ supports :status => true, :restart => true, :reload => true
+end
+
+ohai_plugin "lldp" do
+ template "lldp.rb.erb"
+end
+
+tools_packages = []
+status_packages = {}
+
+if node[:virtualization][:role] != "guest" ||
+ (node[:virtualization][:system] != "lxc" &&
+ node[:virtualization][:system] != "lxd" &&
+ node[:virtualization][:system] != "openvz")
+
+ node[:kernel][:modules].each_key do |modname|
+ case modname
+ when "cciss"
+ tools_packages << "ssacli"
+ status_packages["cciss-vol-status"] ||= []
+ when "hpsa"
+ tools_packages << "ssacli"
+ status_packages["cciss-vol-status"] ||= []
+ when "mptsas"
+ tools_packages << "lsiutil"
+ status_packages["mpt-status"] ||= []
+ when "mpt2sas", "mpt3sas"
+ tools_packages << "sas2ircu"
+ status_packages["sas2ircu-status"] ||= []
+ when "megaraid_mm"
+ tools_packages << "megactl"
+ status_packages["megaraid-status"] ||= []
+ when "megaraid_sas"
+ tools_packages << "megacli"
+ status_packages["megaclisas-status"] ||= []
+ when "aacraid"
+ tools_packages << "arcconf"
+ status_packages["aacraid-status"] ||= []
+ when "arcmsr"
+ tools_packages << "areca"
+ end
+ end
+
+ node[:block_device].each do |name, attributes|
+ next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
+
+ if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
+ status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
+ else
+ Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
+ status_packages["cciss-vol-status"] |= [File.basename(sg)]
+ end
+ end
+ end
+end
+
+%w[ssacli lsiutil sas2ircu megactl megacli arcconf].each do |tools_package|
+ if tools_packages.include?(tools_package)
+ package tools_package
+ else
+ package tools_package do
+ action :purge
+ end
+ end
+end
+
+if tools_packages.include?("areca")
+ include_recipe "git"
+
+ git "/opt/areca" do
+ action :sync
+ repository "https://git.openstreetmap.org/private/areca.git"
+ depth 1
+ user "root"
+ group "root"
+ not_if { kitchen? }
+ end
+else
+ directory "/opt/areca" do
+ action :delete
+ recursive true
+ end
+end
+
+if status_packages.include?("cciss-vol-status")
+ template "/usr/local/bin/cciss-vol-statusd" do
+ source "cciss-vol-statusd.erb"
+ owner "root"
+ group "root"
+ mode "755"
+ notifies :restart, "service[cciss-vol-statusd]"
+ end
+
+ systemd_service "cciss-vol-statusd" do
+ description "Check cciss_vol_status values in the background"
+ exec_start "/usr/local/bin/cciss-vol-statusd"
+ private_tmp true
+ protect_system "full"
+ protect_home true
+ no_new_privileges true
+ notifies :restart, "service[cciss-vol-statusd]"
+ end
+else
+ systemd_service "cciss-vol-statusd" do
+ action :delete
+ end
+
+ template "/usr/local/bin/cciss-vol-statusd" do
+ action :delete
+ end
+end
+
+%w[cciss-vol-status mpt-status sas2ircu-status megaraid-status megaclisas-status aacraid-status].each do |status_package|
+ if status_packages.include?(status_package)
+ package status_package
+
+ template "/etc/default/#{status_package}d" do
+ source "raid.default.erb"
+ owner "root"
+ group "root"
+ mode "644"
+ variables :devices => status_packages[status_package]
+ end
+
+ service "#{status_package}d" do
+ action [:start, :enable]
+ supports :status => false, :restart => true, :reload => false
+ subscribes :restart, "template[/etc/default/#{status_package}d]"
+ end
+ else
+ package status_package do
+ action :purge
+ end
+
+ file "/etc/default/#{status_package}d" do
+ action :delete
+ end
+ end
+end
+
+disks = if node[:hardware][:disk]
+ node[:hardware][:disk][:disks]
+ else
+ []
+ end
+
+intel_ssds = disks.select { |d| d[:vendor] == "INTEL" && d[:model] =~ /^SSD/ }
+
+nvmes = if node[:hardware][:pci]
+ node[:hardware][:pci].values.select { |pci| pci[:driver] == "nvme" }
+ else
+ []
+ end
+
+unless nvmes.empty?
+ package "nvme-cli"
+end
+
+intel_nvmes = nvmes.select { |pci| pci[:vendor_name] == "Intel Corporation" }
+
+if !intel_ssds.empty? || !intel_nvmes.empty?
+ package "unzip"
+
+ intel_mas_tool_version = "1.10"
+ intel_mas_package_version = "#{intel_mas_tool_version}.155-0"
+
+ remote_file "#{Chef::Config[:file_cache_path]}/Intel_MAS_CLI_Tool_#{intel_mas_tool_version}_Linux.zip" do
+ source "https://downloadmirror.intel.com/646992/Intel_MAS_CLI_Tool_Linux_#{intel_mas_tool_version}-v2.zip"
+ end
+
+ execute "#{Chef::Config[:file_cache_path]}/Intel_MAS_CLI_Tool_#{intel_mas_tool_version}_Linux.zip" do
+ command "unzip Intel_MAS_CLI_Tool_#{intel_mas_tool_version}_Linux.zip intelmas_#{intel_mas_package_version}_amd64.deb"
+ cwd Chef::Config[:file_cache_path]
+ user "root"
+ group "root"
+ not_if { ::File.exist?("#{Chef::Config[:file_cache_path]}/intelmas_#{intel_mas_package_version}_amd64.deb") }
+ end
+
+ dpkg_package "intelmas" do
+ version "#{intel_mas_package_version}"
+ source "#{Chef::Config[:file_cache_path]}/intelmas_#{intel_mas_package_version}_amd64.deb"
+ end
+
+ dpkg_package "isdct" do
+ action :purge
+ end
+end
+
+disks = disks.map do |disk|
+ next if disk[:state] == "spun_down" || %w[unconfigured failed].any?(disk[:status])
+
+ if disk[:smart_device]
+ controller = node[:hardware][:disk][:controllers][disk[:controller]]
+
+ 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
+ elsif disk[:device]
+ device = disk[:device].sub("/dev/", "")
+ smart = disk[:smart_device]
+
+ if smart =~ /^.*,(\d+),(\d+),(\d+)$/
+ munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}:#{Regexp.last_match(3)}"
+ end
+ end
+ elsif disk[:device] =~ %r{^/dev/(nvme\d+)n\d+$}
+ device = Regexp.last_match(1)
+ munin = device
+ elsif disk[:device]
+ device = disk[:device].sub("/dev/", "")
+ munin = device
+ end
+
+ next if device.nil?
+
+ Hash[
+ :device => device,
+ :smart => smart,
+ :munin => munin,
+ :hddtemp => munin.tr("-:", "_")
+ ]