Sha256: d9920f0e84865db47eb61f6216bc02f90184a1690a0d8d7828116953762fff55

Contents?: true

Size: 1.5 KB

Versions: 1

Compression:

Stored size: 1.5 KB

Contents

#! /usr/bin/env ruby
#
#   check-hardware-fail
#
# DESCRIPTION:
#   Check dmesg for failing hardware
#   Detects things like overheating CPUs, dying hard drives, etc.
#
# OUTPUT:
#   plain text
#
# PLATFORMS:
#   Linux
#
# DEPENDENCIES:
#   gem: sensu-plugin
#
# USAGE:
#
# NOTES:
#
# LICENSE:
#   Shank Feek, Alan Smith
#   Released under the same terms as Sensu (the MIT license); see LICENSE
#   for details.
#

require 'English'
require 'rubygems' if RUBY_VERSION < '1.9.0'
require 'sensu-plugin/check/cli'

class CheckHardwareFail < Sensu::Plugin::Check::CLI
  option :lines,
         short: '-l NUMBER',
         long: '--lines NUMBER',
         proc: proc(&:to_i),
         default: 0,
         description: 'Maximum number of lines to read from dmesg, 0 (default) means all'

  option :query,
         short: '-q QUERY',
         long: '--query QUERY',
         default: 'Hardware Error',
         description: 'What to look for in the output of dmesg'

  option :invert,
         long: '--invert',
         description: 'Invert order',
         boolean: true,
         default: false

  def run
    cmd = config[:invert] ? 'head' : 'tail'
    errors = if config[:lines] == 0
               `dmesg`.lines.select { |l| l[/#{config[:query]}/] }
             else
               `dmesg | #{cmd} -n #{config[:lines]}`.lines.select { |l| l[/#{config[:query]}/] }
             end
    unknown 'Command execution failed!' unless $CHILD_STATUS.success?
    critical "Problem Detected: #{config[:query]}" if errors.any?
    ok 'OK'
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sensu-plugins-hardware-1.1.0 bin/check-hardware-fail.rb