Sha256: 4a984461a823b1fd797f84a5b2d0c7750e971add3d2daab117474c2455dbea50

Contents?: true

Size: 1.63 KB

Versions: 2

Compression:

Stored size: 1.63 KB

Contents

#! /usr/bin/env ruby
# frozen_string_literal: true

#
#   check-raid
#
# DESCRIPTION:
#   Checks the status of all virtual drives of a particular controller
#
#   MegaCli/MegaCli64 requires root access
#
# OUTPUT:
#   plain text
#
# PLATFORMS:
#   Linux
#
# DEPENDENCIES:
#   gem: sensu-plugin
#   gem: english
#
# USAGE:
#
# NOTES:
#
# LICENSE:
#   Copyright 2014 Magnus Hagdorn <magnus.hagdorn@ed.ac.uk>
#   The University of Edinburgh
#   Released under the same terms as Sensu (the MIT license); see LICENSE  for details.
#

require 'sensu-plugin/check/cli'
require 'English'

#
# Check MegaRAID
#
class CheckMegaRAID < Sensu::Plugin::Check::CLI
  option :megaraidcmd,
         description: 'the MegaCli executable',
         short: '-c CMD',
         long: '--command CMD',
         default: '/opt/MegaRAID/MegaCli/MegaCli64'

  option :controller,
         description: 'the controller to query',
         short: '-C ID',
         long: '--controller ID',
         proc: proc(&:to_i),
         default: 0
  # Main function
  #
  def run
    have_error = false
    error = ''
    # get number of virtual drives
    `#{config[:megaraidcmd]} -LDGetNum -a#{config[:controller]} `
    (0..$CHILD_STATUS.exitstatus - 1).each do |i|
      # and check them in turn
      stdout = `#{config[:megaraidcmd]} -LDInfo -L#{i} -a#{config[:controller]} `
      unless Regexp.new('State\s*:\s*Optimal').match?(stdout)
        error = sprintf '%svirtual drive %d: %s ', error, i, stdout[/State\s*:\s*.*/].split(':')[1] # rubocop:disable Style/FormatString
        have_error = true
      end
    end

    if have_error
      critical error
    else
      ok
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sensu-plugins-raid-checks-2.0.2 bin/check-megaraid-sas-status.rb
sensu-plugins-raid-checks-2.0.1 bin/check-megaraid-sas-status.rb