diff options
Diffstat (limited to 'lib/oxidized')
| -rw-r--r-- | lib/oxidized/config.rb | 5 | ||||
| -rw-r--r-- | lib/oxidized/model/nxos.rb | 8 | ||||
| -rw-r--r-- | lib/oxidized/nodes.rb | 3 | ||||
| -rw-r--r-- | lib/oxidized/source/http.rb | 29 | ||||
| -rw-r--r-- | lib/oxidized/worker.rb | 5 | 
5 files changed, 39 insertions, 11 deletions
| diff --git a/lib/oxidized/config.rb b/lib/oxidized/config.rb index b6b5c40..aba8b63 100644 --- a/lib/oxidized/config.rb +++ b/lib/oxidized/config.rb @@ -28,8 +28,9 @@ module Oxidized        asetus.default.retries       = 3        asetus.default.prompt        = /^([\w.@-]+[#>]\s?)$/        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.next_adds_job = false            # if true, /next adds job, so device is fetched immmeiately +      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' diff --git a/lib/oxidized/model/nxos.rb b/lib/oxidized/model/nxos.rb index fbe772d..e743415 100644 --- a/lib/oxidized/model/nxos.rb +++ b/lib/oxidized/model/nxos.rb @@ -3,6 +3,14 @@ class NXOS < Oxidized::Model    prompt /^(\r?[\w.@_()-]+[#]\s?)$/    comment '! ' +  cmd :secret do |cfg| +    cfg.gsub! /^(snmp-server community).*/, '\\1 <configuration removed>' +    cfg.gsub! /^(snmp-server user (\S+) (\S+) auth (\S+)) (\S+) (priv) (\S+)/, '\\1 <configuration removed> ' +    cfg.gsub! /^(username \S+ password \d) (\S+)/, '\\1 <secret hidden>' +    cfg.gsub! /^(radius-server key).*/, '\\1 <secret hidden>' +    cfg +  end +      cmd 'show version' do |cfg|      cfg = cfg.each_line.take_while { |line| not line.match(/uptime/i) }      comment cfg.join "" diff --git a/lib/oxidized/nodes.rb b/lib/oxidized/nodes.rb index f5a1ad0..6751c7a 100644 --- a/lib/oxidized/nodes.rb +++ b/lib/oxidized/nodes.rb @@ -4,7 +4,7 @@ module Oxidized    class Oxidized::NotSupported < OxidizedError; end    class Oxidized::NodeNotFound < OxidizedError; end    class Nodes < Array -    attr_accessor :source +    attr_accessor :source, :jobs      alias :put :unshift      def load node_want=nil        with_lock do @@ -73,6 +73,7 @@ module Oxidized            # set last job to nil so that the node is picked for immediate update            n.last = nil            put n +          jobs.want += 1 if Oxidized.config.next_adds_job?          end        end      end diff --git a/lib/oxidized/source/http.rb b/lib/oxidized/source/http.rb index 4fd388b..7186f98 100644 --- a/lib/oxidized/source/http.rb +++ b/lib/oxidized/source/http.rb @@ -35,19 +35,21 @@ class HTTP < Source      response = http.request(request)      data = JSON.parse(response.body) -    data.each do |line| -      next if line.empty? +    data.each do |node| +      next if node.empty?        # map node parameters        keys = {} -      @cfg.map.each do |key, position| -        keys[key.to_sym] = node_var_interpolate line[position] +      @cfg.map.each do |key, want_position| +        want_positions = want_position.split('.') +        keys[key.to_sym] = node_var_interpolate node.dig(*want_positions)        end        keys[:model] = map_model keys[:model] if keys.key? :model        # map node specific vars        vars = {} -      @cfg.vars_map.each do |key, position| -        vars[key.to_sym] = node_var_interpolate line[position] +      @cfg.vars_map.each do |key, want_position| +        want_positions = want_position.split('.') +        vars[key.to_sym] = node_var_interpolate node.dig(*want_positions)        end        keys[:vars] = vars unless vars.empty? @@ -58,3 +60,18 @@ class HTTP < Source  end  end + +if RUBY_VERSION < '2.3' +  class Hash +    def dig(key, *rest) +      value = self[key] +      if value.nil? || rest.empty? +        value +      elsif value.respond_to?(:dig) +        value.dig(*rest) +      else # foo.bar.baz (bar exist but is not hash) +        return nil +      end +    end +  end +end diff --git a/lib/oxidized/worker.rb b/lib/oxidized/worker.rb index 1952d01..80d65cb 100644 --- a/lib/oxidized/worker.rb +++ b/lib/oxidized/worker.rb @@ -3,8 +3,9 @@ module Oxidized    require 'oxidized/jobs'    class Worker      def initialize nodes -      @nodes   = nodes -      @jobs    = Jobs.new(Oxidized.config.threads, Oxidized.config.interval, @nodes) +      @nodes      = nodes +      @jobs       = Jobs.new(Oxidized.config.threads, Oxidized.config.interval, @nodes) +      @nodes.jobs = @jobs        Thread.abort_on_exception = true      end | 
