Created
November 22, 2013 21:12
-
-
Save solarkennedy/7606943 to your computer and use it in GitHub Desktop.
A puppet function to try to programmatically monitor smart disks
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
newfunction(:smartd_guess, :type => :rvalue, :doc => | |
'smartd_guess tries to guess which block devices are available for smart | |
monitoring, and which should be ignored. | |
It iterates through the $::blockdevices fact, and returns an ARRAY of HASHES | |
compatible with the jhoblitt smartd module: | |
https://github.com/jhoblitt/puppet-smartd#devices | |
This function exists because smartd AUTOSCAN is too dumb, and manually | |
specifying smartd configs on a per server basis is not web-scale. | |
') do |args| | |
devices_guess = [] | |
# We start smart tests at 2AM | |
hour_counter=2 | |
for device in lookupvar('blockdevices').split(",").sort() do | |
next if not device.match('^sd') | |
# According to the smartd.conf man page, HOUR must be double digit, 00-23 | |
hour = '%02d' % hour_counter | |
smartd_device_hash = { 'device' => "/dev/#{device}" } | |
vendor = lookupvar("blockdevice_#{device}_vendor") | |
case vendor | |
when 'ATA' | |
# Ata devices need smart on. ATA really implies sat now that we are in 2013? | |
smartd_device_hash['options']="-a -d sat -s (S/../../[1-6]/#{hour}|L/../../7/#{hour})" | |
when 'SEAGATE', 'FUJITSU' | |
# When a device has a vendor name directly, it means it is being | |
# identified via SCSI | |
smartd_device_hash['options']="-d scsi -s (S/../../[1-6]/#{hour}|L/../../7/#{hour})" | |
when 'SMC' | |
# This is an SMC device. TODO: Enumerate through SMC drives | |
smartd_device_hash['options']="-d ignore" | |
when 'LSI', 'LSILOGIC' | |
# This is an LSI raid device. TODO: Enumerate through LSI drives | |
smartd_device_hash['options']="-d ignore" | |
when 'Adaptec' | |
# This is an adaptec raid device. TODO: Enumerate through adaptec drives | |
smartd_device_hash['options']="-d ignore" | |
when 'AMCC' | |
# This is the 3ware vendor. TODO: Enumerate through 3ware drives | |
smartd_device_hash['options']="-d ignore" | |
when 'HP' | |
# This is the HP vendor. TODO: Enumerate through HP drives | |
smartd_device_hash['options']="-d ignore" | |
else | |
# If there is a devices that is not covered above, then we are | |
# not ready to intrepret it | |
raise Puppet::ParseError, "Device #{device} has a vendor #{vendor} which | |
is unknown to smartd_guess(). Please tell someone in OPS. If this drive is | |
monitorable, we want to account for it." | |
end #end vendor case | |
# We are building an array of hashes, one hash per disk | |
devices_guess += [ smartd_device_hash ] | |
hour_counter += 1 | |
end # end device loop | |
return devices_guess | |
end # end function | |
end # end module |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment