Skip to content

Instantly share code, notes, and snippets.

@mdkent
Forked from anonymous/gist:278290
Created January 15, 2010 19:09
Show Gist options
  • Save mdkent/278308 to your computer and use it in GitHub Desktop.
Save mdkent/278308 to your computer and use it in GitHub Desktop.
module SmartD
require "open3"
# Go through the devices in node[:block_device].
def self.pop_smartd_hash()
changed = false
node[:block_device].each do |device, properties|
if not node[:quick_start][:smartd].has_key?(device)
# Run 'smartctl -i /dev/device' and look for return
# code of zero and 'SMART support is: Available'
smart_enabled = false
stdin, stdout, stderr =
Open3.popen3("smartctl -i /dev/#{device}")
if not stderr.gets
while (ln = stdout.gets)
/.*smart\ssupport\sis:\s(\w+).*/i.match(ln)
if $1 and $1.downcase!.eql?('available')
smart_enabled = true
end
end
end
node[:quick_start][:smartd][device] = smart_enabled
changed = true
end
end
return changed
end
end
[Fri, 15 Jan 2010 10:28:27 -0800] DEBUG: Loading cookbook quick_start library file: /var/cache/chef/cookbooks/quick_start/libraries/node.rb
[Fri, 15 Jan 2010 10:28:27 -0800] DEBUG: Loading attributes from /var/cache/chef/cookbooks/quick_start/attributes/node.rb
[Fri, 15 Jan 2010 10:28:27 -0800] DEBUG: Loading Recipe quick_start::smartd_test
[Fri, 15 Jan 2010 10:28:27 -0800] DEBUG: Found recipe smartd_test in cookbook quick_start
/var/cache/chef/cookbooks/quick_start/libraries/node.rb:10:in `pop_smartd_hash': undefined local variable or method `node' for SmartD:Module (NameError)
from /var/cache/chef/cookbooks/quick_start/recipes/smartd_test.rb:8:in `from_file'
from /usr/lib/ruby/gems/1.8/gems/chef-0.7.16/lib/chef/mixin/recipe_definition_dsl_core.rb:68:in `instance_eval'
from /usr/lib/ruby/gems/1.8/gems/chef-0.7.16/lib/chef/mixin/recipe_definition_dsl_core.rb:68:in `method_missing'
from /var/cache/chef/cookbooks/quick_start/recipes/smartd_test.rb:1:in `from_file'
from /usr/lib/ruby/gems/1.8/gems/chef-0.7.16/lib/chef/cookbook.rb:166:in `load_recipe'
from /usr/lib/ruby/gems/1.8/gems/chef-0.7.16/lib/chef/compile.rb:153:in `load_recipes'
from /usr/lib/ruby/gems/1.8/gems/chef-0.7.16/lib/chef/compile.rb:142:in `each'
from /usr/lib/ruby/gems/1.8/gems/chef-0.7.16/lib/chef/compile.rb:142:in `load_recipes'
... 7 levels...
from /usr/lib/ruby/gems/1.8/gems/chef-0.7.16/lib/chef/application.rb:57:in `run'
from /usr/lib/ruby/gems/1.8/gems/chef-0.7.16/bin/chef-client:26
from /usr/bin/chef-client:19:in `load'
from /usr/bin/chef-client:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment