Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions bin/check-file-exists.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,29 @@

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

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

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

option :present,
short: '-p PRESENT',
long: '--present PRESENT'

def run
critical_values = []
warning_values = []
unknown_values = []
not_present_values = []

Dir.glob(config[:critical]).each do |file|
critical_values << file
Expand All @@ -74,12 +82,22 @@ def run
unknown_values << file
end

unless config[:present].nil?
unless File.exists?(config[:present])
not_present_values << config[:present]
end
end

if critical_values.any?
critical "#{critical_values.count} matching file(s) found: #{critical_values.join(', ')}"
elsif warning_values.any?
warning "#{warning_values.count} matching file(s) found: #{warning_values.join(', ')}"
elsif unknown_values.any?
unknown "#{unknown_values.count} matching file(s) found: #{unknown_values.join(', ')}"
elsif not_present_values.any?
critical "#{not_present_values.count} matching file(s) not found: #{not_present_values.join(', ')}"
elsif config[:present].instance_of?(String)
ok "Matching file(s) found: #{config[:present]}"
else
ok 'No matching files found'
end
Expand Down