Created
October 24, 2010 16:40
-
-
Save ice799/643666 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/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 = "[email protected]" | |
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