diff options
author | Saku Ytti <saku@ytti.fi> | 2013-04-21 16:37:26 +0300 |
---|---|---|
committer | Saku Ytti <saku@ytti.fi> | 2013-04-21 16:37:26 +0300 |
commit | 5a4d2ce1a0380a47e51a9c7aa248e82a5ba5cd39 (patch) | |
tree | 8fd0cf55b019bae2244a413dd774846cea5920ae /lib/oxidized/node.rb | |
parent | f1287a7925901bf3518eb69079304bfb97f7434d (diff) |
Add input method fallback, e.g. if ssh does not work, try telnet
Diffstat (limited to 'lib/oxidized/node.rb')
-rw-r--r-- | lib/oxidized/node.rb | 41 |
1 files changed, 25 insertions, 16 deletions
diff --git a/lib/oxidized/node.rb b/lib/oxidized/node.rb index 35a5948..a41fcdc 100644 --- a/lib/oxidized/node.rb +++ b/lib/oxidized/node.rb @@ -10,7 +10,8 @@ module Oxidized @name = opt[:name] @ip = Resolv.getaddress @name @group = opt[:group] - @input, @output = resolve_io opt + @input = resolve_input opt + @output = resolve_output opt @model = resolve_model opt @auth = resolve_auth opt @prompt = resolve_prompt opt @@ -18,12 +19,15 @@ module Oxidized def run status, config = :fail, nil - @model.input = input = @input.new - if input.connect self - config = input.get - status = :success if config - else - status = :no_cconnection + @input.each do |input| + @model.input = input = input.new + if input.connect self + config = input.get + status = :success if config + break + else + status = :no_cconnection + end end [status, config] end @@ -66,17 +70,22 @@ module Oxidized auth end - def resolve_io opt - input = (opt[:input] or CFG.input[:default]) - output = (opt[:output] or CFG.output[:default]) - mgr = Oxidized.mgr - if not mgr.input[input] - mgr.input = input or raise MethodNotFound, "#{input} not found" + def resolve_input opt + inputs = (opt[:input] or CFG.input[:default]) + inputs.split(/\s*,\s*/).map do |input| + if not Oxidized.mgr.input[input] + Oxidized.mgr.input = input or raise MethodNotFound, "#{input} not found" + end + Oxidized.mgr.input[input] end - if not mgr.output[output] - mgr.output = output or raise MethodNotFound, "#{output} not found" + end + + def resolve_output opt + output = (opt[:output] or CFG.output[:default]) + if not Oxidized.mgr.output[output] + Oxidized.mgr.output = output or raise MethodNotFound, "#{output} not found" end - [ mgr.input[input], mgr.output[output] ] + Oxidized.mgr.output[output] end def resolve_model opt |