Skip to content

Commit

Permalink
Merge pull request #47 from UGent-DICT/default_return_code
Browse files Browse the repository at this point in the history
Add parameter to specify the default return code on non-200 responses
  • Loading branch information
phrawzty authored Jan 25, 2021
2 parents 8e13781 + ebc3bf7 commit 58a2f0e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Usage: ./check_http_json.rb -u <URI> -e <element> -w <warn> -c <crit>
--pass PASSWORD HTTP basic authentication password.
--headers HEADERS Comma-separated list of HTTP headers to include (ex. HOST:somehost,AUTH:letmein).
--status_level STRING Comma-separated list of HTTP status codes and their associated Nagios alert levels (ex. 301:1,404:2).
--status_level_default VALUE The default return code for unexpected HTTP status codes. Defaults to 1.
-f, --file PATH Target file. Incompatible with -u.
-e, --element ELEMENT... Desired element (ex. foo=>bar=>ish is foo.bar.ish). Repeatable argument.
-E, --element_regex REGEX Desired element expressed as regular expression.
Expand Down
8 changes: 6 additions & 2 deletions check_http_json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,7 @@ def uri_target(options)

# We must get a 200 response; if not, the user might want to know.
if not response.code.to_i == 200 then
# WARN by default.
level = 1
level = options[:status_level_default]
if options[:status_level] then
options[:status_level].each do |s|
k,v = s.split(':')
Expand Down Expand Up @@ -301,6 +300,11 @@ def parse_args(options)
options[:status_level] = x.split(',')
end

options[:status_level_default] = 1
opts.on('--status_level_default VALUE', 'The default return code for unexpected HTTP status codes. Defaults to 1.') do |x|
options[:status_level_default] = x.to_i
end

options[:file] = nil
opts.on('-f', '--file PATH', 'Target file. Incompatible with -u.') do |x|
options[:file] = x
Expand Down

0 comments on commit 58a2f0e

Please sign in to comment.