oxidized-ssh 0.1.2.1 → 0.1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/oxidized/ssh/version.rb +1 -1
- data/lib/oxidized/ssh.rb +15 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b18031bbbc9ee47891b6021cfeb63260348bd705
|
4
|
+
data.tar.gz: fa02a18838c054605a00a4f26f884d76f9e5efe0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60677583298cbd23ea1d910422670c2e2b77d997b67cb956d3f00cab3f2feb25b1ad67a3b9dfa32181908d06a8becdf0105c4c9b5a48519d4602904666e08b10
|
7
|
+
data.tar.gz: f2ea26f9d2a16497a02cb233037daf38039ee99a720897b5c4131ed2eeae66f1b36384b8e77045cdd31f5f4ff0f3bfdf2deaf5bf8e50b3191d300b4ac44842e1
|
data/lib/oxidized/ssh/version.rb
CHANGED
data/lib/oxidized/ssh.rb
CHANGED
@@ -7,14 +7,15 @@ module Oxidized
|
|
7
7
|
class SSH
|
8
8
|
|
9
9
|
attr_reader :connection, :ip, :username, :password
|
10
|
-
attr_reader :prompt, :
|
10
|
+
attr_reader :prompt, :debug, :exec, :pty_options
|
11
11
|
attr_reader :port, :output, :session
|
12
12
|
|
13
13
|
def initialize(options)
|
14
14
|
@ip = options[:ip]
|
15
15
|
@username = options[:username]
|
16
16
|
@password = options[:password]
|
17
|
-
@
|
17
|
+
@verbose = options[:verbose]
|
18
|
+
@debug = options[:debug]
|
18
19
|
@prompt = options[:prompt]
|
19
20
|
@exec = options[:exec]
|
20
21
|
@pty_options = options[:pty_options] ||= { term: "vt100" }
|
@@ -26,7 +27,7 @@ module Oxidized
|
|
26
27
|
|
27
28
|
def start
|
28
29
|
raise "MissingSSHLibrary" if !defined? Net::SSH
|
29
|
-
@connection = Net::SSH.start(@ip, @username, password: @password, verbose: @
|
30
|
+
@connection = Net::SSH.start(@ip, @username, password: @password, verbose: @verbose, port: @port)
|
30
31
|
return yield self if block_given?
|
31
32
|
return (@connection and not @connection.closed?)
|
32
33
|
end
|
@@ -34,7 +35,9 @@ module Oxidized
|
|
34
35
|
def exec!(params)
|
35
36
|
check_for_connection
|
36
37
|
exec(params)
|
37
|
-
|
38
|
+
sanitize_output_buffer("\n", /\r\n/)
|
39
|
+
sanitize_output_buffer('', @prompt, params)
|
40
|
+
@output
|
38
41
|
end
|
39
42
|
|
40
43
|
def check_for_connection
|
@@ -42,7 +45,7 @@ module Oxidized
|
|
42
45
|
end
|
43
46
|
|
44
47
|
def exec(params)
|
45
|
-
@logger.debug "sending command #{params} with expectation of #{@prompt}"
|
48
|
+
@logger.debug "sending command #{params} with expectation of #{@prompt}" if @debug
|
46
49
|
if @exec
|
47
50
|
@connection.exec!(params)
|
48
51
|
else
|
@@ -70,7 +73,7 @@ module Oxidized
|
|
70
73
|
|
71
74
|
def expect *regexps
|
72
75
|
regexps = [regexps].flatten
|
73
|
-
@logger.debug "expecting #{regexps.inspect} at #{@ip}"
|
76
|
+
@logger.debug "expecting #{regexps.inspect} at #{@ip}" if @debug
|
74
77
|
@connection.loop(0.1) do
|
75
78
|
sleep 0.1
|
76
79
|
match = regexps.find { |regexp| @output.match regexp }
|
@@ -101,7 +104,7 @@ module Oxidized
|
|
101
104
|
|
102
105
|
def set_data_hook(ch)
|
103
106
|
ch.on_data do |_ch, data|
|
104
|
-
|
107
|
+
@logger.debug "received #{data}" if @debug
|
105
108
|
@output << data
|
106
109
|
@output = expectation_list_handler(@output) if @expectation_handler
|
107
110
|
end
|
@@ -127,6 +130,11 @@ module Oxidized
|
|
127
130
|
@output = ''
|
128
131
|
end
|
129
132
|
|
133
|
+
def sanitize_output_buffer sub, *regexs
|
134
|
+
@logger.debug "sanitizing #{regexs.join("|")} with #{sub}" if @debug
|
135
|
+
@output.gsub!(/#{regexs.join("|")}/, sub)
|
136
|
+
end
|
137
|
+
|
130
138
|
def disconnect
|
131
139
|
Timeout::timeout(5) { @connection.loop }
|
132
140
|
rescue Errno::ECONNRESET, Net::SSH::Disconnect, IOError
|