<commit_before>#! /usr/bin/env ruby
#
#   check-raid
#
# DESCRIPTION:
#   Generic raid check
#   Supports HP, Adaptec, and MegaRAID controllers. Also supports software RAID.
#
# OUTPUT:
#   plain text
#
# PLATFORMS:
#   Linux
#
# DEPENDENCIES:
#   gem: sensu-plugin
#
# USAGE:
#
# NOTES:
#
# LICENSE:
# Originally by <NAME>, modified by <NAME>. Date: 07/14/2014#
# Released under the same terms as Sensu (the MIT license); see LICENSE  for details.
#

require 'sensu-plugin/check/cli'

#
# Check Raid
#
class CheckRaid < Sensu::Plugin::Check::CLI
  # Check software raid
  #
  def check_software
    # #YELLOW
    if File.exist?('/proc/mdstat') # rubocop:disable GuardClause
      contents = File.read('/proc/mdstat')
      mg = contents.lines.grep(/active/)
      unless mg.empty?
        sg = mg.to_s.lines.grep(/\]\(F\)/)
        # #YELLOW
        unless sg.empty? # rubocop:disable UnlessElse
          warning 'Software RAID warning'
        else
          ok 'Software RAID OK'
        end
      end
    end
  end

  # Check HP raid
  #
  def check_hp
    # #YELLOW
    if File.exist?('/usr/bin/cciss_vol_status') # rubocop:disable GuardClause
      contents = `/usr/bin/cciss_vol_status /dev/sg0`
      c = contents.lines.grep(/status\: OK\./)
      # #YELLOW
      unless c.empty? # rubocop:disable UnlessElse
        ok 'HP RAID OK'
      else
        warning 'HP RAID warning'
      end
    end
  end

  # Check Adaptec raid controllers
  #
  def check_adaptec
    # #YELLOW
    if File.exist?('/usr/StorMan/arcconf') # rubocop:disable GuardClause
      contents = `/usr/StorMan/arcconf GETCONFIG 1 AL`

      mg = contents.lines.grep(/Controller Status/)
      # #YELLOW
      unless mg.empty? # rubocop:disable UnlessElse
        sg = mg.to_s.lines.grep(/Optimal/)
        warning 'Adaptec Physical RAID Controller Failure' if sg.empty?
      else
        warning 'Adaptec Physical RAID Controller Status Read Failure'
      end

      mg = contents.lines.grep(/Status of logical device/)
      # #YELLOW
      unless mg.empty? # rubocop:disable UnlessElse
        sg = mg.to_s.lines.grep(/Optimal/)
        warning 'Adaptec Logical RAID Controller Failure' if sg.empty?
      else
        warning 'Adaptec Logical RAID Controller Status Read Failure'
      end

      mg = contents.lines.grep(/S\.M\.A\.R\.T\.   /)
      # #YELLOW
      unless mg.empty? # rubocop:disable UnlessElse
        sg = mg.to_s.lines.grep(/No/)
        warning 'Adaptec S.M.A.R.T. Disk Failed' if sg.empty?
      else
        warning 'Adaptec S.M.A.R.T. Status Read Failure'
      end

      ok 'Adaptec RAID OK'
    end
  end

  # Check Megaraid
  #
  def check_mega_raid
    # #YELLOW
    if File.exist?('/usr/sbin/megacli') # rubocop:disable GuardClause
      contents = `/usr/sbin/megacli -AdpAllInfo -aALL`
      c = contents.lines.grep(/(Critical|Failed) Disks\s+\: 0/)
      # #YELLOW
      unless c.empty? # rubocop:disable UnlessElse
        ok 'MegaRaid RAID OK'
      else
        warning 'MegaRaid RAID warning'
      end
    end
  end

  # Main function
  #
  def run
    check_software
    unless `lspci`.lines.grep(/RAID/).empty?
      check_hp<commit_msg>Detect degraded MegaRAID arrays<commit_after>#! /usr/bin/env ruby
#
#   check-raid
#
# DESCRIPTION:
#   Generic raid check
#   Supports HP, Adaptec, and MegaRAID controllers. Also supports software RAID.
#
# OUTPUT:
#   plain text
#
# PLATFORMS:
#   Linux
#
# DEPENDENCIES:
#   gem: sensu-plugin
#
# USAGE:
#
# NOTES:
#
# LICENSE:
# Originally by <NAME>, modified by <NAME>. Date: 07/14/2014#
# Released under the same terms as Sensu (the MIT license); see LICENSE  for details.
#

require 'sensu-plugin/check/cli'

#
# Check Raid
#
class CheckRaid < Sensu::Plugin::Check::CLI
  # Check software raid
  #
  def check_software
    # #YELLOW
    if File.exist?('/proc/mdstat') # rubocop:disable GuardClause
      contents = File.read('/proc/mdstat')
      mg = contents.lines.grep(/active/)
      unless mg.empty?
        sg = mg.to_s.lines.grep(/\]\(F\)/)
        # #YELLOW
        unless sg.empty? # rubocop:disable UnlessElse
          warning 'Software RAID warning'
        else
          ok 'Software RAID OK'
        end
      end
    end
  end

  # Check HP raid
  #
  def check_hp
    # #YELLOW
    if File.exist?('/usr/bin/cciss_vol_status') # rubocop:disable GuardClause
      contents = `/usr/bin/cciss_vol_status /dev/sg0`
      c = contents.lines.grep(/status\: OK\./)
      # #YELLOW
      unless c.empty? # rubocop:disable UnlessElse
        ok 'HP RAID OK'
      else
        warning 'HP RAID warning'
      end
    end
  end

  # Check Adaptec raid controllers
  #
  def check_adaptec
    # #YELLOW
    if File.exist?('/usr/StorMan/arcconf') # rubocop:disable GuardClause
      contents = `/usr/StorMan/arcconf GETCONFIG 1 AL`

      mg = contents.lines.grep(/Controller Status/)
      # #YELLOW
      unless mg.empty? # rubocop:disable UnlessElse
        sg = mg.to_s.lines.grep(/Optimal/)
        warning 'Adaptec Physical RAID Controller Failure' if sg.empty?
      else
        warning 'Adaptec Physical RAID Controller Status Read Failure'
      end

      mg = contents.lines.grep(/Status of logical device/)
      # #YELLOW
      unless mg.empty? # rubocop:disable UnlessElse
        sg = mg.to_s.lines.grep(/Optimal/)
        warning 'Adaptec Logical RAID Controller Failure' if sg.empty?
      else
        warning 'Adaptec Logical RAID Controller Status Read Failure'
      end

      mg = contents.lines.grep(/S\.M\.A\.R\.T\.   /)
      # #YELLOW
      unless mg.empty? # rubocop:disable UnlessElse
        sg = mg.to_s.lines.grep(/No/)
        warning 'Adaptec S.M.A.R.T. Disk Failed' if sg.empty?
      else
        warning 'Adaptec S.M.A.R.T. Status Read Failure'
      end

      ok 'Adaptec RAID OK'
    end
  end

  # Check Megaraid
  #
  def check_mega_raid
    # #YELLOW
    if File.exist?('/usr/sbin/megacli') # rubocop:disable GuardClause
      contents = `/usr/sbin/megacli -AdpAllInfo -aALL`
      failed = contents.lines.grep(/(Critical|Failed) Disks\s+\: 0/)
      degraded = contents.lines.grep(/Degraded\s+\: 0/)
      # #YELLOW
      unless failed.empty? or degraded.empty? # rubocop:disable UnlessElse
        ok 'MegaRaid RAID OK'
      else
        warning 'MegaRaid RAID warning'
      end
    end
  end

  # Main function
  #
  def run
    check_software
    unless `lspci`.lines.grep(/RAID/).empty?
      check_hp
{'fraction_non_alphanumeric': 0.11318698427526078, 'fraction_numerical': 0.0035808812081581814, 'mean_word_length': 2.2926704254228603, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3779365', 'n_tokens_mistral': 2384, 'n_tokens_neox': 2202, 'n_words': 553}