forked from jhoblitt/puppet-smartd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit c3aee00
Showing
5 changed files
with
240 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
Copyright 2012 Massachusetts Institute of Technology | ||
|
||
Permission to use, copy, modify, and distribute this software and | ||
its documentation for any purpose and without fee is hereby | ||
granted, provided that both the above copyright notice and this | ||
permission notice appear in all copies, that both the above | ||
copyright notice and this permission notice appear in all | ||
supporting documentation, and that the name of M.I.T. not be used | ||
in advertising or publicity pertaining to distribution of the | ||
software without specific, written prior permission. M.I.T. makes | ||
no representations about the suitability of this software for any | ||
purpose. It is provided "as is" without express or implied | ||
warranty. | ||
|
||
THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS | ||
ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, | ||
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | ||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT | ||
SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | ||
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | ||
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# Figure out if this machine has AMI/LSI MegaRAID aka Dell PERC | ||
# storage controllers, and if so, how many physical disks are | ||
# attached. Currently implemented only on Linux because none of | ||
# our FreeBSD machines use these controllers, so I don't have an | ||
# example "mfiutil show config" to write a parser for and test | ||
# against. | ||
def megacli_usable? | ||
(File.writable?('/dev/megaraid_sas_ioctl_node') or | ||
File.writable?('/dev/megadev0')) and | ||
Facter::Util::Resolution.which('MegaCli') | ||
end | ||
|
||
Facter.add(:megaraid_physical_drives) do | ||
confine :kernel => [ :Linux ] | ||
setcode do | ||
pds = [] | ||
if megacli_usable? | ||
list = Facter::Util::Resolution.exec('MegaCli -PDList -aALL') | ||
list.each_line do |line| | ||
if line =~ /^Device Id:\s+(\d+)/ | ||
pds.push($1) | ||
end | ||
end | ||
end | ||
pds.join(",") | ||
end | ||
end | ||
|
||
Facter.add(:megaraid_adapters) do | ||
confine :kernel => [ :Linux ] | ||
setcode do | ||
if megacli_usable? | ||
count = Facter::Util::Resolution.exec('MegaCli -adpCount 2>&1') | ||
count =~ /Controller Count:\s+(\d+)\./ ? $1 : '0' | ||
else | ||
nil | ||
end | ||
end | ||
end | ||
|
||
# Try to figure out what should be used as the "device" parameter | ||
# for smartd. On FreeBSD it's simple, just use /dev/mfi%d, but | ||
# on Linux we have to find a block device that corresponds to a | ||
# *logical* drive on the controller. Any logical drive will do, | ||
# so long as it's on the same controller. We only support one | ||
# controller for now. If smartmontools is not already installed, | ||
# it will take two Puppet runs to determine this. | ||
Facter.add(:megaraid_smartd_device_name) do | ||
confine :kernel => [ :Linux ] | ||
setcode do | ||
device = nil | ||
if smartctl = Facter::Util::Resolution.which('smartctl') | ||
out = Facter::Util::Resolution.exec(smartctl + ' --scan-open 2>&1') | ||
out.each_line do |line| | ||
if line =~ /open failed: DELL or MegaRaid controller/ | ||
device = (line.split(/\s+/))[0] | ||
end | ||
end | ||
end | ||
device | ||
end | ||
end | ||
|
||
# If this were implemented on FreeBSD, you would have two separate | ||
# implementations: one that uses MegaCli (possibly under Linux emulation) | ||
# for amr(4) controllers, and one that uses mfiutil(8) for mfi(4) | ||
# controllers. | ||
#Facter.add(:megaraid_physical_drives) do | ||
# confine :kernel => [ :FreeBSD ] | ||
# setcode do | ||
# pds = [] | ||
# mfiutil = Facter::Util::Resolution.which('mfiutil') | ||
# if File.writable?('/dev/mfi0') and mfiutil | ||
# list = Facter::Util::Resolution.exec(mfiutil + ' show config' | ||
# # do something here | ||
# end | ||
# pds.join(",") | ||
# end | ||
#end | ||
|
||
Facter.add(:megaraid_adapters) do | ||
confine :kernel => [ :FreeBSD ] | ||
setcode do | ||
Dir.glob('/dev/mfi[0-9]*').size + Dir.glob('/dev/amr[0-9]*').size | ||
end | ||
end | ||
|
||
# I don't know if smartmontools even supports talking to this | ||
# interface, but assume that it works like HPTRR and similar | ||
# hardware RAID controllers. Only one controller is supported. | ||
Facter.add(:megaraid_smartd_device_name) do | ||
confine :kernel => [ :FreeBSD ] | ||
setcode do | ||
(Dir.glob('/dev/mfi[0-9]*') + Dir.glob('/dev/amr[0-9]*'))[0] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class smartd::defaults { | ||
$autoupdate = false | ||
$package_name = 'smartmontools' | ||
$service_name = 'smartd' | ||
$scan = true | ||
$devices = [] | ||
$device_opts = {} | ||
$mail_to = 'root' | ||
$schedule = 'daily' # other choices: once, diminishing | ||
|
||
case $::osfamily { | ||
'FreeBSD': { | ||
$config_file = '/usr/local/etc/smartd.conf' | ||
} | ||
'Debian': { | ||
$config_file = '/etc/smartd.conf' | ||
} | ||
default: { fail("smartd: unsupported OS family ${::osfamily}}") } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
class smartd ($ensure = 'present', | ||
$autoupdate = $smartd::defaults::autoupdate, | ||
$package_name = $smartd::defaults::package_name, | ||
$service_name = $smartd::defaults::service_name, | ||
$config_file = $smartd::defaults::config_file, | ||
$scan = $smartd::defaults::scan, | ||
$devices = $smartd::defaults::devices, | ||
$device_opts = $smartd::defaults::device_opts, | ||
$mail_to = $smartd::defaults::mail_to, | ||
$schedule = $smartd::defaults::schedule, | ||
) inherits smartd::defaults { | ||
case $ensure { | ||
'present': { | ||
if $autoupdate { | ||
$pkg_ensure = 'latest' | ||
} else { | ||
$pkg_ensure = 'present' | ||
} | ||
$svc_ensure = 'running' | ||
$svc_enable = true | ||
$file_ensure = 'present' | ||
} | ||
'absent': { | ||
$pkg_ensure = 'absent' | ||
$svc_ensure = 'stopped' | ||
$svc_enable = false | ||
$file_ensure = 'absent' | ||
} | ||
'purged': { | ||
$pkg_ensure = 'purged' | ||
$svc_ensure = 'stopped' | ||
$svc_enable = false | ||
$file_ensure = 'absent' | ||
} | ||
} | ||
|
||
package {$package_name: | ||
ensure => $pkg_ensure, | ||
} -> service {$service_name: | ||
ensure => $svc_ensure, | ||
enable => $svc_enable, | ||
hasrestart => true, | ||
} | ||
|
||
file {$config_file: | ||
ensure => $file_present, | ||
owner => root, | ||
group => 0, | ||
mode => 0644, | ||
content => template('smartd/smartd.conf'), | ||
require => Package[$package_name], | ||
before => Service[$service_name], | ||
} | ||
|
||
# Special sauce for Debian where it's not enough for the rc script | ||
# to be enabled, it also needs its own extra special config file. | ||
if $::osfamily == 'Debian' { | ||
shell_config {'start_smartd': | ||
file => '/etc/default/smartmontools', | ||
key => 'start_smartd', | ||
value => 'yes', | ||
ensure => $file_ensure, | ||
before => Service[$service_name], | ||
} | ||
} | ||
|
||
# Let monit monitor smartd, if configured. | ||
@monit::monitor {$service_name: | ||
pidfile => "/var/run/${service_name}.pid", | ||
ensure => $file_present, | ||
tag => 'default', | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Managed by Puppet -- do not edit! | ||
DEFAULT -m <%= @mail_to %> -M <%= @schedule %> | ||
<% if @scan -%> | ||
DEVICESCAN | ||
<% end -%> | ||
<% @devices.each do |device| -%> | ||
<%= device -%> | ||
<% if @device_opts.has_key?(device) -%> | ||
<%= @device_opts[device] -%> | ||
<% end #newline here, please %> | ||
<% end -%> | ||
<% megaraid_adapters = scope.lookupvar('::megaraid_adapters') | ||
megaraid_device = scope.lookupvar('::megaraid_smartd_device_name') | ||
megaraid_drives = scope.lookupvar('::megaraid_physical_drives') | ||
megaraid_drives = megaraid_drives.nil? ? [] : megaraid_drives.split(/,/) | ||
|
||
if megaraid_device and megaraid_device != '' and | ||
megaraid_adapters and megaraid_adapters.to_i > 0 -%> | ||
<% megaraid_drives.each do |drive| -%> | ||
<%= megaraid_device %> -d megaraid,<%= megaraid_drives.to_i -%> | ||
<% if @device_opts.has_key?('megaraid') -%> | ||
<%= @device_opts['megaraid'] -%> | ||
<% end #newline here, please %> | ||
<% end -%> | ||
<% end -%> |