bin/metrics-es-node.rb in sensu-plugins-elasticsearch-0.1.1 vs bin/metrics-es-node.rb in sensu-plugins-elasticsearch-0.1.2

- old
+ new

@@ -29,10 +29,11 @@ # require 'sensu-plugin/metric/cli' require 'rest-client' require 'json' +require 'base64' # # ES Node Metrics # class ESMetrics < Sensu::Plugin::Metric::CLI::Graphite @@ -53,12 +54,27 @@ short: '-p PORT', long: '--port PORT', proc: proc(&:to_i), default: 9200 - def run # rubocop:disable all - ln = RestClient::Resource.new "http://#{config[:host]}:#{config[:port]}/_cluster/nodes/_local", timeout: 30 - stats = RestClient::Resource.new "http://#{config[:host]}:#{config[:port]}/_cluster/nodes/_local/stats", timeout: 30 + option :user, + description: 'Elasticsearch User', + short: '-u USER', + long: '--user USER' + + option :password, + description: 'Elasticsearch Password', + short: '-P PASS', + long: '--password PASS' + + def run + headers = {} + if config[:user] && config[:password] + auth = 'Basic ' + Base64.encode64("#{config[:user]}:#{config[:password]}").chomp + headers = { 'Authorization' => auth } + end + ln = RestClient::Resource.new "http://#{config[:host]}:#{config[:port]}/_cluster/nodes/_local", timeout: 30, headers: headers + stats = RestClient::Resource.new "http://#{config[:host]}:#{config[:port]}/_cluster/nodes/_local/stats", timeout: 30, headers: headers ln = JSON.parse(ln.get) stats = JSON.parse(stats.get) timestamp = Time.now.to_i node = stats['nodes'].values.first node['jvm']['mem']['heap_max_in_bytes'] = ln['nodes'].values.first['jvm']['mem']['heap_max_in_bytes']