Skip to content
Open
Changes from 1 commit
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
23 changes: 19 additions & 4 deletions bin/check-cmd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,38 @@ class CheckCmdStatus < Sensu::Plugin::Check::CLI
short: '-o',
long: '--check_output REGEX'

option :echo_stdout,
description: 'Output the stdout of the command',
short: '-e',
long: '--echo_stdout',
boolean: true,
default: false

# Acquire the exit code and/or output of a command and alert if it is not
# what is expected.
#
def acquire_cmd_status
stdout = `#{config[:command]}`
# #YELLOW
unless $CHILD_STATUS.exitstatus.to_s == config[:status] # rubocop:disable UnlessElse
critical "#{config[:command]} exited with #{$CHILD_STATUS.exitstatus}"
status = "#{config[:command]} exited with #{$CHILD_STATUS.exitstatus}"
status += "\nOutput: #{stdout}" if config[:echo_stdout]
critical status
else
if config[:check_output]
if Regexp.new(config[:check_output]).match(stdout)
ok "#{config[:command]} matched #{config[:check_output]} and exited with #{$CHILD_STATUS.exitstatus}"
status = "#{config[:command]} matched #{config[:check_output]} and exited with #{$CHILD_STATUS.exitstatus}"
status += "\nOutput: #{stdout}" if config[:echo_stdout]
ok status
else
critical "#{config[:command]} output didn't match #{config[:check_output]} (exit #{$CHILD_STATUS.exitstatus})"
status = "#{config[:command]} output didn't match #{config[:check_output]} (exit #{$CHILD_STATUS.exitstatus})"
status += "\nOutput: #{stdout}" if config[:echo_stdout]
critical status
end
else
ok "#{config[:command]} exited with #{$CHILD_STATUS.exitstatus}"
status = "#{config[:command]} exited with #{$CHILD_STATUS.exitstatus}"
status += "\nOutput: #{stdout}" if config[:echo_stdout]
status ok
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw this looks wrong to me I am guess this is meant to be ok status.

end
end
end
Expand Down