Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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
Add Comment
Please, Sign In to add comment