summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/oxidized/input/input.rb2
-rw-r--r--lib/oxidized/input/ssh.rb6
-rw-r--r--lib/oxidized/input/telnet.rb6
-rw-r--r--lib/oxidized/model/asa.rb2
-rw-r--r--lib/oxidized/model/eos.rb8
-rw-r--r--lib/oxidized/model/junos.rb2
-rw-r--r--lib/oxidized/model/powerconnect.rb27
-rw-r--r--lib/oxidized/model/routeros.rb17
-rw-r--r--lib/oxidized/output/file.rb1
-rw-r--r--lib/oxidized/output/git.rb1
10 files changed, 62 insertions, 10 deletions
diff --git a/lib/oxidized/input/input.rb b/lib/oxidized/input/input.rb
index a7fb16d..da8ff5d 100644
--- a/lib/oxidized/input/input.rb
+++ b/lib/oxidized/input/input.rb
@@ -1,4 +1,5 @@
module Oxidized
+ class PromptUndetect < OxidizedError; end
class Input
include Oxidized::Config::Vars
@@ -8,6 +9,7 @@ module Oxidized
],
:warn => [
IOError,
+ PromptUndetect,
Timeout::Error,
Errno::ECONNRESET,
Errno::EHOSTUNREACH,
diff --git a/lib/oxidized/input/ssh.rb b/lib/oxidized/input/ssh.rb
index 62a31eb..ec33d37 100644
--- a/lib/oxidized/input/ssh.rb
+++ b/lib/oxidized/input/ssh.rb
@@ -26,7 +26,11 @@ module Oxidized
:paranoid => secure
unless @exec
shell_open @ssh
- @username ? shell_login : expect(@node.prompt)
+ begin
+ @username ? shell_login : expect(@node.prompt)
+ rescue Timeout::Error
+ raise PromptUndetect, [ @output, 'not matching configured prompt', @node.prompt ].join(' ')
+ end
end
connected?
end
diff --git a/lib/oxidized/input/telnet.rb b/lib/oxidized/input/telnet.rb
index 62f361e..13fccf7 100644
--- a/lib/oxidized/input/telnet.rb
+++ b/lib/oxidized/input/telnet.rb
@@ -20,7 +20,11 @@ module Oxidized
@telnet.puts @node.auth[:username]
expect password
@telnet.puts @node.auth[:password]
- expect @node.prompt
+ begin
+ expect @node.prompt
+ rescue Timeout::Error
+ raise PromptUndetect, [ 'unable to detect prompt:', @node.prompt ].join(' ')
+ end
end
def connected?
diff --git a/lib/oxidized/model/asa.rb b/lib/oxidized/model/asa.rb
index 8335b1d..d257e9e 100644
--- a/lib/oxidized/model/asa.rb
+++ b/lib/oxidized/model/asa.rb
@@ -23,7 +23,7 @@ class ASA < Oxidized::Model
comment cfg
end
- cmd 'show running-config' do |cfg|
+ cmd 'more system:running-config' do |cfg|
cfg = cfg.each_line.to_a[3..-1].join
cfg.gsub! /^: [^\n]*\n/, ''
cfg
diff --git a/lib/oxidized/model/eos.rb b/lib/oxidized/model/eos.rb
index 58bb5a9..84ef8cb 100644
--- a/lib/oxidized/model/eos.rb
+++ b/lib/oxidized/model/eos.rb
@@ -29,8 +29,11 @@ class EOS < Oxidized::Model
if vars :enable
post_login do
send "enable\n"
- expect /[pP]assword:\s?$/
- send vars(:enable) + "\n"
+ # Interpret enable: true as meaning we won't be prompted for a password
+ unless vars(:enable).is_a? TrueClass
+ expect /[pP]assword:\s?$/
+ send vars(:enable) + "\n"
+ end
expect /^.+[#>]\s?$/
end
post_login 'terminal length 0'
@@ -39,4 +42,3 @@ class EOS < Oxidized::Model
end
end
-
diff --git a/lib/oxidized/model/junos.rb b/lib/oxidized/model/junos.rb
index 70f0956..e43d71a 100644
--- a/lib/oxidized/model/junos.rb
+++ b/lib/oxidized/model/junos.rb
@@ -9,7 +9,7 @@ class JunOS < Oxidized::Model
cmd :all do |cfg|
# we don't need screen-scraping in ssh due to exec
cfg = cfg.lines.to_a[1..-2].join if telnet
- cfg
+ cfg.lines.map { |line| line.rstrip }.join "\n"
end
cmd :secret do |cfg|
diff --git a/lib/oxidized/model/powerconnect.rb b/lib/oxidized/model/powerconnect.rb
index a1fe229..531ad0b 100644
--- a/lib/oxidized/model/powerconnect.rb
+++ b/lib/oxidized/model/powerconnect.rb
@@ -19,9 +19,8 @@ class PowerConnect < Oxidized::Model
end
cmd 'show system' do |cfg|
- cfg = cfg.split("\n").select { |line| not line[/Up\sTime/] }
- cfg = cfg[0..-28]<<" "
- comment cfg.join("\n")
+ @model = $1 if cfg.match /Power[C|c]onnect (\d{4})[P|F]?/
+ clean cfg
end
cmd 'show running-config'
@@ -39,9 +38,31 @@ class PowerConnect < Oxidized::Model
end
end
+ post_login "terminal datadump"
post_login "terminal length 0"
pre_logout "logout"
+ pre_logout "exit"
end
+ def clean cfg
+ out = []
+ skip_block = false
+ cfg.each_line do |line|
+ if line.match /Up\sTime|Temperature|Power Supplies/i
+ # For 34xx, 54xx, 55xx, and 8024F we should skip this block (terminated by a blank line)
+ skip_block = true if @model =~ /^(34|35)(24|48)$|^(54|55)(24|48)$|^8024$/
+ end
+ # If we have lines to skip do this until we reach and empty line
+ if skip_block
+ skip_block = false if /\S/ !~ line
+ next
+ end
+ out << line.strip
+ end
+ out = comment out.join "\n"
+ out << "\n"
+ end
+
+
end
diff --git a/lib/oxidized/model/routeros.rb b/lib/oxidized/model/routeros.rb
new file mode 100644
index 0000000..bd588b7
--- /dev/null
+++ b/lib/oxidized/model/routeros.rb
@@ -0,0 +1,17 @@
+class RouterOS < Oxidized::Model
+ prompt /^\[\w+@\S+\]\s?>\s?$/
+ comment "# "
+
+ cmd '/system routerboard print' do |cfg|
+ comment cfg
+ end
+
+ cmd '/export' do |cfg|
+ cfg = cfg.split("\n").select { |line| not line[/^\#\s\w{3}\/\d{2}\/\d{4}.*$/] }
+ cfg.join("\n") + "\n"
+ end
+
+ cfg :ssh do
+ exec true
+ end
+end
diff --git a/lib/oxidized/output/file.rb b/lib/oxidized/output/file.rb
index 03c878a..38c9917 100644
--- a/lib/oxidized/output/file.rb
+++ b/lib/oxidized/output/file.rb
@@ -33,6 +33,7 @@ class OxidizedFile < Output
IO.readlines File.join(cfg_dir, node)
else
path = Dir.glob File.join(cfg_dir, '**', node) # fetch node in all groups
+ return nil if path[0].nil?
open(path[0], 'r').readlines
end
end
diff --git a/lib/oxidized/output/git.rb b/lib/oxidized/output/git.rb
index d5eb8e7..e9256e8 100644
--- a/lib/oxidized/output/git.rb
+++ b/lib/oxidized/output/git.rb
@@ -99,6 +99,7 @@ class Git < Output
:parents => repo.empty? ? [] : [repo.head.target].compact,
:update_ref => 'HEAD',
)
+ index.write
end
end
end