oxidized-ssh 0.1.2.1 → 0.1.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b5eb0a4dc218d5fccfe56a5f13f2c38bd9e59853
4
- data.tar.gz: 779d692e5d09167e25cde4d88050fbc4f4aee186
3
+ metadata.gz: b18031bbbc9ee47891b6021cfeb63260348bd705
4
+ data.tar.gz: fa02a18838c054605a00a4f26f884d76f9e5efe0
5
5
  SHA512:
6
- metadata.gz: bf731536ad899827c49ea3599ce47e29c434bbf10a6cfa99b18a0c58e9c909a122240ee6ab61ddff9a7a4ea120a853373ec3b8bb91fcc1b2f32d9d428530b859
7
- data.tar.gz: 696696aa68b44a25253f0c25e8155f8344628ed9dc8cb2c975b90a5cb2705baf28cefa57eb69003404e464c0f71f3361f4b48e64861becbb2f282437d0971dc0
6
+ metadata.gz: 60677583298cbd23ea1d910422670c2e2b77d997b67cb956d3f00cab3f2feb25b1ad67a3b9dfa32181908d06a8becdf0105c4c9b5a48519d4602904666e08b10
7
+ data.tar.gz: f2ea26f9d2a16497a02cb233037daf38039ee99a720897b5c4131ed2eeae66f1b36384b8e77045cdd31f5f4ff0f3bfdf2deaf5bf8e50b3191d300b4ac44842e1
@@ -1,5 +1,5 @@
1
1
  module Oxidized
2
2
  module Ssh
3
- VERSION = "0.1.2.1"
3
+ VERSION = "0.1.2.3"
4
4
  end
5
5
  end
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, :verbosity, :exec, :pty_options
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
- @verbosity = options[:verbosity]
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: @verbosity, port: @port)
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
- @output.gsub(/\r\n/,"\n")
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
- # @logger.debug "received #{data}"
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oxidized-ssh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2.1
4
+ version: 0.1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Schylar