bin/check-http-json.rb in sensu-plugins-http-0.4.0 vs bin/check-http-json.rb in sensu-plugins-http-1.0.0

- old
+ new

@@ -1,6 +1,6 @@ -#! /usr/bin/env ruby +#!/usr/bin/env ruby # # check-http-json # # DESCRIPTION: # Takes either a URL or a combination of host/path/query/port/ssl, and checks @@ -48,12 +48,13 @@ option :header, short: '-H HEADER', long: '--header HEADER' option :ssl, short: '-s', boolean: true, default: false option :insecure, short: '-k', boolean: true, default: false option :user, short: '-U', long: '--username USER' option :password, short: '-a', long: '--password PASS' - option :cert, short: '-c FILE' - option :cacert, short: '-C FILE' + option :cert, short: '-c FILE', long: '--cert FILE' + option :certkey, long: '--cert-key FILE' + option :cacert, short: '-C FILE', long: '--cacert FILE' option :timeout, short: '-t SECS', proc: proc(&:to_i), default: 15 option :key, short: '-K KEY', long: '--key KEY' option :value, short: '-v VALUE', long: '--value VALUE' def run @@ -96,10 +97,13 @@ if config[:ssl] http.use_ssl = true if config[:cert] cert_data = File.read(config[:cert]) http.cert = OpenSSL::X509::Certificate.new(cert_data) + if config[:certkey] + cert_data = File.read(config[:certkey]) + end http.key = OpenSSL::PKey::RSA.new(cert_data, nil) end http.ca_file = config[:cacert] if config[:cacert] http.verify_mode = OpenSSL::SSL::VERIFY_NONE if config[:insecure] end @@ -111,10 +115,10 @@ end if config[:postbody] post_body = IO.readlines(config[:postbody]) req.body = post_body.join end - if !config[:user].nil? && !config[:password].nil? + unless config[:user].nil? && config[:password].nil? req.basic_auth config[:user], config[:password] end if config[:header] config[:header].split(',').each do |header| h, v = header.split(':', 2)