bin/check-http-json.rb in sensu-plugins-http-2.10.0 vs bin/check-http-json.rb in sensu-plugins-http-2.11.0

- old
+ new

@@ -72,10 +72,15 @@ option :valueLt, long: '--value-less-than VALUE' option :whole_response, short: '-w', long: '--whole-response', boolean: true, default: false option :dump_json, short: '-d', long: '--dump-json', boolean: true, default: false option :pretty, long: '--pretty', boolean: true, default: false + option :response_code, + long: '--response-code REGEX', + description: 'Critical if HTTP response code does not match REGEX', + default: '^2([0-9]{2})$' + def run if config[:url] uri = URI.parse(config[:url]) config[:host] = uri.host config[:path] = uri.path @@ -180,10 +185,10 @@ req[h] = v.strip end end res = http.request(req) - unless res.code =~ /^2/ + if res.code !~ /#{config[:response_code]}/ critical "http code: #{res.code}: body: #{res.body}" if config[:whole_response] critical res.code end critical 'invalid JSON from request' unless json_valid?(res.body) ok 'valid JSON returned' if config[:key].nil? && config[:value].nil?