summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSaku Ytti <saku@ytti.fi>2018-06-22 18:45:59 +0300
committerSaku Ytti <saku@ytti.fi>2018-06-22 18:45:59 +0300
commitc0cb572d98708716dc3241e0d73f91143f887b65 (patch)
tree83777b05a06ac4fc76beffe9f3afbb56ceba1b93 /lib
parentee2a575054e3d8f44b6ea92974a22ebb455dc770 (diff)
remove SSH::connect smell
Diffstat (limited to 'lib')
-rw-r--r--lib/oxidized/input/ssh.rb59
1 files changed, 31 insertions, 28 deletions
diff --git a/lib/oxidized/input/ssh.rb b/lib/oxidized/input/ssh.rb
index 0bc846f..ef92ef6 100644
--- a/lib/oxidized/input/ssh.rb
+++ b/lib/oxidized/input/ssh.rb
@@ -21,37 +21,10 @@ module Oxidized
@output = ''
@pty_options = { term: "vt100" }
@node.model.cfg['ssh'].each { |cb| instance_exec(&cb) }
- secure = Oxidized.config.input.ssh.secure
@log = File.open(Oxidized::Config::Log + "/#{@node.ip}-ssh", 'w') if Oxidized.config.input.debug?
- port = vars(:ssh_port) || 22
-
- ssh_opts = {
- port: port.to_i,
- paranoid: secure,
- keepalive: true,
- password: @node.auth[:password], :timeout => Oxidized.config.timeout,
- number_of_password_prompts: 0,
- }
-
- auth_methods = vars(:auth_methods) || %w(none publickey password)
- ssh_opts[:auth_methods] = auth_methods
- Oxidized.logger.debug "AUTH METHODS::#{auth_methods}"
-
- if proxy_host = vars(:ssh_proxy)
- proxy_command = "ssh "
- proxy_command += "-o StrictHostKeyChecking=no " unless secure
- proxy_command += "#{proxy_host} -W %h:%p"
- proxy = Net::SSH::Proxy::Command.new(proxy_command)
- ssh_opts[:proxy] = proxy
- end
-
- ssh_opts[:keys] = [vars(:ssh_keys)].flatten if vars(:ssh_keys)
- ssh_opts[:kex] = vars(:ssh_kex).split(/,\s*/) if vars(:ssh_kex)
- ssh_opts[:encryption] = vars(:ssh_encryption).split(/,\s*/) if vars(:ssh_encryption)
- ssh_opts[:verbose] = Logger::DEBUG if Oxidized.config.input.debug?
Oxidized.logger.debug "lib/oxidized/input/ssh.rb: Connecting to #{@node.name}"
- @ssh = Net::SSH.start(@node.ip, @node.auth[:username], ssh_opts)
+ @ssh = Net::SSH.start(@node.ip, @node.auth[:username], get_ssh_opts)
unless @exec
shell_open @ssh
begin
@@ -143,5 +116,35 @@ module Oxidized
end
end
end
+
+ def get_ssh_opts
+ port = vars(:ssh_port) || 22
+ ssh_opts = {
+ port: port.to_i,
+ paranoid: secure,
+ keepalive: true,
+ password: @node.auth[:password], timeout: Oxidized.config.timeout,
+ number_of_password_prompts: 0
+ }
+
+ auth_methods = vars(:auth_methods) || %w(none publickey password)
+ ssh_opts[:auth_methods] = auth_methods
+ Oxidized.logger.debug "AUTH METHODS::#{auth_methods}"
+
+ if proxy_host = vars(:ssh_proxy)
+ proxy_command = "ssh "
+ proxy_command += "-o StrictHostKeyChecking=no " unless Oxidized.config.input.ssh.secure?
+ proxy_command += "#{proxy_host} -W %h:%p"
+ proxy = Net::SSH::Proxy::Command.new(proxy_command)
+ ssh_opts[:proxy] = proxy
+ end
+
+ ssh_opts[:keys] = [vars(:ssh_keys)].flatten if vars(:ssh_keys)
+ ssh_opts[:kex] = vars(:ssh_kex).split(/,\s*/) if vars(:ssh_kex)
+ ssh_opts[:encryption] = vars(:ssh_encryption).split(/,\s*/) if vars(:ssh_encryption)
+ ssh_opts[:verbose] = Logger::DEBUG if Oxidized.config.input.debug?
+
+ ssh_opts
+ end
end
end