bin/check-influxdb.rb in sensu-plugins-influxdb-0.0.4 vs bin/check-influxdb.rb in sensu-plugins-influxdb-0.0.5
- old
+ new
@@ -11,12 +11,10 @@
# PLATFORMS:
# Linux
#
# DEPENDENCIES:
# gem: sensu-plugin
-# gem: uri
-# gem: json
#
# USAGE:
# #YELLOW
#
# NOTES:
@@ -26,13 +24,11 @@
# Released under the same terms as Sensu (the MIT license); see LICENSE
# for details.
#
require 'sensu-plugin/check/cli'
-require 'net/http'
-require 'uri'
-require 'json'
+require 'net/https'
#
# Check InfluxDB
#
class CheckInfluxDB < Sensu::Plugin::Check::CLI
@@ -47,17 +43,29 @@
short: '-p PORT',
long: '--port PORT',
proc: proc(&:to_i),
default: 8086
- option :ssl,
+ option :use_ssl,
description: 'Turn on/off SSL (default: false)',
short: '-s',
- long: '--ssl',
+ long: '--use_ssl',
boolean: true,
default: false
+ option :verify_ssl,
+ description: 'Turn on/off using SSL certificate (default: false)',
+ short: '-v',
+ long: '--verify_ssl',
+ boolean: true,
+ default: false
+
+ option :ssl_ca_cert,
+ description: 'Path to the ssl ca certificate to connect to the InfluxDB server',
+ short: '-c CA_CERT',
+ long: '--ssl_ca_cert CA_CERT'
+
option :timeout,
description: 'Seconds to wait for the connection to open or read (default: 1.0s)',
short: '-t SECONDS',
long: '--timeout SECONDS',
proc: proc(&:to_f),
@@ -65,10 +73,16 @@
def run
http = Net::HTTP.new(config[:host], config[:port])
http.open_timeout = config[:timeout]
http.read_timeout = config[:timeout]
- http.use_ssl = config[:ssl]
+ http.use_ssl = config[:use_ssl]
+ if config[:verify_ssl]
+ http.ca_file = config[:ssl_ca_cert]
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
+ else
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
+ end
http.start do
response = http.get('/ping')
status_line = "#{response.code} #{response.message}"
if response.is_a?(Net::HTTPSuccess)
ok status_line