Sha256: c0af151440d914502263b27af04cff51fb631b536b521d3ccdf541ea53c5a122

Contents?: true

Size: 1.67 KB

Versions: 6

Compression:

Stored size: 1.67 KB

Contents

#! /usr/bin/env ruby
#
#   check-file-exists
#
# DESCRIPTION:
# Sometimes you just need a simple way to test if your alerting is functioning
# as you've designed it. This test plugin accomplishes just that. But it can
# also be set to check for the existance of any file (provided you have
# read-level permissions for it)
#
# By default it looks in your /tmp folder and looks for the files CRITICAL,
# WARNING or UNKNOWN. If it sees that any of those exists it fires off the
# corresponding status to sensu. Otherwise it fires off an "ok".
#
# This allows you to fire off an alert by doing something as simple as:
# touch /tmp/CRITICAL
#
# And then set it ok again with:
# rm /tmp/CRITICAL
#
# OUTPUT:
#   plain text
#
# PLATFORMS:
#   Linux, BSD
#
# DEPENDENCIES:
#   gem: sensu-plugin
#
# USAGE:
#   #YELLOW
#
# NOTES:
#
# LICENSE:
#   Copyright 2013 Mike Skovgaard <mikesk@gmail.com>
#   Released under the same terms as Sensu (the MIT license); see LICENSE
#   for details.
#

require 'sensu-plugin/check/cli'

class CheckFileExists < Sensu::Plugin::Check::CLI
  option :critical,
         short: '-c CRITICAL_FILE',
         default: '/tmp/CRITICAL'

  option :warning,
         short: '-w WARNING_FILE',
         default: '/tmp/WARNING'

  option :unknown,
         short: '-u UNKNOWN_FILE',
         default: '/tmp/UNKNOWN'

  def run
    if config[:critical] && File.exist?(config[:critical])
      critical "#{config[:critical]} exists!"
    elsif config[:warning] && File.exist?(config[:warning])
      warning "#{config[:warning]} exists!"
    elsif config[:unknown] && File.exist?(config[:unknown])
      unknown "#{config[:unknown]} exists!"
    else
      ok 'No test files exist'
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sensu-plugins-filesystem-checks-0.2.0 bin/check-file-exists.rb
sensu-plugins-filesystem-checks-0.1.0 bin/check-file-exists.rb
sensu-plugins-filesystem-checks-0.0.4 bin/check-file-exists.rb
sensu-plugins-filesystem-checks-0.0.3 bin/check-file-exists.rb
sensu-plugins-filesystem-checks-0.0.2 bin/check-file-exists.rb
sensu-plugins-filesystem-checks-0.0.1 bin/check-file-exists.rb