summaryrefslogtreecommitdiff
path: root/lib/oxidized
diff options
context:
space:
mode:
Diffstat (limited to 'lib/oxidized')
-rw-r--r--lib/oxidized/cli.rb2
-rw-r--r--lib/oxidized/config.rb1
-rw-r--r--lib/oxidized/model/acos.rb22
-rw-r--r--lib/oxidized/model/catos.rb36
-rw-r--r--lib/oxidized/model/comware.rb2
-rw-r--r--lib/oxidized/model/iosxr.rb2
-rw-r--r--lib/oxidized/model/ironware.rb1
-rw-r--r--lib/oxidized/model/mlnxos.rb43
-rw-r--r--lib/oxidized/model/procurve.rb2
-rw-r--r--lib/oxidized/output/git.rb30
-rw-r--r--lib/oxidized/version.rb2
11 files changed, 124 insertions, 19 deletions
diff --git a/lib/oxidized/cli.rb b/lib/oxidized/cli.rb
index 0594dcb..9a09d41 100644
--- a/lib/oxidized/cli.rb
+++ b/lib/oxidized/cli.rb
@@ -24,7 +24,7 @@ module Oxidized
Config.load(@opts)
Oxidized.setup_logger
- @pidfile = File.join(Oxidized::Config::Root, 'pid')
+ @pidfile = File.expand_path(Oxidized.config.pid)
end
def crash error
diff --git a/lib/oxidized/config.rb b/lib/oxidized/config.rb
index 7884625..1797be6 100644
--- a/lib/oxidized/config.rb
+++ b/lib/oxidized/config.rb
@@ -30,6 +30,7 @@ module Oxidized
asetus.default.rest = '127.0.0.1:8888' # or false to disable
asetus.default.vars = {} # could be 'enable'=>'enablePW'
asetus.default.groups = {} # group level configuration
+ asetus.default.pid = File.join(Oxidized::Config::Root, 'pid')
asetus.default.input.default = 'ssh, telnet'
asetus.default.input.debug = false # or String for session log file
diff --git a/lib/oxidized/model/acos.rb b/lib/oxidized/model/acos.rb
index 75fbacf..7db8b00 100644
--- a/lib/oxidized/model/acos.rb
+++ b/lib/oxidized/model/acos.rb
@@ -1,5 +1,5 @@
class ACOS < Oxidized::Model
- # A10 ACOS model for AX and Thunder series
+ # A10 ACOS model for AX and Thunder series
comment '! '
@@ -17,10 +17,14 @@ class ACOS < Oxidized::Model
cmd 'show running-config all-partitions'
cmd 'show aflex all-partitions' do |cfg|
+ comment cfg
+ end
+
+ cmd 'show aflex all-partitions' do |cfg|
@partitions_aflex = cfg.lines.each_with_object({}) do |l,h|
h[$1] = [] if l.match /partition: (.+)/
# only consider scripts that have passed syntax check
- h[h.keys.last] << $1 if l.match /^([\w-]+) +Check/
+ h[h.keys.last] << $1 if l.match /^([\w-]+) +Check/
end
''
end
@@ -52,18 +56,18 @@ class ACOS < Oxidized::Model
username /login:/
password /^Password:/
end
-
+
cfg :telnet, :ssh do
# preferred way to handle additional passwords
- if vars :enable
- post_login do
- send "enable\n"
- send vars(:enable) + "\n"
- end
+ post_login do
+ pw = vars(:enable)
+ pw ||= ""
+ send "enable\r\n"
+ cmd pw
end
post_login 'terminal length 0'
post_login 'terminal width 0'
- pre_logout "exit\nexit\ny"
+ pre_logout "exit\nexit\nY\r\n"
end
end
diff --git a/lib/oxidized/model/catos.rb b/lib/oxidized/model/catos.rb
new file mode 100644
index 0000000..874ebbc
--- /dev/null
+++ b/lib/oxidized/model/catos.rb
@@ -0,0 +1,36 @@
+class Catos < Oxidized::Model
+
+ prompt /^[\w.@-]+> \(enable\) $/
+ comment '# '
+
+ cmd :all do |cfg|
+ cfg.each_line.to_a[1..-2].join
+ end
+
+ cmd 'show system' do |cfg|
+ cfg = cfg.gsub /(\s+)\d+,\d+:\d+:\d+(\s+)/, '\1X\2'
+ comment cfg
+ end
+
+ cmd 'show version' do |cfg|
+ cfg = cfg.gsub /\d+(K)/, 'X\1'
+ cfg = cfg.gsub /^(Uptime is ).*/, '\1X'
+ comment cfg
+ end
+
+ cmd 'show conf all' do |cfg|
+ cfg = cfg.sub /^(#time: ).*/, '\1X'
+ cfg.each_line.drop_while { |line| not line.match /^begin/ }.join
+ end
+
+ cfg :telnet do
+ username /^Username: /
+ password /^Password:/
+ end
+
+ cfg :ssh, :telnet do
+ post_login 'set length 0'
+ pre_logout 'exit'
+ end
+
+end
diff --git a/lib/oxidized/model/comware.rb b/lib/oxidized/model/comware.rb
index 9b36e8b..27b70ae 100644
--- a/lib/oxidized/model/comware.rb
+++ b/lib/oxidized/model/comware.rb
@@ -13,6 +13,8 @@ class Comware < Oxidized::Model
cmd :all do |cfg|
#cfg.gsub! /^.*\e\[42D/, '' # example how to handle pager
+ #skip rogue ^M
+ cfg = cfg.gsub /\r/, ''
cfg.each_line.to_a[1..-2].join
end
diff --git a/lib/oxidized/model/iosxr.rb b/lib/oxidized/model/iosxr.rb
index a622b66..bf01140 100644
--- a/lib/oxidized/model/iosxr.rb
+++ b/lib/oxidized/model/iosxr.rb
@@ -30,7 +30,7 @@ class IOSXR < Oxidized::Model
cfg :telnet do
username /^Username:/
- password /^Password:/
+ password /^\r?Password:/
end
cfg :telnet, :ssh do
diff --git a/lib/oxidized/model/ironware.rb b/lib/oxidized/model/ironware.rb
index 55b6e57..1e8c30e 100644
--- a/lib/oxidized/model/ironware.rb
+++ b/lib/oxidized/model/ironware.rb
@@ -23,6 +23,7 @@ class IronWare < Oxidized::Model
cmd 'show version' do |cfg|
cfg.gsub! /(^((.*)[Ss]ystem uptime(.*))$)/, '' #remove unwanted line system uptime
+ cfg.gsub! /(^((.*)[Tt]he system started at(.*))$)/, ''
cfg.gsub! /[Uu]p\s?[Tt]ime is .*/,''
comment cfg
diff --git a/lib/oxidized/model/mlnxos.rb b/lib/oxidized/model/mlnxos.rb
new file mode 100644
index 0000000..9542c88
--- /dev/null
+++ b/lib/oxidized/model/mlnxos.rb
@@ -0,0 +1,43 @@
+class MLNXOS < Oxidized::Model
+
+ prompt /([\w.@()-\[:\s\]]+[#>]\s)$/
+ comment '## '
+
+ # Pager Handling
+ expect /.+lines\s\d+\-\d+([\s]|\/\d+\s\(END\)\s).+$/ do |data, re|
+ send ' '
+ data.sub re, ''
+ end
+
+ cmd :all do |cfg|
+ cfg.gsub! /\[\?1h=\r/, '' # Pager Handling
+ cfg.gsub! /\r\[K/,'' # Pager Handling
+ cfg.gsub! /\s/, '' # Linebreak Handling
+ cfg = cfg.lines.to_a[2..-3].join
+ end
+
+ cmd :secret do |cfg|
+ cfg.gsub! /(snmp-server community).*/, ' <snmp-server community configuration removed>'
+ cfg.gsub! /username (\S+) password (\d+) (\S+).*/, '<secret hidden>'
+ cfg
+ end
+
+ cmd 'show version' do |cfg|
+ comment cfg
+ end
+
+ cmd 'show inventory' do |cfg|
+ comment cfg
+ end
+
+ cmd 'enable'
+
+ cmd 'show running-config' do |cfg|
+ cfg
+ end
+
+ cfg :ssh do
+ password /^Password:\s*/
+ pre_logout 'exit'
+ end
+end
diff --git a/lib/oxidized/model/procurve.rb b/lib/oxidized/model/procurve.rb
index e667f48..392f510 100644
--- a/lib/oxidized/model/procurve.rb
+++ b/lib/oxidized/model/procurve.rb
@@ -2,7 +2,7 @@ class Procurve < Oxidized::Model
# some models start lines with \r
# previous command is repeated followed by "\eE", which sometimes ends up on last line
- prompt /^\r?([\w -]+\eE)?([\w-]+# )$/
+ prompt /^\r?([\w -]+\eE)?([\w.-]+# )$/
comment '! '
diff --git a/lib/oxidized/output/git.rb b/lib/oxidized/output/git.rb
index 8b605f6..8d9dae1 100644
--- a/lib/oxidized/output/git.rb
+++ b/lib/oxidized/output/git.rb
@@ -21,7 +21,14 @@ class Git < Output
Oxidized.asetus.save :user
raise NoConfig, 'no output git config, edit ~/.config/oxidized/config'
end
- @cfg.repo = File.expand_path @cfg.repo
+
+ if @cfg.repo.respond_to?(:each)
+ @cfg.repo.each do |group, repo|
+ @cfg.repo["#{group}="] = File.expand_path repo
+ end
+ else
+ @cfg.repo = File.expand_path @cfg.repo
+ end
end
def store file, outputs, opt={}
@@ -70,7 +77,10 @@ class Git < Output
def version node, group
begin
repo = @cfg.repo
- if group
+ path = node
+ if group and @cfg.single_repo?
+ path = "#{group}/#{node}"
+ elsif group
repo = File.join File.dirname(repo), group + '.git'
end
repo = Rugged::Repository.new repo
@@ -80,7 +90,7 @@ class Git < Output
i = -1
tab = []
walker.each do |commit|
- if commit.diff(paths: [node]).size > 0
+ if commit.diff(paths: [path]).size > 0
hash = {}
hash[:date] = commit.time.to_s
hash[:oid] = commit.oid
@@ -100,8 +110,10 @@ class Git < Output
def get_version node, group, oid
begin
repo = @cfg.repo
- if group && group != ''
+ if group && group != '' && !@cfg.single_repo?
repo = File.join File.dirname(repo), group + '.git'
+ elsif group && group != ''
+ node = File.join group, node
end
repo = Rugged::Repository.new repo
repo.blob_at(oid,node).content
@@ -115,7 +127,7 @@ class Git < Output
begin
repo = @cfg.repo
diff_commits = nil
- if group && group != ''
+ if group && group != '' && !@cfg.single_repo?
repo = File.join File.dirname(repo), group + '.git'
end
repo = Rugged::Repository.new repo
@@ -147,13 +159,19 @@ class Git < Output
def update repo, file, data
return if data.empty?
+
if @opt[:group]
if @cfg.single_repo?
file = File.join @opt[:group], file
else
- repo = File.join File.dirname(repo), @opt[:group] + '.git'
+ repo = if repo.is_a?(::String)
+ File.join File.dirname(repo), @opt[:group] + '.git'
+ else
+ repo[@opt[:group]]
+ end
end
end
+
begin
repo = Rugged::Repository.new repo
update_repo repo, file, data, @msg, @user, @email
diff --git a/lib/oxidized/version.rb b/lib/oxidized/version.rb
index cc69b85..428cd19 100644
--- a/lib/oxidized/version.rb
+++ b/lib/oxidized/version.rb
@@ -1,3 +1,3 @@
module Oxidized
- VERSION = '0.13.1'
+ VERSION = '0.14.3'
end