summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaku Ytti <saku@ytti.fi>2016-08-29 14:27:57 +0300
committerSaku Ytti <saku@ytti.fi>2016-08-29 17:48:38 +0300
commitdbab46d5f8228f8dd56bbca2e63405e818c598f9 (patch)
treeb3968268edd2bc38ba63c9543f85b13330fb00b4
parent6332dedddc75e0c44fe2fd19994b5080a7818cd1 (diff)
support terminal and ssh auth for same model
Some boxes like prokurwa may authenticate via SSH (proper), or may have no auth on SSH and use terminal auth (improper) Even if SSH is configured for terminal auth, in this change we attempt to detect prompt, so that we won't expect terminal auth, even when requested, if it is not presented.
-rw-r--r--lib/oxidized/input/ssh.rb31
1 files changed, 20 insertions, 11 deletions
diff --git a/lib/oxidized/input/ssh.rb b/lib/oxidized/input/ssh.rb
index cd12167..c0b7cf9 100644
--- a/lib/oxidized/input/ssh.rb
+++ b/lib/oxidized/input/ssh.rb
@@ -42,7 +42,7 @@ module Oxidized
unless @exec
shell_open @ssh
begin
- @username ? shell_login : expect(@node.prompt)
+ login
rescue Timeout::Error
raise PromptUndetect, [ @output, 'not matching configured prompt', @node.prompt ].join(' ')
end
@@ -102,13 +102,18 @@ module Oxidized
end
end
- # Cisco WCS has extremely dubious SSH implementation, SSH auth is always
- # 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]
+ # some models have SSH auth or terminal auth based on version of code
+ # if SSH is configured for terminal auth, we'll still try to detect prompt
+ def login
+ if @username
+ match = expect username, @node.prompt
+ if match == username
+ cmd @node.auth[:username], password
+ cmd @node.auth[:password]
+ end
+ else
+ expect @node.prompt
+ end
end
def exec state=nil
@@ -123,14 +128,18 @@ module Oxidized
@output
end
- def expect regexp
- Oxidized.logger.debug "lib/oxidized/input/ssh.rb: expecting #{regexp.inspect} at #{node.name}"
+ def expect *regexps
+ regexps = [regexps].flatten
+ Oxidized.logger.debug "lib/oxidized/input/ssh.rb: expecting #{regexps.inspect} at #{node.name}"
Timeout::timeout(Oxidized.config.timeout) do
@ssh.loop(0.1) do
sleep 0.1
- not @output.match regexp
+ match = regexps.find { |regexp| @output.match regexp }
+ return match if match
+ true
end
end
end
+
end
end