Skip to content

Instantly share code, notes, and snippets.

@ice799
Created October 24, 2010 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ice799/643666 to your computer and use it in GitHub Desktop.
Save ice799/643666 to your computer and use it in GitHub Desktop.
#!/custom/ree/bin/ruby
require 'net/smtp'
class RaidWatcher
def self.send_alert msg
begin
domain = $config.email.domain,
host = $config.email.server,
port = $config.email.port,
from = "raid@#{$config.email.domain}"
to = "someone_who_can_fix_it@somewhere.com"
content = ''
content << "From: #{from}\r\n"
content << "Subject: #{`hostname -s`} RAID STATUS CHANGE!\r\n"
content << msg
Net::SMTP.start(host, port, domain) do |smtp|
smtp.send_message(content, from, to)
end
rescue => e
# this is bad.
end
end
def self.check_status
IO.popen('/usr/StorMan/arcconf getconfig 1 AL', 'w+') do |io|
io.close_write
begin
while line = io.readline
if line =~ /Controller\sStatus\s*:\s(.*)/
send_alert "RAID controller status not optimal! Status changed to: #{$1}" if $1 != 'Optimal'
elsif line =~ /Logical devices\/Failed\/Degraded\s*:\s(.*)/
send_alert "RAID controller failed/degraded! Logical device status changed to: #{$1}" if $1 != '1/0/0'
elsif line =~ /Status\s*:\s(.*)/
send_alert "RAID bbu status not optimal! BBU status changed to: #{$1}" if ($1 != 'Optimal' && $1 != 'Charging')
elsif line =~ /Capacity remaining\s*:\s([0-9]+)\sp/
send_alert "RAID bbu power DRAINING!!! BBU only has: #{$1}% power left." if $1.to_i <= 85
elsif line =~ /Status of logical device\s*:\s(.*)/
send_alert "RAID logical device status not optimal! Logical device status changed to: #{$1}" if $1 != 'Optimal'
elsif line =~ /Failed stripes\s*:\s(.*)/
send_alert "RAID device has FAILED STRIPES!" if $1 != 'No'
elsif line =~ /State\s*:\s(.*)/
send_alert "RAID physical disk is NOT online!! Physical disk state changed to: #{$1}" if $1 != 'Online'
end
end
rescue EOFError
# done
end
end
end
end
RaidWatcher.check_status
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment