Guest User

Untitled

a guest
Jun 19th, 2018
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. #!/custom/ree/bin/ruby
  2. require 'net/smtp'
  3.  
  4. class RaidWatcher
  5. def self.send_alert msg
  6. begin
  7. domain = $config.email.domain,
  8. host = $config.email.server,
  9. port = $config.email.port,
  10. from = "raid@#{$config.email.domain}"
  11. to = "someone_who_can_fix_it@somewhere.com"
  12.  
  13. content = ''
  14. content << "From: #{from}\r\n"
  15. content << "Subject: #{`hostname -s`} RAID STATUS CHANGE!\r\n"
  16. content << msg
  17.  
  18. Net::SMTP.start(host, port, domain) do |smtp|
  19. smtp.send_message(content, from, to)
  20. end
  21. rescue => e
  22. # this is bad.
  23. end
  24. end
  25.  
  26. def self.check_status
  27. IO.popen('/usr/StorMan/arcconf getconfig 1 AL', 'w+') do |io|
  28. io.close_write
  29. begin
  30. while line = io.readline
  31. if line =~ /Controller\sStatus\s*:\s(.*)/
  32. send_alert "RAID controller status not optimal! Status changed to: #{$1}" if $1 != 'Optimal'
  33. elsif line =~ /Logical devices\/Failed\/Degraded\s*:\s(.*)/
  34. send_alert "RAID controller failed/degraded! Logical device status changed to: #{$1}" if $1 != '1/0/0'
  35. elsif line =~ /Status\s*:\s(.*)/
  36. send_alert "RAID bbu status not optimal! BBU status changed to: #{$1}" if ($1 != 'Optimal' && $1 != 'Charging')
  37. elsif line =~ /Capacity remaining\s*:\s([0-9]+)\sp/
  38. send_alert "RAID bbu power DRAINING!!! BBU only has: #{$1}% power left." if $1.to_i <= 85
  39. elsif line =~ /Status of logical device\s*:\s(.*)/
  40. send_alert "RAID logical device status not optimal! Logical device status changed to: #{$1}" if $1 != 'Optimal'
  41. elsif line =~ /Failed stripes\s*:\s(.*)/
  42. send_alert "RAID device has FAILED STRIPES!" if $1 != 'No'
  43. elsif line =~ /State\s*:\s(.*)/
  44. send_alert "RAID physical disk is NOT online!! Physical disk state changed to: #{$1}" if $1 != 'Online'
  45. end
  46. end
  47. rescue EOFError
  48. # done
  49. end
  50. end
  51. end
  52. end
  53.  
  54. RaidWatcher.check_status
Add Comment
Please, Sign In to add comment