From f9d1dbf5092907aa6b485392b0997677f1402963 Mon Sep 17 00:00:00 2001 From: Bitency Date: Mon, 29 Aug 2016 09:26:28 +0200 Subject: [PATCH] Detect Local auth or SSH auth Quick and dirty fix for detect Local auth or SSH auth. First do a local authentication (most of the times hit) then trying SSH authentication. Works now with Dell 8124F switches. --- lib/oxidized/input/ssh.rb | 41 ++++++++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/lib/oxidized/input/ssh.rb b/lib/oxidized/input/ssh.rb index cd12167d2..222cbee51 100644 --- a/lib/oxidized/input/ssh.rb +++ b/lib/oxidized/input/ssh.rb @@ -42,9 +42,24 @@ def connect node unless @exec shell_open @ssh begin - @username ? shell_login : expect(@node.prompt) + + $errcnt = 0 #err Count + + # Attempt Auth AS local auth (most of the time): + expect username + cmd @node.auth[:username], password + cmd @node.auth[:password] + rescue Timeout::Error - raise PromptUndetect, [ @output, 'not matching configured prompt', @node.prompt ].join(' ') + + # Attempt Auth AS SSH auth if local auth failed: + if $errcnt > 0 + raise PromptUndetect, [ @output, '{$errcnt} inIF not matching configured prompt', @node.prompt ].join(' ') + else + expect @node.prompt + $errcnt+=1 + end + end end connected? @@ -106,11 +121,12 @@ def shell_open ssh # success, it always opens shell and then run auth in shell. I guess # they'll never support exec() :) def shell_login - expect username - cmd @node.auth[:username], password - cmd @node.auth[:password] + # not needed?? + end + + def exec state=nil state == nil ? @exec : (@exec=state) unless vars :ssh_no_exec end @@ -123,14 +139,17 @@ def cmd_shell(cmd, expect_re) @output end + def expect regexp - Oxidized.logger.debug "lib/oxidized/input/ssh.rb: expecting #{regexp.inspect} at #{node.name}" - Timeout::timeout(Oxidized.config.timeout) do + Oxidized.logger.debug "lib/oxidized/input/ssh.rb: expecting #{regexp.inspect} at #{node.name}" + Timeout::timeout(Oxidized.config.timeout) do @ssh.loop(0.1) do - sleep 0.1 - not @output.match regexp + sleep 0.1 + not @output.match regexp end - end - end + end + end + + end end