From 21e3d6490496573f25ef77fe8172766ac7d1a736 Mon Sep 17 00:00:00 2001 From: Wild Kat Date: Sat, 21 Apr 2018 13:27:05 +0200 Subject: the great makeover - standardize layout, alignment, indentation --- lib/oxidized/cli.rb | 4 +- lib/oxidized/config.rb | 4 +- lib/oxidized/core.rb | 6 +- lib/oxidized/hook.rb | 129 ++++++++++---------- lib/oxidized/hook/awssns.rb | 1 - lib/oxidized/hook/exec.rb | 5 +- lib/oxidized/hook/githubrepo.rb | 13 +- lib/oxidized/hook/slackdiff.rb | 6 +- lib/oxidized/hook/xmppdiff.rb | 18 +-- lib/oxidized/input/cli.rb | 11 +- lib/oxidized/input/ftp.rb | 13 +- lib/oxidized/input/ssh.rb | 25 ++-- lib/oxidized/input/telnet.rb | 48 ++++---- lib/oxidized/jobs.rb | 7 +- lib/oxidized/manager.rb | 9 +- lib/oxidized/model/acos.rb | 31 +++-- lib/oxidized/model/acsw.rb | 11 +- lib/oxidized/model/aen.rb | 3 +- lib/oxidized/model/aireos.rb | 8 +- lib/oxidized/model/alteonos.rb | 34 +++--- lib/oxidized/model/alvarion.rb | 4 - lib/oxidized/model/aos.rb | 6 +- lib/oxidized/model/aos7.rb | 5 +- lib/oxidized/model/aosw.rb | 24 ++-- lib/oxidized/model/apc_aos.rb | 3 - lib/oxidized/model/arbos.rb | 5 +- lib/oxidized/model/aricentiss.rb | 2 - lib/oxidized/model/asa.rb | 66 +++++----- lib/oxidized/model/asyncos.rb | 39 +++--- lib/oxidized/model/audiocodes.rb | 12 +- lib/oxidized/model/awplus.rb | 79 ++++++------ lib/oxidized/model/boss.rb | 7 +- lib/oxidized/model/br6910.rb | 88 +++++++------- lib/oxidized/model/c4cmts.rb | 8 +- lib/oxidized/model/catos.rb | 2 - lib/oxidized/model/cisconga.rb | 4 +- lib/oxidized/model/ciscosma.rb | 37 +++--- lib/oxidized/model/ciscosmb.rb | 8 +- lib/oxidized/model/comware.rb | 12 +- lib/oxidized/model/coriant8600.rb | 8 +- lib/oxidized/model/coriantgroove.rb | 8 +- lib/oxidized/model/corianttmos.rb | 4 +- lib/oxidized/model/cumulus.rb | 58 ++++----- lib/oxidized/model/datacom.rb | 2 - lib/oxidized/model/dcnos.rb | 2 - lib/oxidized/model/dlink.rb | 2 +- lib/oxidized/model/dnos.rb | 8 +- lib/oxidized/model/edgecos.rb | 6 +- lib/oxidized/model/edgeos.rb | 2 - lib/oxidized/model/edgeswitch.rb | 4 +- lib/oxidized/model/enterasys.rb | 4 +- lib/oxidized/model/eos.rb | 14 +-- lib/oxidized/model/fabricos.rb | 8 +- lib/oxidized/model/firewareos.rb | 3 - lib/oxidized/model/fortios.rb | 28 ++--- lib/oxidized/model/ftos.rb | 6 +- lib/oxidized/model/fujitsupy.rb | 6 +- lib/oxidized/model/gaiaos.rb | 16 +-- lib/oxidized/model/gcombnps.rb | 19 ++- lib/oxidized/model/hatteras.rb | 13 +- lib/oxidized/model/hirschmann.rb | 18 ++- lib/oxidized/model/hpebladesystem.rb | 32 ++--- lib/oxidized/model/hpemsa.rb | 3 - lib/oxidized/model/ios.rb | 108 ++++++++--------- lib/oxidized/model/iosxr.rb | 4 +- lib/oxidized/model/ipos.rb | 4 +- lib/oxidized/model/ironware.rb | 27 ++--- lib/oxidized/model/isam.rb | 9 +- lib/oxidized/model/junos.rb | 10 +- lib/oxidized/model/masteros.rb | 4 +- lib/oxidized/model/mlnxos.rb | 7 +- lib/oxidized/model/model.rb | 21 ++-- lib/oxidized/model/mtrlrfs.rb | 5 +- lib/oxidized/model/ndms.rb | 1 - lib/oxidized/model/netgear.rb | 2 - lib/oxidized/model/netscaler.rb | 2 - lib/oxidized/model/nos.rb | 4 +- lib/oxidized/model/nxos.rb | 5 +- lib/oxidized/model/oneos.rb | 14 +-- lib/oxidized/model/opengear.rb | 6 +- lib/oxidized/model/opnsense.rb | 8 +- lib/oxidized/model/outputs.rb | 4 +- lib/oxidized/model/panos.rb | 3 +- lib/oxidized/model/pfsense.rb | 8 +- lib/oxidized/model/planet.rb | 20 ++- lib/oxidized/model/powerconnect.rb | 9 +- lib/oxidized/model/procurve.rb | 4 +- lib/oxidized/model/quantaos.rb | 8 +- lib/oxidized/model/routeros.rb | 4 +- lib/oxidized/model/saos.rb | 1 - lib/oxidized/model/screenos.rb | 8 +- lib/oxidized/model/sgos.rb | 5 +- lib/oxidized/model/siklu.rb | 2 - lib/oxidized/model/slxos.rb | 26 ++-- lib/oxidized/model/sros.rb | 1 - lib/oxidized/model/tmos.rb | 4 +- lib/oxidized/model/tplink.rb | 18 ++- lib/oxidized/model/trango.rb | 13 +- lib/oxidized/model/ucs.rb | 1 - lib/oxidized/model/voltaire.rb | 9 +- lib/oxidized/model/voss.rb | 3 +- lib/oxidized/model/vrp.rb | 7 +- lib/oxidized/model/vyatta.rb | 4 +- lib/oxidized/model/weos.rb | 4 +- lib/oxidized/model/xos.rb | 6 +- lib/oxidized/model/zhoneolt.rb | 2 +- lib/oxidized/model/zynos.rb | 4 +- lib/oxidized/node.rb | 19 ++- lib/oxidized/node/stats.rb | 3 +- lib/oxidized/nodes.rb | 13 +- lib/oxidized/output/file.rb | 83 +++++++------ lib/oxidized/output/git.rb | 228 +++++++++++++++++------------------ lib/oxidized/output/gitcrypt.rb | 27 ++--- lib/oxidized/output/http.rb | 50 ++++---- lib/oxidized/output/output.rb | 3 +- lib/oxidized/source/csv.rb | 89 +++++++------- lib/oxidized/source/http.rb | 97 ++++++++------- lib/oxidized/source/source.rb | 13 +- lib/oxidized/source/sql.rb | 103 ++++++++-------- lib/oxidized/string.rb | 5 +- lib/oxidized/worker.rb | 2 +- 121 files changed, 1017 insertions(+), 1208 deletions(-) (limited to 'lib/oxidized') diff --git a/lib/oxidized/cli.rb b/lib/oxidized/cli.rb index 9a09d41..c29e269 100644 --- a/lib/oxidized/cli.rb +++ b/lib/oxidized/cli.rb @@ -40,7 +40,7 @@ module Oxidized end def parse_opts - opts = Slop.new(:help=>true) do + opts = Slop.new(:help => true) do on 'd', 'debug', 'turn on debugging' on 'daemonize', 'Daemonize/fork the process' on 'v', 'version', 'show version' do @@ -62,7 +62,7 @@ module Oxidized def write_pid if pidfile? begin - File.open(pidfile, ::File::CREAT | ::File::EXCL | ::File::WRONLY){|f| f.write("#{Process.pid}") } + File.open(pidfile, ::File::CREAT | ::File::EXCL | ::File::WRONLY) { |f| f.write("#{Process.pid}") } at_exit { File.delete(pidfile) if File.exists?(pidfile) } rescue Errno::EEXIST check_pid diff --git a/lib/oxidized/config.rb b/lib/oxidized/config.rb index 47544fb..a825d39 100644 --- a/lib/oxidized/config.rb +++ b/lib/oxidized/config.rb @@ -13,7 +13,7 @@ module Oxidized HookDir = File.join Directory, %w(lib oxidized hook) Sleep = 1 - def self.load(cmd_opts={}) + def self.load(cmd_opts = {}) asetus = Asetus.new(name: 'oxidized', load: false, key_to_s: true) Oxidized.asetus = asetus @@ -37,7 +37,7 @@ module Oxidized asetus.default.input.default = 'ssh, telnet' asetus.default.input.debug = false # or String for session log file asetus.default.input.ssh.secure = false # complain about changed certs - asetus.default.input.ftp.passive= true # ftp passive mode + asetus.default.input.ftp.passive = true # ftp passive mode asetus.default.output.default = 'file' # file, git asetus.default.source.default = 'csv' # csv, sql diff --git a/lib/oxidized/core.rb b/lib/oxidized/core.rb index e007c9d..440d8e2 100644 --- a/lib/oxidized/core.rb +++ b/lib/oxidized/core.rb @@ -11,9 +11,9 @@ module Oxidized def initialize args Oxidized.mgr = Manager.new Oxidized.Hooks = HookManager.from_config(Oxidized.config) - nodes = Nodes.new + nodes = Nodes.new raise NoNodesFound, 'source returns no usable nodes' if nodes.size == 0 - @worker = Worker.new nodes + @worker = Worker.new nodes trap('HUP') { nodes.load } if Oxidized.config.rest? begin @@ -22,7 +22,7 @@ module Oxidized raise OxidizedError, 'oxidized-web not found: sudo gem install oxidized-web - \ or disable web support by setting "rest: false" in your configuration' end - @rest = API::Web.new nodes, Oxidized.config.rest + @rest = API::Web.new nodes, Oxidized.config.rest @rest.run end run diff --git a/lib/oxidized/hook.rb b/lib/oxidized/hook.rb index c27f6fd..915299b 100644 --- a/lib/oxidized/hook.rb +++ b/lib/oxidized/hook.rb @@ -1,89 +1,88 @@ module Oxidized -class HookManager - class << self - def from_config cfg - mgr = new - cfg.hooks.each do |name,h_cfg| - h_cfg.events.each do |event| - mgr.register event.to_sym, name, h_cfg.type, h_cfg + class HookManager + class << self + def from_config cfg + mgr = new + cfg.hooks.each do |name, h_cfg| + h_cfg.events.each do |event| + mgr.register event.to_sym, name, h_cfg.type, h_cfg + end end + mgr end - mgr end - end - - # HookContext is passed to each hook. It can contain anything related to the - # event in question. At least it contains the event name - class HookContext < OpenStruct; end - # RegisteredHook is a container for a Hook instance - class RegisteredHook < Struct.new(:name, :hook); end + # HookContext is passed to each hook. It can contain anything related to the + # event in question. At least it contains the event name + class HookContext < OpenStruct; end - Events = [ - :node_success, - :node_fail, - :post_store, - :nodes_done - ] - attr_reader :registered_hooks + # RegisteredHook is a container for a Hook instance + class RegisteredHook < Struct.new(:name, :hook); end - def initialize - @registered_hooks = Hash.new {|h,k| h[k] = []} - end + Events = [ + :node_success, + :node_fail, + :post_store, + :nodes_done + ] + attr_reader :registered_hooks - def register event, name, hook_type, cfg - unless Events.include? event - raise ArgumentError, - "unknown event #{event}, available: #{Events.join ','}" + def initialize + @registered_hooks = Hash.new { |h, k| h[k] = [] } end - Oxidized.mgr.add_hook hook_type - begin - hook = Oxidized.mgr.hook.fetch(hook_type).new - rescue KeyError - raise KeyError, "cannot find hook #{hook_type.inspect}" - end + def register event, name, hook_type, cfg + unless Events.include? event + raise ArgumentError, + "unknown event #{event}, available: #{Events.join ','}" + end - hook.cfg = cfg + Oxidized.mgr.add_hook hook_type + begin + hook = Oxidized.mgr.hook.fetch(hook_type).new + rescue KeyError + raise KeyError, "cannot find hook #{hook_type.inspect}" + end - @registered_hooks[event] << RegisteredHook.new(name, hook) - Oxidized.logger.debug "Hook #{name.inspect} registered #{hook.class} for event #{event.inspect}" - end + hook.cfg = cfg - def handle event, ctx_params={} - ctx = HookContext.new ctx_params - ctx.event = event + @registered_hooks[event] << RegisteredHook.new(name, hook) + Oxidized.logger.debug "Hook #{name.inspect} registered #{hook.class} for event #{event.inspect}" + end - @registered_hooks[event].each do |r_hook| - begin - r_hook.hook.run_hook ctx - rescue => e - Oxidized.logger.error "Hook #{r_hook.name} (#{r_hook.hook}) failed " + - "(#{e.inspect}) for event #{event.inspect}" + def handle event, ctx_params = {} + ctx = HookContext.new ctx_params + ctx.event = event + + @registered_hooks[event].each do |r_hook| + begin + r_hook.hook.run_hook ctx + rescue => e + Oxidized.logger.error "Hook #{r_hook.name} (#{r_hook.hook}) failed " + + "(#{e.inspect}) for event #{event.inspect}" + end end end end -end -# Hook abstract base class -class Hook - attr_reader :cfg + # Hook abstract base class + class Hook + attr_reader :cfg - def initialize - end + def initialize + end - def cfg=(cfg) - @cfg = cfg - validate_cfg! if self.respond_to? :validate_cfg! - end + def cfg=(cfg) + @cfg = cfg + validate_cfg! if self.respond_to? :validate_cfg! + end - def run_hook ctx - raise NotImplementedError - end + def run_hook ctx + raise NotImplementedError + end - def log(msg, level=:info) - Oxidized.logger.send(level, "#{self.class.name}: #{msg}") + def log(msg, level = :info) + Oxidized.logger.send(level, "#{self.class.name}: #{msg}") + end end - -end end diff --git a/lib/oxidized/hook/awssns.rb b/lib/oxidized/hook/awssns.rb index 82c118e..183cd2c 100644 --- a/lib/oxidized/hook/awssns.rb +++ b/lib/oxidized/hook/awssns.rb @@ -23,5 +23,4 @@ class AwsSns < Oxidized::Hook message: message.to_json ) end - end diff --git a/lib/oxidized/hook/exec.rb b/lib/oxidized/hook/exec.rb index 3f984c2..8a32412 100644 --- a/lib/oxidized/hook/exec.rb +++ b/lib/oxidized/hook/exec.rb @@ -23,10 +23,9 @@ class Exec < Oxidized::Hook @cmd = cfg.cmd raise "invalid cmd value" unless @cmd.is_a?(String) || @cmd.is_a?(Array) end - rescue RuntimeError => e raise ArgumentError, - "#{self.class.name}: configuration invalid: #{e.message}" + "#{self.class.name}: configuration invalid: #{e.message}" end def run_hook ctx @@ -45,7 +44,7 @@ class Exec < Oxidized::Hook def run_cmd! env pid, status = nil, nil Timeout.timeout(@timeout) do - pid = spawn env, @cmd , :unsetenv_others => true + pid = spawn env, @cmd, :unsetenv_others => true pid, status = wait2 pid unless status.exitstatus.zero? msg = "#{@cmd.inspect} failed with exit value #{status.exitstatus}" diff --git a/lib/oxidized/hook/githubrepo.rb b/lib/oxidized/hook/githubrepo.rb index 4cae4e6..e077d5d 100644 --- a/lib/oxidized/hook/githubrepo.rb +++ b/lib/oxidized/hook/githubrepo.rb @@ -35,21 +35,20 @@ class GithubRepo < Oxidized::Hook end Rugged::Commit.create(repo, { - parents: [repo.head.target, their_branch.target], - tree: merge_index.write_tree(repo), - message: "Merge remote-tracking branch '#{their_branch.name}'", - update_ref: "HEAD" - }) + parents: [repo.head.target, their_branch.target], + tree: merge_index.write_tree(repo), + message: "Merge remote-tracking branch '#{their_branch.name}'", + update_ref: "HEAD" + }) end private def credentials Proc.new do |url, username_from_url, allowed_types| - if cfg.has_key?('username') git_user = cfg.username - else + else git_user = username_from_url ? username_from_url : 'git' end diff --git a/lib/oxidized/hook/slackdiff.rb b/lib/oxidized/hook/slackdiff.rb index e271d5f..2c5ec14 100644 --- a/lib/oxidized/hook/slackdiff.rb +++ b/lib/oxidized/hook/slackdiff.rb @@ -14,8 +14,8 @@ class SlackDiff < Oxidized::Hook return unless ctx.event.to_s == "post_store" log "Connecting to slack" Slack.configure do |config| - config.token = cfg.token - config.proxy = cfg.proxy if cfg.has_key?('proxy') + config.token = cfg.token + config.proxy = cfg.proxy if cfg.has_key?('proxy') end client = Slack::Client.new client.auth_test @@ -46,7 +46,7 @@ class SlackDiff < Oxidized::Hook msg = format(cfg.message, :node => ctx.node.name.to_s, :group => ctx.node.group.to_s, :commitref => ctx.commitref, :model => ctx.node.model.class.name.to_s.downcase) log msg log "Posting message to #{cfg.channel}" - client.chat_postMessage(channel: cfg.channel, text: msg, as_user: true) + client.chat_postMessage(channel: cfg.channel, text: msg, as_user: true) end log "Finished" end diff --git a/lib/oxidized/hook/xmppdiff.rb b/lib/oxidized/hook/xmppdiff.rb index 52cc0e0..6acb172 100644 --- a/lib/oxidized/hook/xmppdiff.rb +++ b/lib/oxidized/hook/xmppdiff.rb @@ -30,25 +30,25 @@ class XMPPDiff < Oxidized::Hook sleep 1 client.auth(cfg.password) sleep 1 - + log "Connected" - + m = Jabber::MUC::SimpleMUCClient.new(client) m.join(cfg.channel + "/" + cfg.nick) - + log "Joined" - + title = "#{ctx.node.name} #{ctx.node.group} #{ctx.node.model.class.name.to_s.downcase}" log "Posting diff as snippet to #{cfg.channel}" - + m.say(title + "\n\n" + diff[:patch].lines.to_a[4..-1].join) - + sleep 1 - + client.close - + log "Finished" - + end end rescue Timeout::Error diff --git a/lib/oxidized/input/cli.rb b/lib/oxidized/input/cli.rb index 660e173..d434e33 100644 --- a/lib/oxidized/input/cli.rb +++ b/lib/oxidized/input/cli.rb @@ -32,26 +32,25 @@ module Oxidized @pre_logout.each { |command, block| block ? block.call : (cmd command, nil) } end - def post_login _post_login=nil, &block + def post_login _post_login = nil, &block unless @exec @post_login << [_post_login, block] end end - def pre_logout _pre_logout=nil, &block + def pre_logout _pre_logout = nil, &block unless @exec - @pre_logout << [_pre_logout, block] + @pre_logout << [_pre_logout, block] end end - def username re=/^(Username|login)/ + def username re = /^(Username|login)/ @username or @username = re end - def password re=/^Password/ + def password re = /^Password/ @password or @password = re end - end end end diff --git a/lib/oxidized/input/ftp.rb b/lib/oxidized/input/ftp.rb index cdf3688..ebe50ef 100644 --- a/lib/oxidized/input/ftp.rb +++ b/lib/oxidized/input/ftp.rb @@ -6,22 +6,22 @@ module Oxidized class FTP < Input RescueFail = { :debug => [ - #Net::SSH::Disconnect, + # Net::SSH::Disconnect, ], :warn => [ - #RuntimeError, - #Net::SSH::AuthenticationFailed, + # RuntimeError, + # Net::SSH::AuthenticationFailed, ], } include Input::CLI def connect node - @node = node + @node = node @node.model.cfg['ftp'].each { |cb| instance_exec(&cb) } @log = File.open(Oxidized::Config::Log + "/#{@node.ip}-ftp", 'w') if Oxidized.config.input.debug? @ftp = Net::FTP.new(@node.ip) @ftp.passive = Oxidized.config.input.ftp.passive - @ftp.login @node.auth[:username], @node.auth[:password] + @ftp.login @node.auth[:username], @node.auth[:password] connected? end @@ -47,10 +47,9 @@ module Oxidized def disconnect @ftp.close - #rescue Errno::ECONNRESET, IOError + # rescue Errno::ECONNRESET, IOError ensure @log.close if Oxidized.config.input.debug? end - end end diff --git a/lib/oxidized/input/ssh.rb b/lib/oxidized/input/ssh.rb index 27e81e0..9cb6a4f 100644 --- a/lib/oxidized/input/ssh.rb +++ b/lib/oxidized/input/ssh.rb @@ -24,20 +24,20 @@ module Oxidized secure = Oxidized.config.input.ssh.secure @log = File.open(Oxidized::Config::Log + "/#{@node.ip}-ssh", 'w') if Oxidized.config.input.debug? port = vars(:ssh_port) || 22 - + ssh_opts = { - :port => port.to_i, - :password => @node.auth[:password], :timeout => Oxidized.config.timeout, - :paranoid => secure, - :auth_methods => %w(none publickey password keyboard-interactive), - :number_of_password_prompts => 0, - } + :port => port.to_i, + :password => @node.auth[:password], :timeout => Oxidized.config.timeout, + :paranoid => secure, + :auth_methods => %w(none publickey password keyboard-interactive), + :number_of_password_prompts => 0, + } if proxy_host = vars(:ssh_proxy) proxy_command = "ssh " proxy_command += "-o StrictHostKeyChecking=no " unless secure proxy_command += "#{proxy_host} -W %h:%p" - proxy = Net::SSH::Proxy::Command.new(proxy_command) + proxy = Net::SSH::Proxy::Command.new(proxy_command) ssh_opts[:proxy] = proxy end @@ -52,7 +52,7 @@ module Oxidized begin login rescue Timeout::Error - raise PromptUndetect, [ @output, 'not matching configured prompt', @node.prompt ].join(' ') + raise PromptUndetect, [@output, 'not matching configured prompt', @node.prompt].join(' ') end end connected? @@ -62,7 +62,7 @@ module Oxidized @ssh and not @ssh.closed? end - def cmd cmd, expect=node.prompt + def cmd cmd, expect = node.prompt Oxidized.logger.debug "lib/oxidized/input/ssh.rb #{cmd} @ #{node.name} with expect: #{expect.inspect}" if @exec @ssh.exec! cmd @@ -128,8 +128,8 @@ module Oxidized end end - def exec state=nil - state == nil ? @exec : (@exec=state) unless vars :ssh_no_exec + def exec state = nil + state == nil ? @exec : (@exec = state) unless vars :ssh_no_exec end def cmd_shell(cmd, expect_re) @@ -152,6 +152,5 @@ module Oxidized end end end - end end diff --git a/lib/oxidized/input/telnet.rb b/lib/oxidized/input/telnet.rb index a5561b9..4371e26 100644 --- a/lib/oxidized/input/telnet.rb +++ b/lib/oxidized/input/telnet.rb @@ -18,7 +18,7 @@ module Oxidized 'Model' => @node.model } opt['Output_log'] = Oxidized::Config::Log + "/#{@node.ip}-telnet" if Oxidized.config.input.debug? - @telnet = Net::Telnet.new opt + @telnet = Net::Telnet.new opt if @node.auth[:username] and @node.auth[:username].length > 0 expect username @telnet.puts @node.auth[:username] @@ -28,7 +28,7 @@ module Oxidized begin expect @node.prompt rescue Timeout::Error - raise PromptUndetect, [ 'unable to detect prompt:', @node.prompt ].join(' ') + raise PromptUndetect, ['unable to detect prompt:', @node.prompt].join(' ') end end @@ -36,7 +36,7 @@ module Oxidized @telnet and not @telnet.sock.closed? end - def cmd cmd, expect=@node.prompt + def cmd cmd, expect = @node.prompt Oxidized.logger.debug "Telnet: #{cmd} @#{@node.name}" args = { 'String' => cmd } args.merge!({ 'Match' => expect, 'Timeout' => @timeout }) if expect @@ -64,11 +64,9 @@ module Oxidized rescue Errno::ECONNRESET end end - end end - class Net::Telnet ## FIXME: we just need 'line = model.expects line' to handle pager ## how to do this, without redefining the whole damn thing @@ -86,7 +84,7 @@ class Net::Telnet elsif options.has_key?("Prompt") options["Prompt"] elsif options.has_key?("String") - Regexp.new( Regexp.quote(options["String"]) ) + Regexp.new(Regexp.quote(options["String"])) end time_out = options["Timeout"] if options.has_key?("Timeout") waittime = options["Waittime"] if options.has_key?("Waittime") @@ -102,7 +100,7 @@ class Net::Telnet line = '' buf = '' rest = '' - until(prompt === line and not IO::select([@sock], nil, nil, waittime)) + until prompt === line and not IO::select([@sock], nil, nil, waittime) unless IO::select([@sock], nil, nil, time_out) raise TimeoutError, "timed out while waiting for more data" end @@ -114,30 +112,30 @@ class Net::Telnet c = rest + c if Integer(c.rindex(/#{IAC}#{SE}/no) || 0) < Integer(c.rindex(/#{IAC}#{SB}/no) || 0) - buf = preprocess(c[0 ... c.rindex(/#{IAC}#{SB}/no)]) - rest = c[c.rindex(/#{IAC}#{SB}/no) .. -1] + buf = preprocess(c[0...c.rindex(/#{IAC}#{SB}/no)]) + rest = c[c.rindex(/#{IAC}#{SB}/no)..-1] elsif pt = c.rindex(/#{IAC}[^#{IAC}#{AO}#{AYT}#{DM}#{IP}#{NOP}]?\z/no) || c.rindex(/\r\z/no) - buf = preprocess(c[0 ... pt]) - rest = c[pt .. -1] + buf = preprocess(c[0...pt]) + rest = c[pt..-1] else buf = preprocess(c) rest = '' end - else - # Not Telnetmode. - # - # We cannot use preprocess() on this data, because that - # method makes some Telnetmode-specific assumptions. - buf = rest + c - rest = '' - unless @options["Binmode"] - if pt = buf.rindex(/\r\z/no) - buf = buf[0 ... pt] - rest = buf[pt .. -1] - end - buf.gsub!(/#{EOL}/no, "\n") - end + else + # Not Telnetmode. + # + # We cannot use preprocess() on this data, because that + # method makes some Telnetmode-specific assumptions. + buf = rest + c + rest = '' + unless @options["Binmode"] + if pt = buf.rindex(/\r\z/no) + buf = buf[0...pt] + rest = buf[pt..-1] + end + buf.gsub!(/#{EOL}/no, "\n") + end end @log.print(buf) if @options.has_key?("Output_log") line += buf diff --git a/lib/oxidized/jobs.rb b/lib/oxidized/jobs.rb index c566778..fdc1cbf 100644 --- a/lib/oxidized/jobs.rb +++ b/lib/oxidized/jobs.rb @@ -6,7 +6,7 @@ module Oxidized def initialize max, interval, nodes @max = max - # Set interval to 1 if interval is 0 (=disabled) so we don't break + # Set interval to 1 if interval is 0 (=disabled) so we don't break # the 'ceil' function @interval = interval == 0 ? 1 : interval @nodes = nodes @@ -28,7 +28,7 @@ module Oxidized @durations.fill AVERAGE_DURATION, @durations.size...@nodes.size end @durations.push(last).shift - @duration = @durations.inject(:+).to_f / @nodes.size #rolling average + @duration = @durations.inject(:+).to_f / @nodes.size # rolling average new_count end @@ -45,9 +45,8 @@ module Oxidized # and c) there is more than MAX_INTER_JOB_GAP since last one was started # then we want one more thread (rationale is to fix hanging thread causing HOLB) if @want <= size and @want < @nodes.size - @want +=1 if (Time.now.utc - @last) > MAX_INTER_JOB_GAP + @want += 1 if (Time.now.utc - @last) > MAX_INTER_JOB_GAP end end - end end diff --git a/lib/oxidized/manager.rb b/lib/oxidized/manager.rb index d2ef4d2..c4523f3 100644 --- a/lib/oxidized/manager.rb +++ b/lib/oxidized/manager.rb @@ -7,11 +7,11 @@ module Oxidized class << self def load dir, file begin - require File.join dir, file+'.rb' + require File.join dir, file + '.rb' klass = nil [Oxidized, Object].each do |mod| klass = mod.constants.find { |const| const.to_s.downcase == file.downcase } - klass = mod.constants.find { |const| const.to_s.downcase == 'oxidized'+ file.downcase } unless klass + klass = mod.constants.find { |const| const.to_s.downcase == 'oxidized' + file.downcase } unless klass klass = mod.const_get klass if klass break if klass end @@ -31,16 +31,19 @@ module Oxidized @source = {} @hook = {} end + def add_input method method = Manager.load Config::InputDir, method return false if method.empty? @input.merge! method end + def add_output method method = Manager.load Config::OutputDir, method return false if method.empty? @output.merge! method end + def add_model _model name = _model _model = Manager.load File.join(Config::Root, 'model'), name @@ -48,12 +51,14 @@ module Oxidized return false if _model.empty? @model.merge! _model end + def add_source _source return nil if @source.has_key? _source _source = Manager.load Config::SourceDir, _source return false if _source.empty? @source.merge! _source end + def add_hook _hook return nil if @hook.has_key? _hook name = _hook diff --git a/lib/oxidized/model/acos.rb b/lib/oxidized/model/acos.rb index 47649a2..a2db89c 100644 --- a/lib/oxidized/model/acos.rb +++ b/lib/oxidized/model/acos.rb @@ -3,7 +3,7 @@ class ACOS < Oxidized::Model comment '! ' - ##ACOS prompt changes depending on the state of the device + # ACOS prompt changes depending on the state of the device prompt /^([-\w.\/:?\[\]\(\)]+[#>]\s?)$/ cmd :secret do |cfg| @@ -30,19 +30,19 @@ class ACOS < Oxidized::Model end cmd 'show partition-config all' do |cfg| - cfg.gsub! /(Current configuration).*/, '\\1 ' - cfg.gsub! /(Configuration last updated at).*/, '\\1 ' - cfg.gsub! /(Configuration last saved at).*/, '\\1 ' - cfg.gsub! /(Configuration last synchronized at).*/, '\\1 ' - cfg - end + cfg.gsub! /(Current configuration).*/, '\\1 ' + cfg.gsub! /(Configuration last updated at).*/, '\\1 ' + cfg.gsub! /(Configuration last saved at).*/, '\\1 ' + cfg.gsub! /(Configuration last synchronized at).*/, '\\1 ' + cfg + end cmd 'show running-config all-partitions' do |cfg| - cfg.gsub! /(Current configuration).*/, '\\1 ' - cfg.gsub! /(Configuration last updated at).*/, '\\1 ' - cfg.gsub! /(Configuration last saved at).*/, '\\1 ' - cfg.gsub! /(Configuration last synchronized at).*/, '\\1 ' - cfg + cfg.gsub! /(Current configuration).*/, '\\1 ' + cfg.gsub! /(Configuration last updated at).*/, '\\1 ' + cfg.gsub! /(Configuration last saved at).*/, '\\1 ' + cfg.gsub! /(Configuration last synchronized at).*/, '\\1 ' + cfg end cmd 'show aflex all-partitions' do |cfg| @@ -50,7 +50,7 @@ class ACOS < Oxidized::Model end cmd 'show aflex all-partitions' do |cfg| - @partitions_aflex = cfg.lines.each_with_object({}) do |l,h| + @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/ @@ -66,7 +66,7 @@ class ACOS < Oxidized::Model pre do unless @partitions_aflex.empty? out = [] - @partitions_aflex.each do |partition,arules| + @partitions_aflex.each do |partition, arules| out << "! partition: #{partition}" arules.each do |name| cmd("show aflex #{name} partition #{partition}") do |cfg| @@ -85,7 +85,7 @@ class ACOS < Oxidized::Model username /login:/ password /^Password:/ end - + cfg :telnet, :ssh do # preferred way to handle additional passwords post_login do @@ -98,5 +98,4 @@ class ACOS < Oxidized::Model post_login 'terminal width 0' pre_logout "exit\nexit\nY\r\n" end - end diff --git a/lib/oxidized/model/acsw.rb b/lib/oxidized/model/acsw.rb index 1aee2b6..c0857b3 100644 --- a/lib/oxidized/model/acsw.rb +++ b/lib/oxidized/model/acsw.rb @@ -1,5 +1,4 @@ class ACSW < Oxidized::Model - prompt /([\w.@()\/\\-]+[#>]\s?)/ comment '! ' @@ -25,16 +24,13 @@ class ACSW < Oxidized::Model cfg end - cmd 'show version' do |cfg| comment cfg end - - cmd 'show inventory' do |cfg| - comment cfg - end - + cmd 'show inventory' do |cfg| + comment cfg + end cmd 'show running-config' do |cfg| cfg = cfg.each_line.to_a[3..-1] @@ -63,5 +59,4 @@ class ACSW < Oxidized::Model post_login 'terminal length 0' pre_logout 'exit' end - end diff --git a/lib/oxidized/model/aen.rb b/lib/oxidized/model/aen.rb index 6d87433..474e6d5 100644 --- a/lib/oxidized/model/aen.rb +++ b/lib/oxidized/model/aen.rb @@ -16,5 +16,4 @@ class AEN < Oxidized::Model cfg :ssh do pre_logout 'exit' end - -end \ No newline at end of file +end diff --git a/lib/oxidized/model/aireos.rb b/lib/oxidized/model/aireos.rb index ba13120..a0378c7 100644 --- a/lib/oxidized/model/aireos.rb +++ b/lib/oxidized/model/aireos.rb @@ -1,17 +1,16 @@ class Aireos < Oxidized::Model - # AireOS (at least I think that is what it's called, hard to find data) # Used in Cisco WLC 5500 - comment '# ' ## this complains too, can't find real comment char + comment '# ' # this complains too, can't find real comment char prompt /^\([^\)]+\)\s>/ cmd :all do |cfg| cfg.each_line.to_a[1..-2].join end - ##show sysinfo? - ##show switchconfig? + # show sysinfo? + # show switchconfig? cmd 'show udi' do |cfg| cfg = comment clean cfg @@ -51,5 +50,4 @@ class Aireos < Oxidized::Model out = out.join "\n" out << "\n" end - end diff --git a/lib/oxidized/model/alteonos.rb b/lib/oxidized/model/alteonos.rb index 9eacf4e..dec4faf 100644 --- a/lib/oxidized/model/alteonos.rb +++ b/lib/oxidized/model/alteonos.rb @@ -1,5 +1,4 @@ class ALTEONOS < Oxidized::Model - prompt /^\(?.+\)?\s?[#>]/ comment '! ' @@ -11,19 +10,19 @@ class ALTEONOS < Oxidized::Model cfg end - ############################################################################################## - ## Added to remove # - ## # - ##/* Configuration dump taken 14:10:20 Fri Jul 28, 2017 (DST) # - ##/* Configuration last applied at 16:17:05 Fri Jul 14, 2017 # - ##/* Configuration last save at 16:17:43 Fri Jul 14, 2017 # - ##/* Version 29.0.3.12, vXXXXXXXX, Base MAC address XXXXXXXXXXX # - ##/* To restore SSL Offloading configuration and management HTTPS access, # - ##/* it is recommended to include the private keys in the dump. # - ## OR # - ##/* To restore SSL Offloading configuration and management HTTPS access,it is recommended # - ##/* to include the private keys in the dump. # - ## # + ############################################################################################## + # Added to remove # + # # + # /* Configuration dump taken 14:10:20 Fri Jul 28, 2017 (DST) # + # /* Configuration last applied at 16:17:05 Fri Jul 14, 2017 # + # /* Configuration last save at 16:17:43 Fri Jul 14, 2017 # + # /* Version 29.0.3.12, vXXXXXXXX, Base MAC address XXXXXXXXXXX # + # /* To restore SSL Offloading configuration and management HTTPS access, # + # /* it is recommended to include the private keys in the dump. # + # OR # + # /* To restore SSL Offloading configuration and management HTTPS access,it is recommended # + # /* to include the private keys in the dump. # + # # ############################################################################################## cmd 'cfg/dump' do |cfg| @@ -35,19 +34,19 @@ class ALTEONOS < Oxidized::Model cfg end - #Answer for Dispay private keys + # Answer for Dispay private keys expect /^Display private keys\?\s?\[y\/n\]\: $/ do |data, re| send "n\r" data.sub re, '' end - #Answer for sync to peer on exit + # Answer for sync to peer on exit expect /^Confirm Sync to Peer\s?\[y\/n\]\: $/ do |data, re| send "n\r" data.sub re, '' end - #Answer for Unsaved configuration + # Answer for Unsaved configuration expect /^(WARNING: There are unsaved configuration changes).*/ do |data, re| send "n\r" data.sub re, '' @@ -56,5 +55,4 @@ class ALTEONOS < Oxidized::Model cfg :ssh do pre_logout 'exit' end - end diff --git a/lib/oxidized/model/alvarion.rb b/lib/oxidized/model/alvarion.rb index 7a4dcc7..8831f49 100644 --- a/lib/oxidized/model/alvarion.rb +++ b/lib/oxidized/model/alvarion.rb @@ -1,5 +1,4 @@ class Alvarion < Oxidized::Model - # Used in Alvarion wisp equipment # Run this command as an instance of Model so we can access node @@ -7,9 +6,6 @@ class Alvarion < Oxidized::Model cmd "#{node.auth[:password]}.cfg" end - cfg :tftp do - end - end diff --git a/lib/oxidized/model/aos.rb b/lib/oxidized/model/aos.rb index ec73b92..fed78c8 100644 --- a/lib/oxidized/model/aos.rb +++ b/lib/oxidized/model/aos.rb @@ -1,8 +1,7 @@ class AOS < Oxidized::Model - # Alcatel-Lucent Operating System # used in OmniSwitch - + comment '! ' cmd :all do |cfg| @@ -10,7 +9,7 @@ class AOS < Oxidized::Model end cmd 'show system' do |cfg| - cfg = cfg.each_line.find{|line|line.match 'Description'} + cfg = cfg.each_line.find { |line| line.match 'Description' } comment cfg.to_s.strip end @@ -34,5 +33,4 @@ class AOS < Oxidized::Model cfg :telnet, :ssh do pre_logout 'exit' end - end diff --git a/lib/oxidized/model/aos7.rb b/lib/oxidized/model/aos7.rb index 8d11066..00bee54 100644 --- a/lib/oxidized/model/aos7.rb +++ b/lib/oxidized/model/aos7.rb @@ -1,8 +1,7 @@ class AOS7 < Oxidized::Model - # Alcatel-Lucent Operating System Version 7 (Linux based) # used in OmniSwitch 6900/10k - + comment '! ' cmd :all do |cfg, cmdstring| @@ -11,7 +10,7 @@ class AOS7 < Oxidized::Model end cmd 'show system' do |cfg| - cfg = cfg.each_line.find{|line|line.match 'Description'} + cfg = cfg.each_line.find { |line| line.match 'Description' } comment cfg.to_s.strip + "\n" end diff --git a/lib/oxidized/model/aosw.rb b/lib/oxidized/model/aosw.rb index 3397305..7543353 100644 --- a/lib/oxidized/model/aosw.rb +++ b/lib/oxidized/model/aosw.rb @@ -1,14 +1,13 @@ class AOSW < Oxidized::Model - # AOSW Aruba Wireless, IAP, Instant Controller and Mobility Access Switches # Used in Alcatel OAW-4750 WLAN controller # Also Dell controllers - + # HPE Aruba Switches should use a different model as the software is based on the HP Procurve line. - + # Support for IAP & Instant Controller tested with 115, 205, 215 & 325 running 6.4.4.8-4.2.4.5_57965 # Support for Mobility Access Switches tested with S2500-48P & S2500-24P running 7.4.1.4_54199 and S2500-24P running 7.4.1.7_57823 - # All IAPs connected to a Instant Controller will have the same config output. Only the controller needs to be monitored. + # All IAPs connected to a Instant Controller will have the same config output. Only the controller needs to be monitored. comment '# ' prompt /^\(?.+\)?\s[#>]/ @@ -26,11 +25,11 @@ class AOSW < Oxidized::Model cfg.gsub!(/ sha (\S+)/, ' sha ') cfg.gsub!(/ des (\S+)/, ' des ') cfg.gsub!(/mobility-manager (\S+) user (\S+) (\S+)/, 'mobility-manager \1 user \2 ') - cfg.gsub!(/mgmt-user (\S+) (root|guest\-provisioning|network\-operations|read\-only|location\-api\-mgmt) (\S+)$/, 'mgmt-user \1 \2 ') #MAS & Wireless Controler - cfg.gsub!(/mgmt-user (\S+) (\S+)( (read\-only|guest\-mgmt))?$/, 'mgmt-user \1 \3') #IAP -#MAS format: mgmt-user -#IAP format (root user): mgmt-user -#IAP format: mgmt-user + cfg.gsub!(/mgmt-user (\S+) (root|guest\-provisioning|network\-operations|read\-only|location\-api\-mgmt) (\S+)$/, 'mgmt-user \1 \2 ') # MAS & Wireless Controler + cfg.gsub!(/mgmt-user (\S+) (\S+)( (read\-only|guest\-mgmt))?$/, 'mgmt-user \1 \3') # IAP + # MAS format: mgmt-user + # IAP format (root user): mgmt-user + # IAP format: mgmt-user cfg.gsub!(/key (\S+)$/, 'key ') cfg.gsub!(/wpa-passphrase (\S+)$/, 'wpa-passphrase ') cfg.gsub!(/bkup-passwords (\S+)$/, 'bkup-passwords ') @@ -45,17 +44,17 @@ class AOSW < Oxidized::Model end cmd 'show inventory' do |cfg| - cfg = "" if cfg.match /(Invalid input detected at '\^' marker|Parse error)/ #Don't show for unsupported devices (IAP and MAS) + cfg = "" if cfg.match /(Invalid input detected at '\^' marker|Parse error)/ # Don't show for unsupported devices (IAP and MAS) rstrip_cfg clean cfg end cmd 'show slots' do |cfg| - cfg = "" if cfg.match /(Invalid input detected at '\^' marker|Parse error)/ #Don't show for unsupported devices (IAP and MAS) + cfg = "" if cfg.match /(Invalid input detected at '\^' marker|Parse error)/ # Don't show for unsupported devices (IAP and MAS) rstrip_cfg comment cfg end cmd 'show license' do |cfg| - cfg = "" if cfg.match /(Invalid input detected at '\^' marker|Parse error)/ #Don't show for unsupported devices (IAP and MAS) + cfg = "" if cfg.match /(Invalid input detected at '\^' marker|Parse error)/ # Don't show for unsupported devices (IAP and MAS) rstrip_cfg comment cfg end @@ -112,5 +111,4 @@ class AOSW < Oxidized::Model out = comment out.join "\n" out << "\n" end - end diff --git a/lib/oxidized/model/apc_aos.rb b/lib/oxidized/model/apc_aos.rb index 530d436..5a4d232 100644 --- a/lib/oxidized/model/apc_aos.rb +++ b/lib/oxidized/model/apc_aos.rb @@ -1,11 +1,8 @@ class Apc_aos < Oxidized::Model - cmd 'config.ini' do |cfg| cfg.gsub! /^; Configuration file\, generated on.*/, '' end cfg :ftp do end - end - diff --git a/lib/oxidized/model/arbos.rb b/lib/oxidized/model/arbos.rb index 389f3f6..51b269d 100644 --- a/lib/oxidized/model/arbos.rb +++ b/lib/oxidized/model/arbos.rb @@ -1,9 +1,8 @@ -class ARBOS < Oxidized::Model - +class ARBOS < Oxidized::Model # Arbor OS model # prompt /^[\S\s]+\n([\w.@-]+[:\/#>]+)\s?$/ - comment '# ' + comment '# ' cmd 'system hardware' do |cfg| cfg.gsub! /^Boot\ time\:\s.+/, '' # Remove boot timer diff --git a/lib/oxidized/model/aricentiss.rb b/lib/oxidized/model/aricentiss.rb index 14f8502..77b78f4 100644 --- a/lib/oxidized/model/aricentiss.rb +++ b/lib/oxidized/model/aricentiss.rb @@ -4,7 +4,6 @@ # 0 SSE-G48-TG4 (P2-01) 1.0.16-9 class AricentISS < Oxidized::Model - prompt (/^(\e\[27m)?[ \r]*[\w-]+# ?$/) cfg :ssh do @@ -49,5 +48,4 @@ class AricentISS < Oxidized::Model l }.join.gsub(/ +$/, '') end - end diff --git a/lib/oxidized/model/asa.rb b/lib/oxidized/model/asa.rb index bea0705..dfd94b1 100644 --- a/lib/oxidized/model/asa.rb +++ b/lib/oxidized/model/asa.rb @@ -1,5 +1,4 @@ class ASA < Oxidized::Model - # Cisco ASA model # # Only SSH supported for the sake of security @@ -54,48 +53,47 @@ class ASA < Oxidized::Model post_login 'terminal pager 0' pre_logout 'exit' end - + def single_context - # Single context mode - cmd 'more system:running-config' do |cfg| - cfg = cfg.each_line.to_a[3..-1].join - cfg.gsub! /^: [^\n]*\n/, '' - # backup any xml referenced in the configuration. - anyconnect_profiles = cfg.scan(Regexp.new('(\sdisk0:/.+\.xml)')).flatten - anyconnect_profiles.each do |profile| - cfg << (comment profile + "\n" ) - cmd ("more" + profile) do |xml| - cfg << (comment xml) - end + # Single context mode + cmd 'more system:running-config' do |cfg| + cfg = cfg.each_line.to_a[3..-1].join + cfg.gsub! /^: [^\n]*\n/, '' + # backup any xml referenced in the configuration. + anyconnect_profiles = cfg.scan(Regexp.new('(\sdisk0:/.+\.xml)')).flatten + anyconnect_profiles.each do |profile| + cfg << (comment profile + "\n") + cmd ("more" + profile) do |xml| + cfg << (comment xml) end - # if DAP is enabled, also backup dap.xml - if cfg.rindex(/dynamic-access-policy-record\s(?!DfltAccessPolicy)/) - cfg << (comment "disk0:/dap.xml\n") - cmd "more disk0:/dap.xml" do |xml| - cfg << (comment xml) - end + end + # if DAP is enabled, also backup dap.xml + if cfg.rindex(/dynamic-access-policy-record\s(?!DfltAccessPolicy)/) + cfg << (comment "disk0:/dap.xml\n") + cmd "more disk0:/dap.xml" do |xml| + cfg << (comment xml) end - cfg end + cfg + end end def multiple_context - # Multiple context mode - cmd 'changeto system' do |cfg| - cmd 'show running-config' do |systemcfg| - allcfg = "\n\n" + systemcfg + "\n\n" - contexts = systemcfg.scan(/^context (\S+)$/) - files = systemcfg.scan(/config-url (\S+)$/) - contexts.each_with_index do |cont, i| - allcfg = allcfg + "\n\n----------========== [ CONTEXT " + cont.join(" ") + " FILE " + files[i].join(" ") + " ] ==========----------\n\n" - cmd "more " + files[i].join(" ") do |cfgcontext| - allcfg = allcfg + "\n\n" + cfgcontext - end + # Multiple context mode + cmd 'changeto system' do |cfg| + cmd 'show running-config' do |systemcfg| + allcfg = "\n\n" + systemcfg + "\n\n" + contexts = systemcfg.scan(/^context (\S+)$/) + files = systemcfg.scan(/config-url (\S+)$/) + contexts.each_with_index do |cont, i| + allcfg = allcfg + "\n\n----------========== [ CONTEXT " + cont.join(" ") + " FILE " + files[i].join(" ") + " ] ==========----------\n\n" + cmd "more " + files[i].join(" ") do |cfgcontext| + allcfg = allcfg + "\n\n" + cfgcontext end - cfg = allcfg end - cfg + cfg = allcfg end + cfg + end end - end diff --git a/lib/oxidized/model/asyncos.rb b/lib/oxidized/model/asyncos.rb index ac19e34..2857ef8 100644 --- a/lib/oxidized/model/asyncos.rb +++ b/lib/oxidized/model/asyncos.rb @@ -1,28 +1,27 @@ class AsyncOS < Oxidized::Model - # ESA prompt "(mail.example.com)> " prompt /^\r*([(][\w. ]+[)][#>]\s+)$/ - comment '! ' - - # Select passphrase display option - expect /\[\S+\]>\s/ do |data, re| - send "3\n" + comment '! ' + + # Select passphrase display option + expect /\[\S+\]>\s/ do |data, re| + send "3\n" data.sub re, '' end - + # handle paging - expect /-Press Any Key For More-+.*$/ do |data, re| + expect /-Press Any Key For More-+.*$/ do |data, re| send " " data.sub re, '' end - + cmd 'version' do |cfg| comment cfg end cmd 'showconfig' do |cfg| - #Delete hour and date which change each run - #cfg.gsub! /\sCurrent Time: \S+\s\S+\s+\S+\s\S+\s\S+/, ' Current Time:' + # Delete hour and date which change each run + # cfg.gsub! /\sCurrent Time: \S+\s\S+\s+\S+\s\S+\s\S+/, ' Current Time:' # Delete select passphrase display option cfg.gsub! /Choose the passphrase option:/, '' cfg.gsub! /1. Mask passphrases \(Files with masked passphrases cannot be loaded using/, '' @@ -30,20 +29,18 @@ class AsyncOS < Oxidized::Model cfg.gsub! /2. Encrypt passphrases/, '' cfg.gsub! /3. Plain passphrases/, '' cfg.gsub! /^3$/, '' - #Delete space - cfg.gsub! /\n\s{25,26}/, '' - #Delete after line - cfg.gsub! /([-\\\/,.\w><@]+)(\s{25,27})/,"\\1" - # Add a carriage return - cfg.gsub! /([-\\\/,.\w><@]+)(\s{6})([-\\\/,.\w><@]+)/,"\\1\n\\2\\3" + # Delete space + cfg.gsub! /\n\s{25,26}/, '' + # Delete after line + cfg.gsub! /([-\\\/,.\w><@]+)(\s{25,27})/, "\\1" + # Add a carriage return + cfg.gsub! /([-\\\/,.\w><@]+)(\s{6})([-\\\/,.\w><@]+)/, "\\1\n\\2\\3" # Delete prompt - cfg.gsub! /^\r*([(][\w. ]+[)][#>]\s+)$/, '' + cfg.gsub! /^\r*([(][\w. ]+[)][#>]\s+)$/, '' cfg - end - + cfg :ssh do pre_logout "exit" end - end diff --git a/lib/oxidized/model/audiocodes.rb b/lib/oxidized/model/audiocodes.rb index b7ee70e..2c77abb 100644 --- a/lib/oxidized/model/audiocodes.rb +++ b/lib/oxidized/model/audiocodes.rb @@ -1,20 +1,17 @@ class AudioCodes < Oxidized::Model - -# Pull config from AudioCodes Mediant devices from version > 7.0 + # Pull config from AudioCodes Mediant devices from version > 7.0 prompt /^\r?([\w.@() -]+[#>]\s?)$/ - comment '## ' + comment '## ' expect /\s*--MORE--$/ do |data, re| - send ' ' data.sub re, '' - end cmd 'show running-config' do |cfg| - cfg + cfg end cfg :ssh do @@ -22,11 +19,10 @@ class AudioCodes < Oxidized::Model password /^.+password:\s$/ pre_logout 'exit' end - + cfg :telnet do username /^Username:\s$/ password /^Password:\s$/ pre_logout 'exit' end - end diff --git a/lib/oxidized/model/awplus.rb b/lib/oxidized/model/awplus.rb index 1d8fbcd..7c88d60 100644 --- a/lib/oxidized/model/awplus.rb +++ b/lib/oxidized/model/awplus.rb @@ -1,27 +1,26 @@ class AWPlus < Oxidized::Model + # Allied Telesis Alliedware Plus Model# + # https://www.alliedtelesis.com/products/software/AlliedWare-Plus - #Allied Telesis Alliedware Plus Model# - #https://www.alliedtelesis.com/products/software/AlliedWare-Plus - prompt /^(\r?[\w.@:\/-]+[#>]\s?)$/ - comment '! ' + comment '! ' - #Avoids needing "term length 0" to display full config file. - expect /--More--/ do |data, re| - send ' ' - data.sub re, '' - end + # Avoids needing "term length 0" to display full config file. + expect /--More--/ do |data, re| + send ' ' + data.sub re, '' + end - #Removes gibberish pager output e.g. VT100 escape codes + # Removes gibberish pager output e.g. VT100 escape codes cmd :all do |cfg| cfg.gsub! /\e\[K/, '' # example how to handle pager - cleareol EL0 cfg.gsub! /\e\[7m\e\[m/, '' # example how to handle pager - Reverse SGR7 - cfg.gsub! /\r/, '' # Filters rogue ^M - see issue #415 + cfg.gsub! /\r/, '' # Filters rogue ^M - see issue #415 cfg.each_line.to_a[1..-2].join end - #Remove passwords from config file. - #Add vars "remove_secret: true" to global oxidized config file to enable. + # Remove passwords from config file. + # Add vars "remove_secret: true" to global oxidized config file to enable. cmd :secret do |cfg| cfg.gsub! /^(snmp-server community).*/, '\\1 ' @@ -34,52 +33,52 @@ class AWPlus < Oxidized::Model cfg end - #Adds "Show system" output to start of config. + # Adds "Show system" output to start of config. cmd 'Show System' do |cfg| - comment cfg.insert(0,"--------------------------------------------------------------------------------! \n") - #Unhash below to write a comment in the config file. - cfg.insert(0,"Starting: Show system cmd \n") + comment cfg.insert(0, "--------------------------------------------------------------------------------! \n") + # Unhash below to write a comment in the config file. + cfg.insert(0, "Starting: Show system cmd \n") cfg << "\n \nEnding: show system cmd" comment cfg << "\n--------------------------------------------------------------------------------! \n \n" - #Removes the following lines from "show system" in output file. This ensures oxidized diffs are meaningful. - comment cfg.each_line.reject { |line| - line.match /^$\n/ or #Remove blank lines in "sh sys" - line.match /System Status\s*.*/ or - line.match /RAM\s*:.*/ or - line.match /Uptime\s*:.*/ or - line.match /Flash\s*:.*/ or - line.match /Current software\s*:.*/ or - line.match /Software version\s*:.*/ or - line.match /Build date\s*:.*/ }.join + # Removes the following lines from "show system" in output file. This ensures oxidized diffs are meaningful. + comment cfg.each_line.reject { |line| + line.match /^$\n/ or # Remove blank lines in "sh sys" + line.match /System Status\s*.*/ or + line.match /RAM\s*:.*/ or + line.match /Uptime\s*:.*/ or + line.match /Flash\s*:.*/ or + line.match /Current software\s*:.*/ or + line.match /Software version\s*:.*/ or + line.match /Build date\s*:.*/ + } .join end - - #Actually get the devices running config# + + # Actually get the devices running config# cmd 'show running-config' do |cfg| cfg end - - #Config required for telnet to detect username prompt + + # Config required for telnet to detect username prompt cfg :telnet do username /login:\s/ - end + end - #Main login config - cfg :telnet, :ssh do + # Main login config + cfg :telnet, :ssh do post_login do if vars :enable send "enable\n" expect /^Password:\s/ cmd vars(:enable) + "\r\n" else - cmd 'enable' # Required for Priv-Exec users without enable PW to be put into "enable mode". + cmd 'enable' # Required for Priv-Exec users without enable PW to be put into "enable mode". end -# cmd 'terminal length 0' #set so the entire config is output without intervention. + # cmd 'terminal length 0' #set so the entire config is output without intervention. end pre_logout do -# cmd 'terminal no length' #Sets term length back to default on exit. - send "exit\r\n" + # cmd 'terminal no length' #Sets term length back to default on exit. + send "exit\r\n" end - end - + end end diff --git a/lib/oxidized/model/boss.rb b/lib/oxidized/model/boss.rb index 02201a1..cf762ee 100644 --- a/lib/oxidized/model/boss.rb +++ b/lib/oxidized/model/boss.rb @@ -16,7 +16,7 @@ class Boss < Oxidized::Model data.sub re, '' end - # Handle the Failed retries since last login + # Handle the Failed retries since last login # no known way to disable other than to implement radius authentication expect /Press ENTER to continue/ do |data, re| send "\n" @@ -29,7 +29,7 @@ class Boss < Oxidized::Model send "c" data.sub re, '' end - + # needed for proper formatting cmd('') { |cfg| comment "#{cfg}\n" } @@ -43,7 +43,7 @@ class Boss < Oxidized::Model cfg.gsub! /\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} .*/, '' comment "#{cfg}\n" end - + # if a stack then collect the stacking information cmd 'show stack-info' do |cfg| if @stack @@ -72,5 +72,4 @@ class Boss < Oxidized::Model post_login 'terminal length 0' post_login 'terminal width 132' end - end diff --git a/lib/oxidized/model/br6910.rb b/lib/oxidized/model/br6910.rb index df93793..1e79da3 100644 --- a/lib/oxidized/model/br6910.rb +++ b/lib/oxidized/model/br6910.rb @@ -1,45 +1,43 @@ - -class BR6910 < Oxidized::Model - - prompt /^([\w.@()-]+[#>]\s?)$/ - comment '! ' - - # not possible to disable paging prior to show running-config - expect /^((.*)Others to exit ---(.*))$/ do |data, re| - send 'a' - data.sub re, '' - end - - cmd :all do |cfg| - # sometimes br6910s inserts arbitrary whitespace after commands are - # issued on the CLI, from run to run. this normalises the output. - cfg.each_line.to_a[1..-2].drop_while { |e| e.match /^\s+$/ }.join - end - - cmd 'show version' do |cfg| - comment cfg - end - - # show flash is not possible on a brocade 6910, do dir instead - # to see flash contents (includes config file names) - cmd 'dir' do |cfg| - comment cfg - end - - cmd 'show running-config' do |cfg| - arr = cfg.each_line.to_a - arr[2..-1].join unless arr.length < 2 - end - - cfg :telnet do - username /^Username:/ - password /^Password:/ - end - - # post login and post logout - cfg :telnet, :ssh do - post_login '' - pre_logout 'exit' - end - -end + +class BR6910 < Oxidized::Model + prompt /^([\w.@()-]+[#>]\s?)$/ + comment '! ' + + # not possible to disable paging prior to show running-config + expect /^((.*)Others to exit ---(.*))$/ do |data, re| + send 'a' + data.sub re, '' + end + + cmd :all do |cfg| + # sometimes br6910s inserts arbitrary whitespace after commands are + # issued on the CLI, from run to run. this normalises the output. + cfg.each_line.to_a[1..-2].drop_while { |e| e.match /^\s+$/ }.join + end + + cmd 'show version' do |cfg| + comment cfg + end + + # show flash is not possible on a brocade 6910, do dir instead + # to see flash contents (includes config file names) + cmd 'dir' do |cfg| + comment cfg + end + + cmd 'show running-config' do |cfg| + arr = cfg.each_line.to_a + arr[2..-1].join unless arr.length < 2 + end + + cfg :telnet do + username /^Username:/ + password /^Password:/ + end + + # post login and post logout + cfg :telnet, :ssh do + post_login '' + pre_logout 'exit' + end +end diff --git a/lib/oxidized/model/c4cmts.rb b/lib/oxidized/model/c4cmts.rb index 150029c..8ea27c6 100644 --- a/lib/oxidized/model/c4cmts.rb +++ b/lib/oxidized/model/c4cmts.rb @@ -1,15 +1,14 @@ class C4CMTS < Oxidized::Model - # Arris C4 CMTS prompt /^([\w.@:\/-]+[#>]\s?)$/ comment '! ' cmd :all do |cfg| - cfg.each_line.to_a[1..-2].map{|line|line.delete("\r").rstrip}.join("\n") + "\n" + cfg.each_line.to_a[1..-2].map { |line| line.delete("\r").rstrip }.join("\n") + "\n" end - cmd :secret do |cfg| + cmd :secret do |cfg| cfg.gsub! /(.+)\s+encrypted-password\s+\w+\s+(.*)/, '\\1