Class: ServerMonitor::MegaCliVDStatus

Inherits:
Object
  • Object
show all
Defined in:
lib/servermonitor/megacli_vd_status.rb

Class Method Summary collapse

Class Method Details

.configObject



22
23
24
# File 'lib/servermonitor/megacli_vd_status.rb', line 22

def self.config
  @config ||= VDConfiguration.new
end

.configure {|config| ... } ⇒ Object

Yields:



26
27
28
# File 'lib/servermonitor/megacli_vd_status.rb', line 26

def self.configure
  yield(config)
end

.runObject



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
# File 'lib/servermonitor/megacli_vd_status.rb', line 30

def self.run
  # Get current hostname
  fhostname = `hostname -f`

  # Get the VD state from megacli binary and grep for "State" keyword
  raid_status = `#{self.config.megacli} -LDInfo -Lall -aALL | #{self.config.grep} "State"`

  # Define eympty array
  in_in = []

  # Define empty variable for raid state
  vd_status = nil
  #
  raid_status.each_line { |l| in_in << l.chomp }

  # Check virtual drive status
  in_in.each do |i|
    Regexp.new('State\s*:\s*Optimal').match?(i) ? vd_status = "Optimal".upcase : vd_status = "NOT Optimal".upcase

    # Display VD Status
    if vd_status == "Optimal"
      puts "Virtual drive status is " + vd_status.to_s + " on hostname " + fhostname
      puts exit 0 unless self.config.exit_codes == false
    else
      puts "Virtual drive status is " + vd_status.to_s + " on hostname " + fhostname
      puts exit 1 unless self.config.exit_codes == false
    end
    if self.config.email_to != nil
      time    = Time.now.strftime("%d.%m.%Y %H:%M")
      subject = "Daily RAID check STARTED on #{fhostname} at #{time}. RAID STATE: #{vd_status}."
      body    = "Daily RAID check: #{vd_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