Sha256: 66bfb1dc688b903717bf4f9625ddd2f8e0502ad48b1203b02b785ea3c6bc90bc

Contents?: true

Size: 1.53 KB

Versions: 1

Compression:

Stored size: 1.53 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 pattern to look for in the output of dmesg (regex or literal)'

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

  def run
    cmd = config[:invert] ? 'head' : 'tail'
    output = if config[:lines].zero?
               `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: #{output[0]}" if output.any?
    ok 'OK'
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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