Skip to content

Instantly share code, notes, and snippets.

@toto
Created August 12, 2009 12:56
Show Gist options
  • Save toto/166486 to your computer and use it in GitHub Desktop.
Save toto/166486 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Uses some commands to determine the OpenSolaris system state and
require 'rubygems'
gem 'twitter'
require 'twitter'
ME_ON_TWITTER = 'mrtoto'
httpauth = Twitter::HTTPAuth.new('email', 'password')
$twitter = Twitter::Base.new(httpauth)
field_names = ['Pool', 'Size', 'Used Space', 'Avalible Space', 'Capacity Used', 'Health', 'Alternative Root']
pool_states = %w{ DEGRADED FAULTED ONLINE OFFLINE REMOVED UNAVAIL }
def twitter!(status)
$twitter.update(status) if status
STDERR.puts "Twitter: #{status}" if $DEBUG
end
zpool_list = `/usr/sbin/zpool list -H`
states = []
zpool_list.each_line do |line|
states << line.split("\t").collect{|e| e.strip}
end
states.each do |pool_state|
# check health
health = pool_state[field_names.index('Health')]
if health != 'ONLINE'
twitter!("@#{ME_ON_TWITTER} ZFS Pool #{pool_state.first} on #{`hostname`.strip} is in #{health} condition")
end
# check free space
used_capacity = (pool_state[field_names.index('Capacity Used')].to_f) / 100
if used_capacity > 0.9
used = pool_state[field_names.index('Used Space')]
total = pool_state[field_names.index('Avalible Space')]
twitter!("@#{ME_ON_TWITTER} Pool #{pool_state.first} on #{`hostname`.strip} has low free space. #{used} of #{total} used (#{used_capacity*100}%)")
end
str = %Q{#{`hostname`.strip}: #{pool_state.first} - Used: #{pool_state[field_names.index('Used Space')]}, Free: #{pool_state[field_names.index('Avalible Space')]}, Used: #{pool_state[field_names.index('Capacity Used')]}, Health: #{pool_state[field_names.index('Health')]}}
twitter!(str)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment