From d156ac397beffabe3f0cb045f923050a3ab74887 Mon Sep 17 00:00:00 2001 From: Neil Lathwood Date: Tue, 31 Oct 2017 21:38:54 +0000 Subject: Added support for sending single node request to http source --- lib/oxidized/source/http.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib/oxidized/source/http.rb') diff --git a/lib/oxidized/source/http.rb b/lib/oxidized/source/http.rb index 6c12f29..e4cb58e 100644 --- a/lib/oxidized/source/http.rb +++ b/lib/oxidized/source/http.rb @@ -15,7 +15,7 @@ class HTTP < Source require "uri" require "json" - def load + def load node=nil nodes = [] uri = URI.parse(@cfg.url) http = Net::HTTP.new(uri.host, uri.port) @@ -28,7 +28,11 @@ class HTTP < Source headers[header] = value end - request = Net::HTTP::Get.new(uri.request_uri, headers) + req_uri = uri.request_uri + if node + req_uri = "#{req_uri}/#{node}" + end + request = Net::HTTP::Get.new(req_uri, headers) if (@cfg.user? && @cfg.pass?) request.basic_auth(@cfg.user,@cfg.pass) end -- cgit v1.2.1 From 29704b5f2721a742d312ced784a8076e27e8063b Mon Sep 17 00:00:00 2001 From: laf Date: Fri, 10 Nov 2017 14:12:13 +0000 Subject: Added sql support for calling for single host --- lib/oxidized/source/http.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/oxidized/source/http.rb') diff --git a/lib/oxidized/source/http.rb b/lib/oxidized/source/http.rb index e4cb58e..73df6f7 100644 --- a/lib/oxidized/source/http.rb +++ b/lib/oxidized/source/http.rb @@ -15,7 +15,7 @@ class HTTP < Source require "uri" require "json" - def load node=nil + def load node_want=nil nodes = [] uri = URI.parse(@cfg.url) http = Net::HTTP.new(uri.host, uri.port) @@ -29,8 +29,8 @@ class HTTP < Source end req_uri = uri.request_uri - if node - req_uri = "#{req_uri}/#{node}" + if node_want + req_uri = "#{req_uri}/#{node_want}" end request = Net::HTTP::Get.new(req_uri, headers) if (@cfg.user? && @cfg.pass?) -- cgit v1.2.1 From 01d7f29905fd9ca712e8b640408425cf2d3ad64d Mon Sep 17 00:00:00 2001 From: Wild Kat Date: Wed, 11 Apr 2018 19:58:30 +0200 Subject: standardize on verbose hash methods --- lib/oxidized/source/http.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/oxidized/source/http.rb') diff --git a/lib/oxidized/source/http.rb b/lib/oxidized/source/http.rb index 6c12f29..56a575b 100644 --- a/lib/oxidized/source/http.rb +++ b/lib/oxidized/source/http.rb @@ -43,7 +43,7 @@ class HTTP < Source want_positions = want_position.split('.') keys[key.to_sym] = node_var_interpolate node.dig(*want_positions) end - keys[:model] = map_model keys[:model] if keys.key? :model + keys[:model] = map_model keys[:model] if keys.has_key? :model # map node specific vars vars = {} -- cgit v1.2.1 From 21e3d6490496573f25ef77fe8172766ac7d1a736 Mon Sep 17 00:00:00 2001 From: Wild Kat Date: Sat, 21 Apr 2018 13:27:05 +0200 Subject: the great makeover - standardize layout, alignment, indentation --- lib/oxidized/source/http.rb | 97 ++++++++++++++++++++++----------------------- 1 file changed, 48 insertions(+), 49 deletions(-) (limited to 'lib/oxidized/source/http.rb') diff --git a/lib/oxidized/source/http.rb b/lib/oxidized/source/http.rb index 56a575b..4480cbb 100644 --- a/lib/oxidized/source/http.rb +++ b/lib/oxidized/source/http.rb @@ -1,64 +1,63 @@ module Oxidized -class HTTP < Source - def initialize - @cfg = Oxidized.config.source.http - super - end - - def setup - if @cfg.url.empty? - raise NoConfig, 'no source http url config, edit ~/.config/oxidized/config' + class HTTP < Source + def initialize + @cfg = Oxidized.config.source.http + super end - end - - require "net/http" - require "uri" - require "json" - def load - nodes = [] - uri = URI.parse(@cfg.url) - http = Net::HTTP.new(uri.host, uri.port) - http.use_ssl = true if uri.scheme == 'https' - http.verify_mode = OpenSSL::SSL::VERIFY_NONE unless @cfg.secure - - # map headers - headers = {} - @cfg.headers.each do |header, value| - headers[header] = value + def setup + if @cfg.url.empty? + raise NoConfig, 'no source http url config, edit ~/.config/oxidized/config' + end end - request = Net::HTTP::Get.new(uri.request_uri, headers) - if (@cfg.user? && @cfg.pass?) - request.basic_auth(@cfg.user,@cfg.pass) - end + require "net/http" + require "uri" + require "json" - response = http.request(request) - data = JSON.parse(response.body) - data.each do |node| - next if node.empty? - # map node parameters - keys = {} - @cfg.map.each do |key, want_position| - want_positions = want_position.split('.') - keys[key.to_sym] = node_var_interpolate node.dig(*want_positions) + def load + nodes = [] + uri = URI.parse(@cfg.url) + http = Net::HTTP.new(uri.host, uri.port) + http.use_ssl = true if uri.scheme == 'https' + http.verify_mode = OpenSSL::SSL::VERIFY_NONE unless @cfg.secure + + # map headers + headers = {} + @cfg.headers.each do |header, value| + headers[header] = value end - keys[:model] = map_model keys[:model] if keys.has_key? :model - # map node specific vars - vars = {} - @cfg.vars_map.each do |key, want_position| - want_positions = want_position.split('.') - vars[key.to_sym] = node_var_interpolate node.dig(*want_positions) + request = Net::HTTP::Get.new(uri.request_uri, headers) + if (@cfg.user? && @cfg.pass?) + request.basic_auth(@cfg.user, @cfg.pass) end - keys[:vars] = vars unless vars.empty? - nodes << keys + response = http.request(request) + data = JSON.parse(response.body) + data.each do |node| + next if node.empty? + # map node parameters + keys = {} + @cfg.map.each do |key, want_position| + want_positions = want_position.split('.') + keys[key.to_sym] = node_var_interpolate node.dig(*want_positions) + end + keys[:model] = map_model keys[:model] if keys.has_key? :model + + # map node specific vars + vars = {} + @cfg.vars_map.each do |key, want_position| + want_positions = want_position.split('.') + vars[key.to_sym] = node_var_interpolate node.dig(*want_positions) + end + keys[:vars] = vars unless vars.empty? + + nodes << keys + end + nodes end - nodes end - -end end if RUBY_VERSION < '2.3' -- cgit v1.2.1 From c65bbfe28eaafa21e7660b51758fafcdafc42bab Mon Sep 17 00:00:00 2001 From: Neil Lathwood Date: Fri, 27 Apr 2018 10:55:47 +0100 Subject: travis fixes --- lib/oxidized/source/http.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/oxidized/source/http.rb') diff --git a/lib/oxidized/source/http.rb b/lib/oxidized/source/http.rb index 6d7dce3..55dcd4c 100644 --- a/lib/oxidized/source/http.rb +++ b/lib/oxidized/source/http.rb @@ -15,7 +15,7 @@ module Oxidized require "uri" require "json" - def load node_want=nil + def load node_want = nil nodes = [] uri = URI.parse(@cfg.url) http = Net::HTTP.new(uri.host, uri.port) -- cgit v1.2.1