oxidized 0.15.0 → 0.16.0

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: a5dd4172e3c9577bfb601bc1d88378abf9540179
4
- data.tar.gz: 57dcd79de9f7303ad54031a33b51579d6f33882a
3
+ metadata.gz: ebfd90e4c9c182e28f85e2563cd28af4dd952477
4
+ data.tar.gz: 4d37d169505e9f479e6a27431bc6d7de017e14a1
5
5
  SHA512:
6
- metadata.gz: 41682a4c5ff7978340c21e7255ffdc1b9fe25615db8977b0bd027045fa9849bb4be6edd401b7e6776e54be497714188b3d3ec1d74909a596a1d945945cc1c6c0
7
- data.tar.gz: e63697ab95faad315a36b6bfb6e0be416aaae3a4c7d2433f371f85914b0ec658ab13bf7ecd58723774902984c1204885dfaa2e82fea6e829c93bd5a46e038360
6
+ metadata.gz: 54da4be2a0fba2af711a0d81ba1696c99618efa4363ee0f586e2fcd0bb309786ef8ae67b38e8ca6353d354b7720d3220a63756bf346ec78aa2ea7c436679ffb8
7
+ data.tar.gz: 65d882b2bf026b7fea33e674413afda46ebd247e0d7cf2e1b48e874986c68839db94a0695438aabd65f2b204b58e1a155b6e9559afe994c5d84558c464d67c55
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 0.16.0
2
+ - FEATURE: support Gaia OS devices (by @totosh)
3
+ - BUGFIX: #fetch, #version fixes in nodes.rb (by @danilopopeye)
4
+ - BUGFIX: procurve
5
+
1
6
  # 0.15.0
2
7
  - FEATURE: disable periodic collection, only on demand (by Adam Winberg)
3
8
  - FEATURE: allow disabling ssh exec mode always (mainly for oxidized-script) (by @nickhilliard)
data/README.md CHANGED
@@ -64,6 +64,8 @@ Oxidized is a network device configuration backup tool. It's a RANCID replacemen
64
64
  * NOS (Network Operating System)
65
65
  * Vyatta
66
66
  * 6910
67
+ * Check Point
68
+ * GaiaOS
67
69
  * Ciena
68
70
  * SOAS
69
71
  * Cisco
data/lib/oxidized.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'fileutils'
2
+
1
3
  module Oxidized
2
4
  class OxidizedError < StandardError; end
3
5
 
@@ -34,6 +36,7 @@ module Oxidized
34
36
  end
35
37
 
36
38
  def self.setup_logger
39
+ FileUtils.mkdir_p(Config::Log) unless File.directory?(Config::Log)
37
40
  self.logger = if config.has_key?('use_syslog') && config.use_syslog
38
41
  require 'syslog/logger'
39
42
  Syslog::Logger.new('oxidized')
@@ -5,7 +5,7 @@ module Oxidized
5
5
  class Config
6
6
  Root = ENV['OXIDIZED_HOME'] || File.join(ENV['HOME'], '.config', 'oxidized')
7
7
  Crash = File.join Root, 'crash'
8
- Log = File.join Root, 'log'
8
+ Log = File.join Root, 'logs'
9
9
  InputDir = File.join Directory, %w(lib oxidized input)
10
10
  OutputDir = File.join Directory, %w(lib oxidized output)
11
11
  ModelDir = File.join Directory, %w(lib oxidized model)
@@ -18,7 +18,7 @@ module Oxidized
18
18
  def connect node
19
19
  @node = node
20
20
  @node.model.cfg['ftp'].each { |cb| instance_exec(&cb) }
21
- @log = File.open(Oxidized::Config::Log + "-#{@node.ip}-ftp", 'w') if Oxidized.config.input.debug?
21
+ @log = File.open(Oxidized::Config::Log + "/#{@node.ip}-ftp", 'w') if Oxidized.config.input.debug?
22
22
  @ftp = Net::FTP.new @node.ip, @node.auth[:username], @node.auth[:password]
23
23
  connected?
24
24
  end
@@ -21,7 +21,7 @@ module Oxidized
21
21
  @output = ''
22
22
  @node.model.cfg['ssh'].each { |cb| instance_exec(&cb) }
23
23
  secure = Oxidized.config.input.ssh.secure
