bin/check-http-json.rb in sensu-plugins-http-2.7.0 vs bin/check-http-json.rb in sensu-plugins-http-2.8.0
- old
+ new
@@ -63,10 +63,12 @@
option :key, short: '-K KEY', long: '--key KEY'
option :value, short: '-v VALUE', long: '--value VALUE'
option :valueGt, long: '--value-greater-than VALUE'
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
def run
if config[:url]
uri = URI.parse(config[:url])
config[:host] = uri.host
@@ -186,22 +188,28 @@
raise "could not find key: #{config[:key]}" if leaf.nil?
message = "key has expected value: '#{config[:key]}' "
if config[:value]
raise "unexpected value for key: '#{leaf}' != '#{config[:value]}'" unless leaf.to_s == config[:value].to_s
- message += " equals '#{config[:value]}'"
+ message += "equals '#{config[:value]}'"
end
if config[:valueGt]
raise "unexpected value for key: '#{leaf}' not > '#{config[:valueGt]}'" unless leaf.to_f > config[:valueGt].to_f
- message += " greater than '#{config[:valueGt]}'"
+ message += "greater than '#{config[:valueGt]}'"
end
if config[:valueLt]
raise "unexpected value for key: '#{leaf}' not < '#{config[:valueLt]}'" unless leaf.to_f < config[:valueLt].to_f
- message += " less than '#{config[:valueLt]}'"
+ message += "less than '#{config[:valueLt]}'"
end
ok message
rescue => e
- critical "key check failed: #{e}"
+ if config[:dump_json]
+ json_response = config[:pretty] ? JSON.pretty_generate(json) : json
+ message = "key check failed: #{e}. Response: #{json_response}"
+ else
+ message = "key check failed: #{e}"
+ end
+ critical message
end
end
end