Class: Oxidized::HTTP
Instance Attribute Summary
Attributes included from Input::CLI
#node
Instance Method Summary
collapse
Methods included from Input::CLI
#connect_cli, #disconnect_cli, #get, #login, #password, #post_login, #pre_logout, #username
Methods inherited from Source
#map_model, #node_var_interpolate
Constructor Details
#initialize ⇒ HTTP
Returns a new instance of HTTP.
3
4
5
6
|
# File 'lib/oxidized/source/http.rb', line 3
def initialize
@cfg = Oxidized.config.source.http
super
end
|
Instance Method Details
#cmd(callback) ⇒ Object
25
26
27
|
# File 'lib/oxidized/input/http.rb', line 25
def cmd callback
instance_exec(&callback)
end
|
#connect(node) ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/oxidized/input/http.rb', line 13
def connect node
@node = node
@m = Mechanize.new
@log = File.open(Oxidized::Config::Log + "/#{@node.ip}-http", "w") if Oxidized.config.input.debug?
@node.model.cfg["http"].each { |cb| instance_exec(&cb) }
url = URI::HTTP.build host: @node.ip, path: @main_page
@m_page = @m.get(url.to_s)
login
end
|
#load(node_want = nil) ⇒ Object
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
|
# File 'lib/oxidized/source/http.rb', line 19
def load node_want = nil
nodes = []
data = JSON.parse(read_http(node_want))
data = string_navigate(data, @cfg.hosts_location) if @cfg.hosts_location?
data.each do |node|
next if node.empty?
keys = {}
@cfg.map.each do |key, want_position|
keys[key.to_sym] = node_var_interpolate string_navigate(node, want_position)
end
keys[:model] = map_model keys[:model] if keys.has_key? :model
vars = {}
@cfg.vars_map.each do |key, want_position|
vars[key.to_sym] = node_var_interpolate string_navigate(node, want_position)
end
keys[:vars] = vars unless vars.empty?
nodes << keys
end
nodes
end
|
#setup ⇒ Object
8
9
10
11
12
|
# File 'lib/oxidized/source/http.rb', line 8
def setup
if @cfg.url.empty?
raise NoConfig, 'no source http url config, edit ~/.config/oxidized/config'
end
end
|