30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/servermonitor/megacli_disk_smart_status.rb', line 30
def self.run
fhostname = `hostname -f`
raid_status = `#{self.config.megacli} -LDInfo -Lall -aALL | #{self.config.grep} "Drive has flagged a S.M.A.R.T alert"`
in_in = []
smart_status = nil
raid_status.each_line { |l| in_in << l.chomp }
in_in.each do |i|
Regexp.new('Drive\s*has\s*flagged\s*a\s*S\.M\.A\.R\.T\s*alert\s*:\s*Yes').match?(i) ? smart_status = "ALERT: YES".upcase : smart_status = "ALERT: NO".upcase
if smart_status == "ALERT: NO"
puts "S.M.A.R.T drive status is " + smart_status.to_s + " on hostname " + fhostname
puts exit 0 unless self.config.exit_codes == false
else
puts "S.M.A.R.T drive status is " + smart_status.to_s + " on hostname " + fhostname
puts exit 1 unless self.config.exit_codes == false
end
if self.config.email_to != nil && smart_status != "ALERT: NO"
time = Time.now.strftime("%d.%m.%Y %H:%M")
subject = "RAID check STARTED on #{fhostname} at #{time}. RAID STATE: #{smart_status}."
body = "RAID check: #{smart_status}"
email = ServerMonitor::EMail.new(self.config.email_from, self.config.email_to, self.config.smtp_address, self.config.smtp_port, self.config.smtp_username, self.config.smtp_password, subject, body)
email.deliver
end
end
end
|