Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect Local auth or SSH auth #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 30 additions & 11 deletions lib/oxidized/input/ssh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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
Expand All @@ -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