diff options
-rw-r--r-- | README.md | 5 | ||||
-rwxr-xr-x | extra/oxidized-report-git-commits | 2 | ||||
-rw-r--r-- | lib/oxidized/hook.rb | 1 | ||||
-rw-r--r-- | lib/oxidized/hook/exec.rb | 1 | ||||
-rw-r--r-- | lib/oxidized/model/aen.rb | 20 | ||||
-rw-r--r-- | lib/oxidized/model/coriantgroove.rb | 30 | ||||
-rw-r--r-- | lib/oxidized/model/fortios.rb | 1 | ||||
-rw-r--r-- | lib/oxidized/model/ftos.rb | 2 | ||||
-rw-r--r-- | lib/oxidized/node.rb | 2 | ||||
-rw-r--r-- | lib/oxidized/worker.rb | 23 |
10 files changed, 84 insertions, 3 deletions
@@ -55,10 +55,13 @@ Oxidized is a network device configuration backup tool. It's a RANCID replacemen * A10 Networks * [ACOS](lib/oxidized/model/acos.rb) + * Accedian Performance Elements (NIDs) + * [AEN](lib/oxidized/model/aen.rb) * Alcatel-Lucent * [AOS](lib/oxidized/model/aos.rb) * [AOS7](lib/oxidized/model/aos7.rb) * [ISAM](lib/oxidized/model/isam.rb) + * [SR OS (Formerly TiMOS)](lib/oxidized/model/timos.rb) * Wireless * Alvarion * [BreezeACCESS](lib/oxidized/model/alvarion.rb) @@ -104,6 +107,7 @@ Oxidized is a network device configuration backup tool. It's a RANCID replacemen * Coriant (former Tellabs) * [TMOS (8800)](lib/oxidized/model/corianttmos.rb) * [8600](lib/oxidized/model/coriant8600.rb) + * [Groove](lib/oxidized/model/coriantgroove.rb) * Cumulus * [Linux](lib/oxidized/model/cumulus.rb) * DataCom @@ -901,6 +905,7 @@ Following configuration keys need to be defined for all hooks: * `node_success`: triggered when configuration is succesfully pulled from a node and right before storing the configuration. * `node_fail`: triggered after `retries` amount of failed node pulls. * `post_store`: triggered after node configuration is stored (this is executed only when the configuration has changed). + * `nodes_done`: triggered after finished fetching all nodes. ## Hook type: exec The `exec` hook type allows users to run an arbitrary shell command or a binary when triggered. diff --git a/extra/oxidized-report-git-commits b/extra/oxidized-report-git-commits index db36ecf..193e2cd 100755 --- a/extra/oxidized-report-git-commits +++ b/extra/oxidized-report-git-commits @@ -58,4 +58,4 @@ echo "Git repo: ${OX_REPO_NAME}" echo "Git commit ID: ${OX_REPO_COMMITREF}" echo "" -git --bare --git-dir="${OX_REPO_NAME}" diff --no-color "${OX_REPO_COMMITREF}~1..${OX_REPO_COMMITREF}" +git --bare --git-dir="${OX_REPO_NAME}" show --pretty='' --no-color "${OX_REPO_COMMITREF}" diff --git a/lib/oxidized/hook.rb b/lib/oxidized/hook.rb index 029688d..c27f6fd 100644 --- a/lib/oxidized/hook.rb +++ b/lib/oxidized/hook.rb @@ -23,6 +23,7 @@ class HookManager :node_success, :node_fail, :post_store, + :nodes_done ] attr_reader :registered_hooks diff --git a/lib/oxidized/hook/exec.rb b/lib/oxidized/hook/exec.rb index fa8aff1..a9a5950 100644 --- a/lib/oxidized/hook/exec.rb +++ b/lib/oxidized/hook/exec.rb @@ -71,7 +71,6 @@ class Exec < Oxidized::Hook "OX_NODE_FROM" => ctx.node.from.to_s, "OX_NODE_MSG" => ctx.node.msg.to_s, "OX_NODE_GROUP" => ctx.node.group.to_s, - "OX_EVENT" => ctx.event.to_s, "OX_REPO_COMMITREF" => ctx.commitref.to_s, "OX_REPO_NAME" => ctx.node.repo.to_s, ) diff --git a/lib/oxidized/model/aen.rb b/lib/oxidized/model/aen.rb new file mode 100644 index 0000000..6d87433 --- /dev/null +++ b/lib/oxidized/model/aen.rb @@ -0,0 +1,20 @@ +class AEN < Oxidized::Model + # Accedian + + comment '# ' + + prompt /^([-\w.\/:?\[\]\(\)]+:\s?)$/ + + cmd 'configuration generate-script module all' do |cfg| + cfg + end + + cmd :all do |cfg| + cfg.each_line.to_a[1..-2].join + end + + cfg :ssh do + pre_logout 'exit' + end + +end
\ No newline at end of file diff --git a/lib/oxidized/model/coriantgroove.rb b/lib/oxidized/model/coriantgroove.rb new file mode 100644 index 0000000..4fc44b7 --- /dev/null +++ b/lib/oxidized/model/coriantgroove.rb @@ -0,0 +1,30 @@ +class CoriantGroove < Oxidized::Model + + comment '# ' + + prompt /^(\w+@.*>\s*)$/ + + cmd :all do |cfg| + cfg.each_line.to_a[1..-3].map{|line|line.delete("\r").rstrip}.join("\n") + "\n" + end + + cmd 'show inventory' do |cfg| + cfg = cfg.each_line.to_a[0..-2].join + comment cfg + end + + cmd 'show softwareload' do |cfg| + cfg = cfg.each_line.to_a[0..-2].join + comment cfg + end + + cmd 'show config | display commands' do |cfg| + cfg.each_line.to_a[1..-1].join + end + + cfg :ssh do + post_login 'set -f cli-config cli-columns 65535' + pre_logout 'quit -f' + end + +end diff --git a/lib/oxidized/model/fortios.rb b/lib/oxidized/model/fortios.rb index 2d15aae..605a596 100644 --- a/lib/oxidized/model/fortios.rb +++ b/lib/oxidized/model/fortios.rb @@ -17,6 +17,7 @@ class FortiOS < Oxidized::Model cmd :secret do |cfg| cfg.gsub! /(set (?:passwd|password|secondary-secret|rsso-secret|psksecret|secret|key ENC)).*/, '\\1 <configuration removed>' cfg.gsub! /(set private-key).*-+END ENCRYPTED PRIVATE KEY-*"$/m , '\\1 <configuration removed>' + cfg.gsub! /(IPS Malicious URL Database).*/, '\\1 <configuration removed>' cfg end diff --git a/lib/oxidized/model/ftos.rb b/lib/oxidized/model/ftos.rb index b465271..1c3b8b4 100644 --- a/lib/oxidized/model/ftos.rb +++ b/lib/oxidized/model/ftos.rb @@ -15,6 +15,8 @@ class FTOS < Oxidized::Model end cmd 'show inventory' do |cfg| + # Old versions of FTOS can occasionally return data that triggers encoding errors. + cfg.encode!("UTF-8", :invalid => :replace, :undef => :replace, :replace => "") comment cfg end diff --git a/lib/oxidized/node.rb b/lib/oxidized/node.rb index 8d0d0af..4f9ae54 100644 --- a/lib/oxidized/node.rb +++ b/lib/oxidized/node.rb @@ -8,6 +8,7 @@ module Oxidized attr_reader :name, :ip, :model, :input, :output, :group, :auth, :prompt, :vars, :last, :repo attr_accessor :running, :user, :msg, :from, :stats, :retry alias :running? :running + def initialize opt Oxidized.logger.debug 'resolving DNS for %s...' % opt[:name] # remove the prefix if an IP Address is provided with one as IPAddr converts it to a network address. @@ -217,6 +218,7 @@ module Oxidized end #model + # FIXME: warning: instance variable @model not initialized if Oxidized.config.models.has_key?(@model.class.name.to_s.downcase) if Oxidized.config.models[@model.class.name.to_s.downcase].has_key?(key_str) value = Oxidized.config.models[@model.class.name.to_s.downcase][key_str] diff --git a/lib/oxidized/worker.rb b/lib/oxidized/worker.rb index 80d65cb..dfe9803 100644 --- a/lib/oxidized/worker.rb +++ b/lib/oxidized/worker.rb @@ -3,6 +3,7 @@ module Oxidized require 'oxidized/jobs' class Worker def initialize nodes + @jobs_done = 0 @nodes = nodes @jobs = Jobs.new(Oxidized.config.threads, Oxidized.config.interval, @nodes) @nodes.jobs = @jobs @@ -14,8 +15,9 @@ module Oxidized @jobs.delete_if { |job| ended << job if not job.alive? } ended.each { |job| process job } @jobs.work + while @jobs.size < @jobs.want - Oxidized.logger.debug "lib/oxidized/worker.rb: Jobs #{@jobs.size}, Want: #{@jobs.want}" + Oxidized.logger.debug "lib/oxidized/worker.rb: Jobs running: #{@jobs.size} of #{@jobs.want} - ended: #{@jobs_done} of #{@nodes.size}" # ask for next node in queue non destructive way nextnode = @nodes.first unless nextnode.last.nil? @@ -29,6 +31,8 @@ module Oxidized @jobs.push Job.new node Oxidized.logger.debug "lib/oxidized/worker.rb: Added #{node.name} to the job queue" end + + run_done_hook if is_cycle_finished? Oxidized.logger.debug("lib/oxidized/worker.rb: #{@jobs.size} jobs running in parallel") unless @jobs.empty? end @@ -38,6 +42,8 @@ module Oxidized node.stats.add job @jobs.duration job.time node.running = false + @jobs_done += 1 # needed for worker_done event + if job.status == :success Oxidized.Hooks.handle :node_success, :node => node, :job => job @@ -71,5 +77,20 @@ module Oxidized Oxidized.logger.warn "#{node.name} not found, removed while collecting?" end + private + + def is_cycle_finished? + @jobs_done > 0 && @jobs_done % @nodes.count == 0 + end + + def run_done_hook + Oxidized.logger.debug "lib/oxidized/worker.rb: Running :nodes_done hook" + Oxidized.Hooks.handle :nodes_done + rescue => e + # swallow the hook erros and continue as normal + Oxidized.logger.error "lib/oxidized/worker.rb: #{e.message}" + ensure + @jobs_done = 0 + end end end |