24
- @log = File.open(Oxidized::Config::Log + "-#{@node.ip}-ssh", 'w') if Oxidized.config.input.debug?
24
+ @log = File.open(Oxidized::Config::Log + "/#{@node.ip}-ssh", 'w') if Oxidized.config.input.debug?
25
25
  port = vars(:ssh_port) || 22
26
26
  if proxy_host = vars(:ssh_proxy)
27
27
  proxy = Net::SSH::Proxy::Command.new("ssh #{proxy_host} -W %h:%p")
@@ -16,7 +16,7 @@ module Oxidized
16
16
  'Port' => port.to_i,
17
17
  'Timeout' => @timeout,
18
18
  'Model' => @node.model }
19
- opt['Output_log'] = Oxidized::Config::Log + "-#{@node.ip}-telnet" if Oxidized.config.input.debug?
19
+ opt['Output_log'] = Oxidized::Config::Log + "/#{@node.ip}-telnet" if Oxidized.config.input.debug?
20
20
 
21
21
  @telnet = Net::Telnet.new opt
22
22
  if @node.auth[:username] and @node.auth[:username].length > 0
@@ -0,0 +1,46 @@
1
+ class GaiaOS < Oxidized::Model
2
+
3
+ # CheckPoint - Gaia OS Model
4
+
5
+ # Gaia Prompt
6
+ prompt /^([\[\]\w.@:-]+[#>]\s?)$/
7
+
8
+ # Comment tag
9
+ comment '# '
10
+
11
+
12
+ cmd :all do |cfg|
13
+ cfg = cfg.each_line.to_a[1..-2].join
14
+ end
15
+
16
+ cmd :secret do |cfg|
17
+ cfg.gsub! /^(set expert-password-hash ).*/, '\1<EXPERT PASSWORD REMOVED>'
18
+ cfg.gsub! /^(set user \S+ password-hash ).*/,'\1<USER PASSWORD REMOVED>'
19
+ cfg.gsub! /^(set ospf .* secret ).*/,'\1<OSPF KEY REMOVED>'
20
+ cfg.gsub! /^(set snmp community )(.*)( read-only.*)/,'\1<SNMP COMMUNITY REMOVED>\3'
21
+ cfg.gsub! /^(add snmp .* community )(.*)(\S?.*)/,'\1<SNMP COMMUNITY REMOVED>\3'
22
+ cfg.gsub! /(auth|privacy)(-pass-phrase-hashed )(\S*)/,'\1-pass-phrase-hashed <SNMP PASS-PHRASE REMOVED>'
23
+ cfg
24
+ end
25
+
26
+ cmd 'show asset all' do |cfg|
27
+ comment cfg
28
+ end
29
+
30
+ cmd 'show version all' do |cfg|
31
+ comment cfg
32
+ end
33
+
34
+ cmd 'show configuration' do |cfg|
35
+ cfg.gsub! /^# Exported by \S+ on .*/, '# '
36
+ cfg
37
+ end
38
+
39
+
40
+ cfg :ssh do
41
+ # User shell must be /etc/cli.sh
42
+ post_login 'set clienv rows 0'
43
+ pre_logout 'exit'
44
+ end
45
+
46
+ end
@@ -11,7 +11,7 @@ class Procurve < Oxidized::Model
11
11
  data.gsub re, ''
12
12
  end
13
13
 
14
- expect /Press any key to continue/ do
14
+ expect /Press any key to continue(\e\[\??\d+(;\d+)*[A-Za-z])*$/ do
15
15
  send ' '
16
16
  ""
17
17
  end
data/lib/oxidized/node.rb CHANGED
@@ -174,8 +174,12 @@ module Oxidized
174
174
  def resolve_repo
175
175
  remote_repo = Oxidized.config.output.git.repo
176
176
 
177
- if Oxidized.config.output.git.single_repo? || @group.nil? || remote_repo.is_a?(String)
178
- remote_repo
177
+ if remote_repo.is_a?(::String)
178
+ if Oxidized.config.output.git.single_repo? || @group.nil?
179
+ remote_repo
180
+ else
181
+ File.join(File.dirname(remote_repo), @group + '.git')
182
+ end
179
183
  else
180
184
  remote_repo[@group]
181
185
  end
@@ -56,11 +56,8 @@ module Oxidized
56
56
  end
57
57
  end
58
58
 
59
- def fetch node, group
60
- with_lock do
61
- i = find_node_index node
62
- output = self[i].output.new
63
- raise Oxidized::NotSupported unless output.respond_to? :fetch
59
+ def fetch node_name, group
60
+ yield_node_output(node_name) do |node, output|
64
61
  output.fetch node, group
65
62
  end
66
63
  end
@@ -94,6 +91,24 @@ module Oxidized
94
91
  find_index node or raise Oxidized::NodeNotFound, "unable to find '#{node}'"
95
92
  end
96
93
 
94
+ def version node_name, group
95
+ yield_node_output(node_name) do |node, output|
96
+ output.version node, group
97
+ end
98
+ end
99
+
100
+ def get_version node_name, group, oid
101
+ yield_node_output(node_name) do |node, output|
102
+ output.get_version node, group, oid
103
+ end
104
+ end
105
+
106
+ def get_diff node_name, group, oid1, oid2
107
+ yield_node_output(node_name) do |node, output|
108
+ output.get_diff node, group, oid1, oid2
109
+ end
110
+ end
111
+
97
112
  private
98
113
 
99
114
  def initialize opts={}
@@ -151,34 +166,13 @@ module Oxidized
151
166
  sort_by! { |x| x.last.nil? ? Time.new(0) : x.last.end }
152
167
  end
153
168
 
154
- public
155
-
156
- def version node, group
169
+ def yield_node_output(node_name)
157
170
  with_lock do
158
- i = find_node_index node
159
- output = self[i].output.new
171
+ node = find { |n| n.name == node_name }
172
+ output = node.output.new
160
173
  raise Oxidized::NotSupported unless output.respond_to? :fetch
161
- output.version node, group
162
- end
163
- end
164
-
165
- def get_version node, group, oid
166
- with_lock do
167
- i = find_node_index node
168
- output = self[i].output.new
169
- raise Oxidized::NotSupported unless output.respond_to? :fetch
170
- output.get_version node, group, oid
174
+ yield node, output
171
175
  end
172
176
  end
173
-
174
- def get_diff node, group, oid1, oid2
175
- with_lock do
176
- i = find_node_index node
177
- output = self[i].output.new
178
- raise Oxidized::NotSupported unless output.respond_to? :fetch
179
- output.get_diff node, group, oid1, oid2
180
- end
181
- end
182
-
183
177
  end
184
178
  end
@@ -41,7 +41,7 @@ class Git < Output
41
41
 
42
42
  outputs.types.each do |type|
43
43
  type_cfg = ''
44
- type_repo = File.join File.dirname(repo), type + '.git'
44
+ puts type_repo = File.join(File.dirname(repo), type + '.git')
45
45
  outputs.type(type).each do |output|
46
46
  (type_cfg << output; next) if not output.name
47
47
  type_file = file + '--' + output.name
@@ -60,29 +60,21 @@ class Git < Output
60
60
 
61
61
  def fetch node, group
62
62
  begin
63
- repo = @cfg.repo
64
- repo = File.join File.dirname(repo), group + '.git' if group and not @cfg.single_repo?
63
+ repo, path = yield_repo_and_path(node, group)
65
64
  repo = Rugged::Repository.new repo
66
65
  index = repo.index
67
66
  index.read_tree repo.head.target.tree unless repo.empty?
68
- file = node
69
- file = File.join(group, node) if group and @cfg.single_repo?
70
- repo.read(index.get(file)[:oid]).data
67
+ repo.read(index.get(path)[:oid]).data
71
68
  rescue
72
69
  'node not found'
73
70
  end
74
71
  end
75
72
 
76
- #give a hash of all oid revision for the given node, and the date of the commit
73
+ # give a hash of all oid revision for the given node, and the date of the commit
77
74
  def version node, group
78
75
  begin
79
- repo = @cfg.repo
80
- path = node
81
- if group and @cfg.single_repo?
82
- path = "#{group}/#{node}"
83
- elsif group
84
- repo = File.join File.dirname(repo), group + '.git'
85
- end
76
+ repo, path = yield_repo_and_path(node, group)
77
+
86
78
  repo = Rugged::Repository.new repo
87
79
  walker = Rugged::Walker.new(repo)
88
80
  walker.sorting(Rugged::SORT_DATE)
@@ -109,14 +101,9 @@ class Git < Output
109
101
  #give the blob of a specific revision
110
102
  def get_version node, group, oid
111
103
  begin
112
- repo = @cfg.repo
113
- if group && group != '' && !@cfg.single_repo?
114
- repo = File.join File.dirname(repo), group + '.git'
115
- elsif group && group != ''
116
- node = File.join group, node
117
- end
104
+ repo, path = yield_repo_and_path(node, group)
118
105
  repo = Rugged::Repository.new repo
119
- repo.blob_at(oid,node).content
106
+ repo.blob_at(oid,path).content
120
107
  rescue
121
108
  'version not found'
122
109
  end
@@ -125,30 +112,27 @@ class Git < Output
125
112
  #give a hash with the patch of a diff between 2 revision and the stats (added and deleted lines)
126
113
  def get_diff node, group, oid1, oid2
127
114
  begin
128
- repo = @cfg.repo
129
115
  diff_commits = nil
130
- if group && group != '' && !@cfg.single_repo?
131
- repo = File.join File.dirname(repo), group + '.git'
132
- end
116
+ repo, _ = yield_repo_and_path(node, group)
133
117
  repo = Rugged::Repository.new repo
134
118
  commit = repo.lookup(oid1)
135
- #if the second revision is precised
119
+
136
120
  if oid2
137
121
  commit_old = repo.lookup(oid2)
138
122
  diff = repo.diff(commit_old, commit)
139
123
  diff.each do |patch|
140
- if /#{node}\s+/.match(patch.to_s.lines.first)
124
+ if /#{node.name}\s+/.match(patch.to_s.lines.first)
141
125
  diff_commits = {:patch => patch.to_s, :stat => patch.stat}
142
126
  break
143
127
  end
144
128
  end
145
- #else gives the diffs between the first oid and his first parrent
146
129
  else
147
130
  stat = commit.parents[0].diff(commit).stat
148
131
  stat = [stat[1],stat[2]]
149
132
  patch = commit.parents[0].diff(commit).patch
150
133
  diff_commits = {:patch => patch, :stat => stat}
151
134
  end
135
+
152
136
  diff_commits
153
137
  rescue
154
138
  'no diffs'
@@ -157,6 +141,16 @@ class Git < Output
157
141
 
158
142
  private
159
143
 
144
+ def yield_repo_and_path(node, group)
145
+ repo, path = node.repo, node.name
146
+
147
+ if group and @cfg.single_repo?
148
+ path = "#{group}/#{node.name}"
149
+ end
150
+
151
+ [repo, path]
152
+ end
153
+
160
154
  def update repo, file, data
161
155
  return if data.empty?
162
156
 
@@ -1,3 +1,3 @@
1
1
  module Oxidized
2
- VERSION = '0.15.0'
2
+ VERSION = '0.16.0'
3
3
  end
data/oxidized.gemspec CHANGED
@@ -23,6 +23,11 @@ Gem::Specification.new do |s|
23
23
  s.add_runtime_dependency 'slop', '~> 3.5'
24
24
  s.add_runtime_dependency 'net-ssh', '>= 3.0.0', '<3.1'
25
25
  s.add_runtime_dependency 'rugged', '~> 0.21', '>= 0.21.4'
26
+
27
+ if defined?(RUBY_VERSION) && RUBY_VERSION > '2.3'
28
+ s.add_runtime_dependency 'net-telnet'
29
+ end
30
+
26
31
  s.add_development_dependency 'pry', '~> 0'
27
32
  s.add_development_dependency 'bundler', '~> 1.10'
28
33
  s.add_development_dependency 'rake', '~> 10.0'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oxidized
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.0
4
+ version: 0.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Saku Ytti
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-07-11 00:00:00.000000000 Z
13
+ date: 2016-07-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: asetus
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.21.4
83
+ - !ruby/object:Gem::Dependency
84
+ name: net-telnet
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: pry
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -224,6 +238,7 @@ files:
224
238
  - lib/oxidized/model/firewareos.rb
225
239
  - lib/oxidized/model/fortios.rb
226
240
  - lib/oxidized/model/ftos.rb
241
+ - lib/oxidized/model/gaiaos.rb
227
242
  - lib/oxidized/model/ios.rb
228
243
  - lib/oxidized/model/iosxr.rb
229
244
  - lib/oxidized/model/ipos.rb