From 5a4d2ce1a0380a47e51a9c7aa248e82a5ba5cd39 Mon Sep 17 00:00:00 2001 From: Saku Ytti Date: Sun, 21 Apr 2013 16:37:26 +0300 Subject: Add input method fallback, e.g. if ssh does not work, try telnet --- README.md | 7 +++++-- TODO.md | 5 +---- lib/oxidized/config/bootstrap.rb | 2 +- lib/oxidized/input/ssh.rb | 2 +- lib/oxidized/node.rb | 41 ++++++++++++++++++++++++---------------- 5 files changed, 33 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 237578b..ca7df43 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,13 @@ # Pitch * automatically adds/removes threads to meet configured retrieval interval - * restful API to move node immediately to head-of-queue (maybe trigger from snmp trap or syslog), to be serviced by next spawned thread (GET /nodes/next/$node) + * restful API to move node immediately to head-of-queue + * syslog udp+file example to catch config changg event (ios/junos) and trigger config fetch + * will signal ios/junos user who made change, which output module can (git does) use + * 'git blame' will show for each line who and when the change was made * restful API to reload list of nodes (GET /nodes/reload) # Install - early days, but try to run it and edit ~/.config/oxidized/config + * early days, but try to lib/tst and edit ~/.config/oxidized/config # API ## Input diff --git a/TODO.md b/TODO.md index ff5dc15..b43962b 100644 --- a/TODO.md +++ b/TODO.md @@ -13,6 +13,7 @@ I don't really need it myself, since I don't have platforms where it would be ne * if job ended later than now-iteration have rand(node.size) == 0 to add thread * if now is less than job_ended+iteration same chance to remove thread? * should we try to avoid max threads from being hit? (like maybe non-success thread is pulling average?) + * dont add thread, if even one thread is too much (too few nodes for interval), still must process 'next' request w/o delay # config @@ -32,7 +33,3 @@ use sidekiq? Any benefits? # docs, testing * yard docs * rspec tests - - -# input method fallback - * ssh, with telnet fallback diff --git a/lib/oxidized/config/bootstrap.rb b/lib/oxidized/config/bootstrap.rb index c3ea09d..6d865b5 100644 --- a/lib/oxidized/config/bootstrap.rb +++ b/lib/oxidized/config/bootstrap.rb @@ -12,7 +12,7 @@ module Oxidized CFG.prompt = /^([\w\.\-@]{3,30}[#>]\s?)$/ CFG.rest = 8888 CFG.input = { - :default => 'ssh', + :default => 'ssh, telnet', } CFG.output = { :default => 'git', diff --git a/lib/oxidized/input/ssh.rb b/lib/oxidized/input/ssh.rb index 45c89ba..3471eea 100644 --- a/lib/oxidized/input/ssh.rb +++ b/lib/oxidized/input/ssh.rb @@ -12,7 +12,7 @@ module Oxidized begin @ssh = Net::SSH.start @node.ip, @node.auth[:username], :password => @node.auth[:password], :timeout => CFG.timeout - rescue Timeout::Error, Net::SSH::Disconnect + rescue Timeout::Error, Net::SSH::Disconnect, Errno::ECONNREFUSED return false end @ses = open_shell @ssh unless @exec 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 -- cgit v1.2.1