7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/jerakia/datasource/http.rb', line 7
def run
Jerakia.log.debug("Searching key #{lookup.request.key} using the http datasource (#{whoami})")
option :host, { :type => String, :mandatory => true }
option :port, { :type => Integer, :default => 80 }
option :output, { :type => String, :default => 'json' }
option :failure, { :type => String, :default => 'graceful' }
option :ignore_404, { :default => true }
option :headers, { :type => Hash }
option :http_read_timeout, { :type => Integer }
option :use_ssl
option :ssl_ca_cert, { :type => String }
option :ssl_cert, { :type => String }
option :ssl_key, { :type => String }
option :ssl_verify
option :use_auth
option :auth_user, { :type => String }
option :auth_pass, { :type => String }
option :http_connect_timeout,{ :type => Integer }
option :paths, { :type => Array, :mandatory => true }
lookup_supported_params = [
:host,
:port,
:output,
:failure,
:ignore_404,
:headers,
:http_connect_timeout,
:http_read_timeout,
:use_ssl,
:ssl_ca_cert,
:ssl_cert,
:ssl_key,
:ssl_verify,
:use_auth,
:auth_user,
:auth_pass,
]
lookup_params = options.select { |p| lookup_supported_params.include?(p) }
http_lookup = LookupHttp.new(lookup_params)
options[:paths].flatten.each do |path|
Jerakia.log.debug("Attempting to load data from #{path}")
return unless response.want?
data=http_lookup.get_parsed(path)
Jerakia.log.debug("Datasource provided #{data} looking for key #{lookup.request.key}")
if data[lookup.request.key]
Jerakia.log.debug("Found data #{data[lookup.request.key]}")
response.submit data[lookup.request.key]
end
end
end
|