From e2899b55638101ddf97aeab919a9f064daf05451 Mon Sep 17 00:00:00 2001 From: Saku Ytti Date: Sat, 4 Feb 2017 11:49:31 +0200 Subject: give option to stop resolving name to IP With ssh proxy you might want to have far-end resolve --- lib/oxidized/config.rb | 1 + lib/oxidized/node.rb | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/oxidized/config.rb b/lib/oxidized/config.rb index b6b5c40..c97fa2f 100644 --- a/lib/oxidized/config.rb +++ b/lib/oxidized/config.rb @@ -20,6 +20,7 @@ module Oxidized asetus.default.username = 'username' asetus.default.password = 'password' asetus.default.model = 'junos' + asetus.deefault.resolve_dns = true # if false, don't resolve DNS to IP asetus.default.interval = 3600 asetus.default.use_syslog = false asetus.default.debug = false diff --git a/lib/oxidized/node.rb b/lib/oxidized/node.rb index 6f89b56..7201a73 100644 --- a/lib/oxidized/node.rb +++ b/lib/oxidized/node.rb @@ -14,7 +14,8 @@ module Oxidized ip_addr, _ = opt[:ip].to_s.split("/") Oxidized.logger.debug 'IPADDR %s' % ip_addr.to_s @name = opt[:name] - @ip = IPAddr.new(ip_addr).to_s rescue nil + @ip = @name unless Oxidized.config.resolve_dns? + @ip ||= IPAddr.new(ip_addr).to_s rescue nil @ip ||= Resolv.new.getaddress @name @group = opt[:group] @input = resolve_input opt -- cgit v1.2.1 From 50b3bc843d115351d109399a9ef453e3790b01fd Mon Sep 17 00:00:00 2001 From: Saku Ytti Date: Sat, 4 Feb 2017 12:00:03 +0200 Subject: typo fix --- lib/oxidized/config.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/oxidized/config.rb b/lib/oxidized/config.rb index c97fa2f..a92cea6 100644 --- a/lib/oxidized/config.rb +++ b/lib/oxidized/config.rb @@ -20,7 +20,7 @@ module Oxidized asetus.default.username = 'username' asetus.default.password = 'password' asetus.default.model = 'junos' - asetus.deefault.resolve_dns = true # if false, don't resolve DNS to IP + asetus.default.resolve_dns = true # if false, don't resolve DNS to IP asetus.default.interval = 3600 asetus.default.use_syslog = false asetus.default.debug = false -- cgit v1.2.1 From d156ac397beffabe3f0cb045f923050a3ab74887 Mon Sep 17 00:00:00 2001 From: Neil Lathwood Date: Tue, 31 Oct 2017 21:38:54 +0000 Subject: Added support for sending single node request to http source --- lib/oxidized/nodes.rb | 3 ++- lib/oxidized/source/http.rb | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/oxidized/nodes.rb b/lib/oxidized/nodes.rb index 3f84e15..84cf956 100644 --- a/lib/oxidized/nodes.rb +++ b/lib/oxidized/nodes.rb @@ -12,7 +12,8 @@ module Oxidized @source = Oxidized.config.source.default Oxidized.mgr.add_source @source Oxidized.logger.info "lib/oxidized/nodes.rb: Loading nodes" - Oxidized.mgr.source[@source].new.load.each do |node| + nodes = Oxidized.mgr.source[@source].new.load node_want + nodes.each do |node| # we want to load specific node(s), not all of them next unless node_want? node_want, node begin diff --git a/lib/oxidized/source/http.rb b/lib/oxidized/source/http.rb index 6c12f29..e4cb58e 100644 --- a/lib/oxidized/source/http.rb +++ b/lib/oxidized/source/http.rb @@ -15,7 +15,7 @@ class HTTP < Source require "uri" require "json" - def load + def load node=nil nodes = [] uri = URI.parse(@cfg.url) http = Net::HTTP.new(uri.host, uri.port) @@ -28,7 +28,11 @@ class HTTP < Source headers[header] = value end - request = Net::HTTP::Get.new(uri.request_uri, headers) + req_uri = uri.request_uri + if node + req_uri = "#{req_uri}/#{node}" + end + request = Net::HTTP::Get.new(req_uri, headers) if (@cfg.user? && @cfg.pass?) request.basic_auth(@cfg.user,@cfg.pass) end -- cgit v1.2.1 From 29704b5f2721a742d312ced784a8076e27e8063b Mon Sep 17 00:00:00 2001 From: laf Date: Fri, 10 Nov 2017 14:12:13 +0000 Subject: Added sql support for calling for single host --- lib/oxidized/source/http.rb | 6 +++--- lib/oxidized/source/sql.rb | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/oxidized/source/http.rb b/lib/oxidized/source/http.rb index e4cb58e..73df6f7 100644 --- a/lib/oxidized/source/http.rb +++ b/lib/oxidized/source/http.rb @@ -15,7 +15,7 @@ class HTTP < Source require "uri" require "json" - def load node=nil + def load node_want=nil nodes = [] uri = URI.parse(@cfg.url) http = Net::HTTP.new(uri.host, uri.port) @@ -29,8 +29,8 @@ class HTTP < Source end req_uri = uri.request_uri - if node - req_uri = "#{req_uri}/#{node}" + if node_want + req_uri = "#{req_uri}/#{node_want}" end request = Net::HTTP::Get.new(req_uri, headers) if (@cfg.user? && @cfg.pass?) diff --git a/lib/oxidized/source/sql.rb b/lib/oxidized/source/sql.rb index 13fc39b..7e2824d 100644 --- a/lib/oxidized/source/sql.rb +++ b/lib/oxidized/source/sql.rb @@ -18,11 +18,12 @@ class SQL < Source end end - def load + def load node_want=nil nodes = [] db = connect query = db[@cfg.table.to_sym] query = query.with_sql(@cfg.query) if @cfg.query? + query = qeury.where(@cfg.map.name.to_sym node_want) query.each do |node| # map node parameters keys = {} -- cgit v1.2.1 From d96cfac1f09ff4055f54ab604358290865d41f62 Mon Sep 17 00:00:00 2001 From: laf Date: Fri, 10 Nov 2017 14:44:45 +0000 Subject: updated to check if node_want --- lib/oxidized/source/sql.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/oxidized/source/sql.rb b/lib/oxidized/source/sql.rb index 7e2824d..97064fa 100644 --- a/lib/oxidized/source/sql.rb +++ b/lib/oxidized/source/sql.rb @@ -23,7 +23,11 @@ class SQL < Source db = connect query = db[@cfg.table.to_sym] query = query.with_sql(@cfg.query) if @cfg.query? - query = qeury.where(@cfg.map.name.to_sym node_want) + + if node_want + query = query.where(@cfg.map.name.to_sym=>node_want) + end + query.each do |node| # map node parameters keys = {} -- cgit v1.2.1 From fd1b2c2ac903b3a8e2578a4ca0f48a61309a0493 Mon Sep 17 00:00:00 2001 From: Ilya Demyanov Date: Sun, 31 Dec 2017 09:19:49 +0300 Subject: Create snr.rb --- lib/oxidized/model/snr.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 lib/oxidized/model/snr.rb (limited to 'lib') diff --git a/lib/oxidized/model/snr.rb b/lib/oxidized/model/snr.rb new file mode 100644 index 0000000..3f1fab5 --- /dev/null +++ b/lib/oxidized/model/snr.rb @@ -0,0 +1,14 @@ +class SNR < Oxidized::Model + + comment '!' + + cmd 'show running-config' do |cfg| + cfg = cfg.each_line.to_a[1..-1] + end + + cfg :ssh do + post_login 'terminal length 0' + pre_logout 'exit' + end + +end -- cgit v1.2.1 From 6890754f0a579fc9be3912113dcfe510b2837f7c Mon Sep 17 00:00:00 2001 From: CppMonkey Date: Thu, 1 Feb 2018 17:39:00 +0000 Subject: Initial commit for SSH/Telnet on Xyzel XGS4600 series --- lib/oxidized/model/zynoscli.rb | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 lib/oxidized/model/zynoscli.rb (limited to 'lib') diff --git a/lib/oxidized/model/zynoscli.rb b/lib/oxidized/model/zynoscli.rb new file mode 100644 index 0000000..9f29a16 --- /dev/null +++ b/lib/oxidized/model/zynoscli.rb @@ -0,0 +1,35 @@ +class ZyNOSCLI < Oxidized::Model + + # Used in Zyxel DSLAMs, such as SAM1316 + + # Typical prompt "XGS4600#" + prompt /^([\w.@()-]+[#>]\s\e7)$/ + comment ';; ' + + cmd :all do |cfg| + cfg.gsub! /^.*\e7/, '' + end + + cmd 'show running-config' + + cfg :telnet do + username /^User name:/i + password /^Password:/i + end + + cfg :telnet, :ssh do + if vars :enable + post_login do + send "enable\n" + # Interpret enable: true as meaning we won't be prompted for a password + unless vars(:enable).is_a? TrueClass + expect /[pP]assword:\s?$/ + send vars(:enable) + "\n" + end + expect /^.+[#]$/ + end + end + pre_logout 'exit' + end + +end -- cgit v1.2.1 From 7c108b6b7a3277aac44455b93a587d1d01a58041 Mon Sep 17 00:00:00 2001 From: Neil Lathwood Date: Mon, 5 Feb 2018 21:55:31 +0000 Subject: Added support for setting ssh auth methods --- lib/oxidized/input/ssh.rb | 5 ++++- lib/oxidized/worker.rb | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/oxidized/input/ssh.rb b/lib/oxidized/input/ssh.rb index 27e81e0..8df18f5 100644 --- a/lib/oxidized/input/ssh.rb +++ b/lib/oxidized/input/ssh.rb @@ -29,10 +29,13 @@ module Oxidized :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, } + auth_methods = vars(:auth_methods) || %w(none publickey password) + ssh_opts[:auth_methods] = auth_methods + Oxidized.logger.info "AUTH METHODS::#{auth_methods}" + if proxy_host = vars(:ssh_proxy) proxy_command = "ssh " proxy_command += "-o StrictHostKeyChecking=no " unless secure diff --git a/lib/oxidized/worker.rb b/lib/oxidized/worker.rb index 4173680..062233b 100644 --- a/lib/oxidized/worker.rb +++ b/lib/oxidized/worker.rb @@ -80,7 +80,11 @@ module Oxidized private def is_cycle_finished? - @jobs_done > 0 && @jobs_done % @nodes.count == 0 + if @jobs_done > @nodes.count + true + else + @jobs_done > 0 && @jobs_done % @nodes.count == 0 + end end def run_done_hook -- cgit v1.2.1 From 97aa0535a0c8c237c1ccb7a1683d5f6faa1f0339 Mon Sep 17 00:00:00 2001 From: CppMonkey Date: Tue, 20 Mar 2018 09:53:41 +0000 Subject: Added more commands Shows more details. Confirms stacking config (Ring/Chain) Allows tracking of firmware on ras0 and ras1 --- lib/oxidized/model/zynoscli.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/oxidized/model/zynoscli.rb b/lib/oxidized/model/zynoscli.rb index 9f29a16..ae64b04 100644 --- a/lib/oxidized/model/zynoscli.rb +++ b/lib/oxidized/model/zynoscli.rb @@ -1,5 +1,4 @@ class ZyNOSCLI < Oxidized::Model - # Used in Zyxel DSLAMs, such as SAM1316 # Typical prompt "XGS4600#" @@ -9,6 +8,9 @@ class ZyNOSCLI < Oxidized::Model cmd :all do |cfg| cfg.gsub! /^.*\e7/, '' end + cmd 'show stacking' + + cmd 'show version' cmd 'show running-config' @@ -31,5 +33,4 @@ class ZyNOSCLI < Oxidized::Model end pre_logout 'exit' end - end -- cgit v1.2.1 From 343cf3227cafe4a7de4a7be5934163eb6bd2dba9 Mon Sep 17 00:00:00 2001 From: Wild Kat Date: Tue, 20 Mar 2018 23:17:29 +0100 Subject: expand dcnos model --- lib/oxidized/model/dcnos.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib') diff --git a/lib/oxidized/model/dcnos.rb b/lib/oxidized/model/dcnos.rb index 5a39e2b..4a33fa0 100644 --- a/lib/oxidized/model/dcnos.rb +++ b/lib/oxidized/model/dcnos.rb @@ -12,6 +12,14 @@ class DCNOS < Oxidized::Model comment cfg end + cmd 'show boot-files' do |cfg| + comment cfg + end + + cmd 'show flash' do |cfg| + comment cfg + end + cmd 'show running-config' do |cfg| cfg = cfg.each_line.to_a[1..-1] end -- cgit v1.2.1 From 2d8e40344a05ac16869941c19dbcd6df8ddac80c Mon Sep 17 00:00:00 2001 From: Wild Kat Date: Tue, 20 Mar 2018 23:38:23 +0100 Subject: better comments --- lib/oxidized/model/dcnos.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/oxidized/model/dcnos.rb b/lib/oxidized/model/dcnos.rb index 4a33fa0..c6b2e36 100644 --- a/lib/oxidized/model/dcnos.rb +++ b/lib/oxidized/model/dcnos.rb @@ -6,7 +6,7 @@ class DCNOS < Oxidized::Model - comment '!' + comment '! ' cmd 'show version' do |cfg| comment cfg -- cgit v1.2.1 From ff0a42cdfd2bdb34d0852a0d85f63825a44fdf1b Mon Sep 17 00:00:00 2001 From: James Hannah Date: Wed, 21 Mar 2018 09:02:38 +0000 Subject: Alter DNOS config. Remove constantly changing info Gsub out the uptime which changes constantly, and remove the output of "show system" which duplicates the info from "show version" and contains fan speed data which isn't helpful. --- lib/oxidized/model/dnos.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/oxidized/model/dnos.rb b/lib/oxidized/model/dnos.rb index 5c3cd53..22e1876 100644 --- a/lib/oxidized/model/dnos.rb +++ b/lib/oxidized/model/dnos.rb @@ -6,6 +6,7 @@ class DNOS < Oxidized::Model cmd :all do |cfg| cfg.gsub! /^% Invalid input detected at '\^' marker\.$|^\s+\^$/, '' + cfg.gsub! /^Dell Networking OS uptime is\s.+/, '' # Omit constantly changing uptime info cfg.each_line.to_a[2..-2].join end @@ -27,10 +28,6 @@ class DNOS < Oxidized::Model comment cfg end - cmd 'show system' do |cfg| - comment cfg - end - cmd 'show running-config' do |cfg| cfg = cfg.each_line.to_a[3..-1].join cfg -- cgit v1.2.1 From 4ba96c79f7eaf5dd9c02c9488d77a5c896c96d8c Mon Sep 17 00:00:00 2001 From: Wild Kat Date: Fri, 23 Mar 2018 09:24:38 +0100 Subject: yield cfg for clarity --- lib/oxidized/model/dcnos.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/oxidized/model/dcnos.rb b/lib/oxidized/model/dcnos.rb index c6b2e36..f53bc0d 100644 --- a/lib/oxidized/model/dcnos.rb +++ b/lib/oxidized/model/dcnos.rb @@ -21,7 +21,8 @@ class DCNOS < Oxidized::Model end cmd 'show running-config' do |cfg| - cfg = cfg.each_line.to_a[1..-1] + cfg = cfg.each_line.to_a[1..-1].join + cfg end cfg :telnet do -- cgit v1.2.1 From b2fcf887b3ea7e85e916ec7265a494a6efbf8fa7 Mon Sep 17 00:00:00 2001 From: Wild Kat Date: Thu, 5 Apr 2018 14:23:20 +0200 Subject: strip uptime info from show version --- lib/oxidized/model/dcnos.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'lib') diff --git a/lib/oxidized/model/dcnos.rb b/lib/oxidized/model/dcnos.rb index f53bc0d..ec0c7f6 100644 --- a/lib/oxidized/model/dcnos.rb +++ b/lib/oxidized/model/dcnos.rb @@ -9,6 +9,7 @@ class DCNOS < Oxidized::Model comment '! ' cmd 'show version' do |cfg| + cfg = cfg.gsub! /^(Uptime is ).*/, '' comment cfg end -- cgit v1.2.1 From b54a5e211f2127d9397e6d43c30fd47de33ee5a5 Mon Sep 17 00:00:00 2001 From: Wild Kat Date: Thu, 5 Apr 2018 15:29:00 +0200 Subject: unspeakable things took place in original PR, correcting model --- lib/oxidized/model/dcnos.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/oxidized/model/dcnos.rb b/lib/oxidized/model/dcnos.rb index ec0c7f6..8506280 100644 --- a/lib/oxidized/model/dcnos.rb +++ b/lib/oxidized/model/dcnos.rb @@ -8,8 +8,12 @@ class DCNOS < Oxidized::Model comment '! ' + cmd :all do |cfg| + cfg.each_line.to_a[1..-1].join + end + cmd 'show version' do |cfg| - cfg = cfg.gsub! /^(Uptime is ).*/, '' + cfg.gsub! /\s(Uptime is).*/, '' comment cfg end @@ -22,7 +26,6 @@ class DCNOS < Oxidized::Model end cmd 'show running-config' do |cfg| - cfg = cfg.each_line.to_a[1..-1].join cfg end -- cgit v1.2.1 From 265e7f55d7bf481757b12218e893231a7d6e092e Mon Sep 17 00:00:00 2001 From: Wild Kat Date: Fri, 6 Apr 2018 21:19:07 +0200 Subject: refactor githubrepo credential handling --- lib/oxidized/hook/githubrepo.rb | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/oxidized/hook/githubrepo.rb b/lib/oxidized/hook/githubrepo.rb index f74b22a..715438b 100644 --- a/lib/oxidized/hook/githubrepo.rb +++ b/lib/oxidized/hook/githubrepo.rb @@ -45,16 +45,23 @@ class GithubRepo < Oxidized::Hook private def credentials - @credentials ||= if cfg.has_key?('username') && cfg.has_key?('password') - log "Using https auth", :debug - Rugged::Credentials::UserPassword.new(username: cfg.username, password: cfg.password) - else - if cfg.has_key?('publickey') && cfg.has_key?('privatekey') - log "Using ssh auth with key", :debug - Rugged::Credentials::SshKey.new(username: 'git', publickey: File.expand_path(cfg.publickey), privatekey: File.expand_path(cfg.privatekey), passphrase: ENV["OXIDIZED_SSH_PASSPHRASE"]) + Proc.new do |url, username_from_url, allowed_types| + + if cfg.has_key?('username') + git_user = cfg.username + else + git_user = username_from_url ? username_from_url : 'git' + end + + if cfg.has_key?('password') + log "Authenticating using username and password", :debug + Rugged::Credentials::UserPassword.new(username: git_user, password: cfg.password) + elsif cfg.has_key?('publickey') && cfg.has_key?('privatekey') + log "Authenticating using ssh keys", :debug + Rugged::Credentials::SshKey.new(username: git_user, publickey: File.expand_path(cfg.publickey), privatekey: File.expand_path(cfg.privatekey), passphrase: ENV["OXIDIZED_SSH_PASSPHRASE"]) else - log "Using ssh auth with agentforwarding", :debug - Rugged::Credentials::SshKeyFromAgent.new(username: 'git') + log "Authenticating using ssh agent", :debug + Rugged::Credentials::SshKeyFromAgent.new(username: git_user) end end end -- cgit v1.2.1 From 331838fd9203dcf72e94ea218defc9a2115fabf6 Mon Sep 17 00:00:00 2001 From: Wild Kat Date: Fri, 6 Apr 2018 22:12:18 +0200 Subject: expose username in debug log --- lib/oxidized/hook/githubrepo.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/oxidized/hook/githubrepo.rb b/lib/oxidized/hook/githubrepo.rb index 715438b..4cae4e6 100644 --- a/lib/oxidized/hook/githubrepo.rb +++ b/lib/oxidized/hook/githubrepo.rb @@ -54,13 +54,13 @@ class GithubRepo < Oxidized::Hook end if cfg.has_key?('password') - log "Authenticating using username and password", :debug + log "Authenticating using username and password as '#{git_user}'", :debug Rugged::Credentials::UserPassword.new(username: git_user, password: cfg.password) elsif cfg.has_key?('publickey') && cfg.has_key?('privatekey') - log "Authenticating using ssh keys", :debug + log "Authenticating using ssh keys as '#{git_user}'", :debug Rugged::Credentials::SshKey.new(username: git_user, publickey: File.expand_path(cfg.publickey), privatekey: File.expand_path(cfg.privatekey), passphrase: ENV["OXIDIZED_SSH_PASSPHRASE"]) else - log "Authenticating using ssh agent", :debug + log "Authenticating using ssh agent as '#{git_user}'", :debug Rugged::Credentials::SshKeyFromAgent.new(username: git_user) end end -- cgit v1.2.1 From f3c489be3d747af4608234fb55d93d8d3e037470 Mon Sep 17 00:00:00 2001 From: Martin Overgaard Hansen Date: Sat, 7 Apr 2018 21:34:18 +0200 Subject: Allowed prompt to contain hyphen --- lib/oxidized/model/aricentiss.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/oxidized/model/aricentiss.rb b/lib/oxidized/model/aricentiss.rb index 8821801..14f8502 100644 --- a/lib/oxidized/model/aricentiss.rb +++ b/lib/oxidized/model/aricentiss.rb @@ -5,7 +5,7 @@ class AricentISS < Oxidized::Model - prompt (/^(\e\[27m)?[ \r]*\w+# ?$/) + prompt (/^(\e\[27m)?[ \r]*[\w-]+# ?$/) cfg :ssh do # "pagination" was misspelled in some (earlier) versions (at least 1.0.16-9) -- cgit v1.2.1 From a4bd3e5ca5ab747fdbf2bd876d7be7a947e74f46 Mon Sep 17 00:00:00 2001 From: Wild Kat Date: Sun, 8 Apr 2018 00:35:47 +0200 Subject: eliminate inverse methods from models --- lib/oxidized/model/aosw.rb | 2 +- lib/oxidized/model/asa.rb | 2 +- lib/oxidized/model/comware.rb | 2 +- lib/oxidized/model/firewareos.rb | 2 +- lib/oxidized/model/powerconnect.rb | 4 ++-- lib/oxidized/model/procurve.rb | 2 +- lib/oxidized/model/routeros.rb | 2 +- lib/oxidized/model/vrp.rb | 2 +- lib/oxidized/model/zhoneolt.rb | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/oxidized/model/aosw.rb b/lib/oxidized/model/aosw.rb index 71fde2e..3397305 100644 --- a/lib/oxidized/model/aosw.rb +++ b/lib/oxidized/model/aosw.rb @@ -40,7 +40,7 @@ class AOSW < Oxidized::Model end cmd 'show version' do |cfg| - cfg = cfg.each_line.select { |line| not line.match /(Switch|AP) uptime/i } + cfg = cfg.each_line.reject { |line| line.match /(Switch|AP) uptime/i } rstrip_cfg comment cfg.join end diff --git a/lib/oxidized/model/asa.rb b/lib/oxidized/model/asa.rb index 9df4206..bea0705 100644 --- a/lib/oxidized/model/asa.rb +++ b/lib/oxidized/model/asa.rb @@ -27,7 +27,7 @@ class ASA < Oxidized::Model cmd 'show version' do |cfg| # avoid commits due to uptime / ixo-router01 up 2 mins 28 secs / ixo-router01 up 1 days 2 hours - cfg = cfg.each_line.select { |line| not line.match /(\s+up\s+\d+\s+)|(.*days.*)/ } + cfg = cfg.each_line.reject { |line| line.match /(\s+up\s+\d+\s+)|(.*days.*)/ } cfg = cfg.join comment cfg end diff --git a/lib/oxidized/model/comware.rb b/lib/oxidized/model/comware.rb index a5b7190..0ba26d5 100644 --- a/lib/oxidized/model/comware.rb +++ b/lib/oxidized/model/comware.rb @@ -47,7 +47,7 @@ class Comware < Oxidized::Model end cmd 'display version' do |cfg| - cfg = cfg.each_line.select {|l| not l.match /uptime/i }.join + cfg = cfg.each_line.reject { |l| l.match /uptime/i }.join comment cfg end diff --git a/lib/oxidized/model/firewareos.rb b/lib/oxidized/model/firewareos.rb index 1b3d07c..31770dc 100644 --- a/lib/oxidized/model/firewareos.rb +++ b/lib/oxidized/model/firewareos.rb @@ -15,7 +15,7 @@ class FirewareOS < Oxidized::Model cmd 'show sysinfo' do |cfg| # avoid commits due to uptime - cfg = cfg.each_line.select { |line| not line.match /(.*time.*)|(.*memory.*)|(.*cpu.*)/ } + cfg = cfg.each_line.reject { |line| line.match /(.*time.*)|(.*memory.*)|(.*cpu.*)/ } cfg = cfg.join comment cfg end diff --git a/lib/oxidized/model/powerconnect.rb b/lib/oxidized/model/powerconnect.rb index f602a36..ca91e60 100644 --- a/lib/oxidized/model/powerconnect.rb +++ b/lib/oxidized/model/powerconnect.rb @@ -22,7 +22,7 @@ class PowerConnect < Oxidized::Model if (@stackable.nil?) @stackable = true if cfg.match /(U|u)nit\s/ end - cfg = cfg.split("\n").select { |line| not line[/Up\sTime/] } + cfg = cfg.split("\n").reject { |line| line[/Up\sTime/] } comment cfg.join("\n") + "\n" end @@ -72,7 +72,7 @@ class PowerConnect < Oxidized::Model end out << line.strip end - out = out.select { |line| not line[/Up\sTime/] } + out = out.reject { |line| line[/Up\sTime/] } out = comment out.join "\n" out << "\n" end diff --git a/lib/oxidized/model/procurve.rb b/lib/oxidized/model/procurve.rb index 444fb5b..705a814 100644 --- a/lib/oxidized/model/procurve.rb +++ b/lib/oxidized/model/procurve.rb @@ -67,7 +67,7 @@ class Procurve < Oxidized::Model # not supported on all models cmd 'show system information' do |cfg| - cfg = cfg.each_line.select { |line| not line.match /(.*CPU.*)|(.*Up Time.*)|(.*Total.*)|(.*Free.*)|(.*Lowest.*)|(.*Missed.*)/ } + cfg = cfg.each_line.reject { |line| line.match /(.*CPU.*)|(.*Up Time.*)|(.*Total.*)|(.*Free.*)|(.*Lowest.*)|(.*Missed.*)/ } cfg = cfg.join comment cfg end diff --git a/lib/oxidized/model/routeros.rb b/lib/oxidized/model/routeros.rb index 6717446..b62a3be 100644 --- a/lib/oxidized/model/routeros.rb +++ b/lib/oxidized/model/routeros.rb @@ -20,7 +20,7 @@ class RouterOS < Oxidized::Model cfg.gsub! /\x1B\[([0-9]{1,3}((;[0-9]{1,3})*)?)?[m|K]/, '' # strip ANSI colours cfg.gsub! /\\\r\n\s+/, '' # strip new line cfg.gsub! /# inactive time\r\n/, '' # Remove time based system comment - cfg = cfg.split("\n").select { |line| not line[/^\#\s\w{3}\/\d{2}\/\d{4}.*$/] } + cfg = cfg.split("\n").reject { |line| line[/^\#\s\w{3}\/\d{2}\/\d{4}.*$/] } cfg.join("\n") + "\n" end end diff --git a/lib/oxidized/model/vrp.rb b/lib/oxidized/model/vrp.rb index 98229c3..e44f69e 100644 --- a/lib/oxidized/model/vrp.rb +++ b/lib/oxidized/model/vrp.rb @@ -25,7 +25,7 @@ class VRP < Oxidized::Model end cmd 'display version' do |cfg| - cfg = cfg.each_line.select {|l| not l.match /uptime/ }.join + cfg = cfg.each_line.reject { |l| l.match /uptime/ }.join comment cfg end diff --git a/lib/oxidized/model/zhoneolt.rb b/lib/oxidized/model/zhoneolt.rb index b60edb2..c50680c 100644 --- a/lib/oxidized/model/zhoneolt.rb +++ b/lib/oxidized/model/zhoneolt.rb @@ -39,7 +39,7 @@ class ZhoneOLT < Oxidized::Model end cmd 'dump console' do |cfg| - cfg = cfg.each_line.select { |line| not line.match /To Abort the operation enter Ctrl-C/ }.join + cfg = cfg.each_line.reject { |line| line.match /To Abort the operation enter Ctrl-C/ }.join end # zhone technically supports ssh, but it locks up a ton. Especially when -- cgit v1.2.1 From 0bebd8cb9ea83b4933aca702b2734e6597271fec Mon Sep 17 00:00:00 2001 From: Andre Sencioles Date: Mon, 9 Apr 2018 09:39:56 +1200 Subject: Disable paging for "show full-configuration" on FortiOS --- lib/oxidized/model/fortios.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/oxidized/model/fortios.rb b/lib/oxidized/model/fortios.rb index 23370c4..9287dce 100644 --- a/lib/oxidized/model/fortios.rb +++ b/lib/oxidized/model/fortios.rb @@ -49,7 +49,7 @@ class FortiOS < Oxidized::Model cfg << cmd('end') if @vdom_enabled - cfg << cmd('show full-configuration') + cfg << cmd('show full-configuration | grep .') cfg.join "\n" end -- cgit v1.2.1 From 01d7f29905fd9ca712e8b640408425cf2d3ad64d Mon Sep 17 00:00:00 2001 From: Wild Kat Date: Wed, 11 Apr 2018 19:58:30 +0200 Subject: standardize on verbose hash methods --- lib/oxidized/manager.rb | 4 ++-- lib/oxidized/source/csv.rb | 2 +- lib/oxidized/source/http.rb | 2 +- lib/oxidized/source/sql.rb | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) (limited to 'lib') diff --git a/lib/oxidized/manager.rb b/lib/oxidized/manager.rb index bf28ae7..d2ef4d2 100644 --- a/lib/oxidized/manager.rb +++ b/lib/oxidized/manager.rb @@ -49,13 +49,13 @@ module Oxidized @model.merge! _model end def add_source _source - return nil if @source.key? _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.key? _hook + return nil if @hook.has_key? _hook name = _hook _hook = Manager.load File.join(Config::Root, 'hook'), name _hook = Manager.load Config::HookDir, name if _hook.empty? diff --git a/lib/oxidized/source/csv.rb b/lib/oxidized/source/csv.rb index 4814bd7..b61525e 100644 --- a/lib/oxidized/source/csv.rb +++ b/lib/oxidized/source/csv.rb @@ -36,7 +36,7 @@ class CSV < Source @cfg.map.each do |key, position| keys[key.to_sym] = node_var_interpolate data[position] end - keys[:model] = map_model keys[:model] if keys.key? :model + keys[:model] = map_model keys[:model] if keys.has_key? :model # map node specific vars vars = {} diff --git a/lib/oxidized/source/http.rb b/lib/oxidized/source/http.rb index 6c12f29..56a575b 100644 --- a/lib/oxidized/source/http.rb +++ b/lib/oxidized/source/http.rb @@ -43,7 +43,7 @@ class HTTP < Source 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 + keys[:model] = map_model keys[:model] if keys.has_key? :model # map node specific vars vars = {} diff --git a/lib/oxidized/source/sql.rb b/lib/oxidized/source/sql.rb index 13fc39b..ca3bcc3 100644 --- a/lib/oxidized/source/sql.rb +++ b/lib/oxidized/source/sql.rb @@ -27,7 +27,7 @@ class SQL < Source # map node parameters keys = {} @cfg.map.each { |key, sql_column| keys[key.to_sym] = node_var_interpolate node[sql_column.to_sym] } - keys[:model] = map_model keys[:model] if keys.key? :model + keys[:model] = map_model keys[:model] if keys.has_key? :model # map node specific vars vars = {} -- cgit v1.2.1 From 36f31e7d053365fe9f5d6b64bae4ac485677c93c Mon Sep 17 00:00:00 2001 From: Wild Kat Date: Wed, 11 Apr 2018 21:14:56 +0200 Subject: eliminate tabs in favor of double space --- lib/oxidized/model/asyncos.rb | 88 ++++---- lib/oxidized/model/ciscosma.rb | 80 +++---- lib/oxidized/model/cumulus.rb | 2 +- lib/oxidized/output/gitcrypt.rb | 484 ++++++++++++++++++++-------------------- 4 files changed, 327 insertions(+), 327 deletions(-) (limited to 'lib') diff --git a/lib/oxidized/model/asyncos.rb b/lib/oxidized/model/asyncos.rb index 875690b..ac19e34 100644 --- a/lib/oxidized/model/asyncos.rb +++ b/lib/oxidized/model/asyncos.rb @@ -1,49 +1,49 @@ 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" - data.sub re, '' - end - - # handle paging - expect /-Press Any Key For More-+.*$/ do |data, re| - send " " - data.sub re, '' - end - - cmd 'version' do |cfg| - comment cfg - end + # ESA prompt "(mail.example.com)> " + prompt /^\r*([(][\w. ]+[)][#>]\s+)$/ + 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| + 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 select passphrase display option - cfg.gsub! /Choose the passphrase option:/, '' - cfg.gsub! /1. Mask passphrases \(Files with masked passphrases cannot be loaded using/, '' - cfg.gsub! /loadconfig command\)/, '' - 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 prompt - cfg.gsub! /^\r*([(][\w. ]+[)][#>]\s+)$/, '' - cfg + 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 select passphrase display option + cfg.gsub! /Choose the passphrase option:/, '' + cfg.gsub! /1. Mask passphrases \(Files with masked passphrases cannot be loaded using/, '' + cfg.gsub! /loadconfig command\)/, '' + 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 prompt + cfg.gsub! /^\r*([(][\w. ]+[)][#>]\s+)$/, '' + cfg - end - - cfg :ssh do - pre_logout "exit" - end - + end + + cfg :ssh do + pre_logout "exit" + end + end diff --git a/lib/oxidized/model/ciscosma.rb b/lib/oxidized/model/ciscosma.rb index a52e38a..6777ad5 100644 --- a/lib/oxidized/model/ciscosma.rb +++ b/lib/oxidized/model/ciscosma.rb @@ -1,45 +1,45 @@ class CiscoSMA < Oxidized::Model - # SMA prompt "mail.example.com> " - prompt /^\r*([-\w. ]+\.[-\w. ]+\.[-\w. ]+[#>]\s+)$/ - comment '! ' - - # Select passphrase display option - expect /using loadconfig command\. \[Y\]\>/ do |data, re| - send "y\n" - data.sub re, '' - end - - # handle paging - expect /-Press Any Key For More-+.*$/ do |data, re| - send " " - data.sub re, '' - end - - cmd 'version' do |cfg| - comment cfg - end + # SMA prompt "mail.example.com> " + prompt /^\r*([-\w. ]+\.[-\w. ]+\.[-\w. ]+[#>]\s+)$/ + comment '! ' + + # Select passphrase display option + expect /using loadconfig command\. \[Y\]\>/ do |data, re| + send "y\n" + data.sub re, '' + end + + # handle paging + 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 select passphrase display option - cfg.gsub! /Do you want to mask the password\? Files with masked passwords cannot be loaded/, '' - cfg.gsub! /^\s+y/, '' - # Delete space - cfg.gsub! /\n\s{25}/, '' - # Delete after line - cfg.gsub! /([\/\-,.\w><@]+)(\s{27})/,"\\1" - # Add a carriage return - cfg.gsub! /([\/\-,.\w><@]+)(\s{6,8})([\/\-,.\w><@]+)/,"\\1\n\\2\\3" - # Delete prompt - cfg.gsub! /^\r*([-\w. ]+\.[-\w. ]+\.[-\w. ]+[#>]\s+)$/, '' - cfg + 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 select passphrase display option + cfg.gsub! /Do you want to mask the password\? Files with masked passwords cannot be loaded/, '' + cfg.gsub! /^\s+y/, '' + # Delete space + cfg.gsub! /\n\s{25}/, '' + # Delete after line + cfg.gsub! /([\/\-,.\w><@]+)(\s{27})/,"\\1" + # Add a carriage return + cfg.gsub! /([\/\-,.\w><@]+)(\s{6,8})([\/\-,.\w><@]+)/,"\\1\n\\2\\3" + # Delete prompt + cfg.gsub! /^\r*([-\w. ]+\.[-\w. ]+\.[-\w. ]+[#>]\s+)$/, '' + cfg - end - - cfg :ssh do - pre_logout "exit" - end - + end + + cfg :ssh do + pre_logout "exit" + end + end diff --git a/lib/oxidized/model/cumulus.rb b/lib/oxidized/model/cumulus.rb index 20acb8a..09f3955 100644 --- a/lib/oxidized/model/cumulus.rb +++ b/lib/oxidized/model/cumulus.rb @@ -68,7 +68,7 @@ class Cumulus < Oxidized::Model cfg += add_comment 'TRAFFIC' cfg += cmd 'cat /etc/cumulus/datapath/traffic.conf' - + cfg += add_comment 'ACL' cfg += cmd 'iptables -L -n' diff --git a/lib/oxidized/output/gitcrypt.rb b/lib/oxidized/output/gitcrypt.rb index b0d80f2..0567458 100644 --- a/lib/oxidized/output/gitcrypt.rb +++ b/lib/oxidized/output/gitcrypt.rb @@ -1,244 +1,244 @@ module Oxidized - class GitCrypt < Output - class GitCryptError < OxidizedError; end - begin - require 'git' - rescue LoadError - raise OxidizedError, 'git not found: sudo gem install ruby-git' - end - - attr_reader :commitref - - def initialize - @cfg = Oxidized.config.output.gitcrypt - @gitcrypt_cmd = "/usr/bin/git-crypt" - @gitcrypt_init = @gitcrypt_cmd + " init" - @gitcrypt_unlock = @gitcrypt_cmd + " unlock" - @gitcrypt_lock = @gitcrypt_cmd + " lock" - @gitcrypt_adduser = @gitcrypt_cmd + " add-gpg-user --trusted " - end - - def setup - if @cfg.empty? - Oxidized.asetus.user.output.gitcrypt.user = 'Oxidized' - Oxidized.asetus.user.output.gitcrypt.email = 'o@example.com' - Oxidized.asetus.user.output.gitcrypt.repo = File.join(Config::Root, 'oxidized.git') - Oxidized.asetus.save :user - raise NoConfig, 'no output git config, edit ~/.config/oxidized/config' - end - - 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 crypt_init repo - repo.chdir do - system(@gitcrypt_init) - @cfg.users.each do |user| - system("#{@gitcrypt_adduser} #{user}") - end - File.write(".gitattributes", "* filter=git-crypt diff=git-crypt\n.gitattributes !filter !diff") - repo.add(".gitattributes") - repo.commit("Initial commit: crypt all config files") - end - end - - def lock repo - repo.chdir do - system(@gitcrypt_lock) - end - end - - def unlock repo - repo.chdir do - system(@gitcrypt_unlock) - end - end - - def store file, outputs, opt={} - @msg = opt[:msg] - @user = (opt[:user] or @cfg.user) - @email = (opt[:email] or @cfg.email) - @opt = opt - @commitref = nil - repo = @cfg.repo - - outputs.types.each do |type| - type_cfg = '' - type_repo = File.join(File.dirname(repo), type + '.git') - outputs.type(type).each do |output| - (type_cfg << output; next) if not output.name - type_file = file + '--' + output.name - if @cfg.type_as_directory? - type_file = type + '/' + type_file - type_repo = repo - end - update type_repo, type_file, output - end - update type_repo, file, type_cfg - end - - update repo, file, outputs.to_cfg - end - - - def fetch node, group - begin - repo, path = yield_repo_and_path(node, group) - repo = Git.open repo - unlock repo - index = repo.index - # Empty repo ? - empty = File.exists? index.path - if empty - raise 'Empty git repo' - else - File.read path - end - lock repo - rescue - 'node not found' - end - end - - # give a hash of all oid revision for the given node, and the date of the commit - def version node, group - begin - repo, path = yield_repo_and_path(node, group) - - repo = Git.open repo - unlock repo - walker = repo.log.path(path) - i = -1 - tab = [] - walker.each do |commit| - hash = {} - hash[:date] = commit.date.to_s - hash[:oid] = commit.objectish - hash[:author] = commit.author - hash[:message] = commit.message - tab[i += 1] = hash - end - walker.reset - tab - rescue - 'node not found' - end - end - - #give the blob of a specific revision - def get_version node, group, oid - begin - repo, path = yield_repo_and_path(node, group) - repo = Git.open repo - unlock repo - repo.gtree(oid).files[path].contents - rescue - 'version not found' - ensure - lock repo - end - end - - #give a hash with the patch of a diff between 2 revision and the stats (added and deleted lines) - def get_diff node, group, oid1, oid2 - begin - diff_commits = nil - repo, path = yield_repo_and_path(node, group) - repo = Git.open repo - unlock repo - commit = repo.gcommit(oid1) - - if oid2 - commit_old = repo.gcommit(oid2) - diff = repo.diff(commit_old, commit) - stats = [diff.stats[:files][node.name][:insertions], diff.stats[:files][node.name][:deletions]] - diff.each do |patch| - if /#{node.name}\s+/.match(patch.patch.to_s.lines.first) - diff_commits = {:patch => patch.patch.to_s, :stat => stats} - break - end - end - else - stat = commit.parents[0].diff(commit).stats - stat = [stat[:files][node.name][:insertions],stat[:files][node.name][:deletions]] - patch = commit.parents[0].diff(commit).patch - diff_commits = {:patch => patch, :stat => stat} - end - lock repo - diff_commits - rescue - 'no diffs' - ensure - lock repo - end - end - - private - - def yield_repo_and_path(node, group) - repo, path = node.repo, node.name - - if group and @cfg.single_repo? - path = "#{group}/#{node.name}" - end - - [repo, path] - end - - def update repo, file, data - return if data.empty? - - if @opt[:group] - if @cfg.single_repo? - file = File.join @opt[:group], file - else - repo = if repo.is_a?(::String) - File.join File.dirname(repo), @opt[:group] + '.git' - else - repo[@opt[:group]] - end - end - end - - begin - update_repo repo, file, data, @msg, @user, @email - rescue Git::GitExecuteError, ArgumentError => open_error - Oxidized.logger.debug "open_error #{open_error} #{file}" - begin - grepo = Git.init repo - crypt_init grepo - rescue => create_error - raise GitCryptError, "first '#{open_error.message}' was raised while opening git repo, then '#{create_error.message}' was while trying to create git repo" - end - retry - end - end - - def update_repo repo, file, data, msg, user, email - grepo = Git.open repo - grepo.config('user.name', user) - grepo.config('user.email', email) - grepo.chdir do - unlock grepo - File.write(file, data) - grepo.add(file) - if grepo.status[file].nil? - grepo.commit(msg) - @commitref = grepo.log(1).first.objectish - true - elsif !grepo.status[file].type.nil? - grepo.commit(msg) - @commitref = grepo.log(1).first.objectish - true - end - lock grepo - end - end - end + class GitCrypt < Output + class GitCryptError < OxidizedError; end + begin + require 'git' + rescue LoadError + raise OxidizedError, 'git not found: sudo gem install ruby-git' + end + + attr_reader :commitref + + def initialize + @cfg = Oxidized.config.output.gitcrypt + @gitcrypt_cmd = "/usr/bin/git-crypt" + @gitcrypt_init = @gitcrypt_cmd + " init" + @gitcrypt_unlock = @gitcrypt_cmd + " unlock" + @gitcrypt_lock = @gitcrypt_cmd + " lock" + @gitcrypt_adduser = @gitcrypt_cmd + " add-gpg-user --trusted " + end + + def setup + if @cfg.empty? + Oxidized.asetus.user.output.gitcrypt.user = 'Oxidized' + Oxidized.asetus.user.output.gitcrypt.email = 'o@example.com' + Oxidized.asetus.user.output.gitcrypt.repo = File.join(Config::Root, 'oxidized.git') + Oxidized.asetus.save :user + raise NoConfig, 'no output git config, edit ~/.config/oxidized/config' + end + + 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 crypt_init repo + repo.chdir do + system(@gitcrypt_init) + @cfg.users.each do |user| + system("#{@gitcrypt_adduser} #{user}") + end + File.write(".gitattributes", "* filter=git-crypt diff=git-crypt\n.gitattributes !filter !diff") + repo.add(".gitattributes") + repo.commit("Initial commit: crypt all config files") + end + end + + def lock repo + repo.chdir do + system(@gitcrypt_lock) + end + end + + def unlock repo + repo.chdir do + system(@gitcrypt_unlock) + end + end + + def store file, outputs, opt={} + @msg = opt[:msg] + @user = (opt[:user] or @cfg.user) + @email = (opt[:email] or @cfg.email) + @opt = opt + @commitref = nil + repo = @cfg.repo + + outputs.types.each do |type| + type_cfg = '' + type_repo = File.join(File.dirname(repo), type + '.git') + outputs.type(type).each do |output| + (type_cfg << output; next) if not output.name + type_file = file + '--' + output.name + if @cfg.type_as_directory? + type_file = type + '/' + type_file + type_repo = repo + end + update type_repo, type_file, output + end + update type_repo, file, type_cfg + end + + update repo, file, outputs.to_cfg + end + + + def fetch node, group + begin + repo, path = yield_repo_and_path(node, group) + repo = Git.open repo + unlock repo + index = repo.index + # Empty repo ? + empty = File.exists? index.path + if empty + raise 'Empty git repo' + else + File.read path + end + lock repo + rescue + 'node not found' + end + end + + # give a hash of all oid revision for the given node, and the date of the commit + def version node, group + begin + repo, path = yield_repo_and_path(node, group) + + repo = Git.open repo + unlock repo + walker = repo.log.path(path) + i = -1 + tab = [] + walker.each do |commit| + hash = {} + hash[:date] = commit.date.to_s + hash[:oid] = commit.objectish + hash[:author] = commit.author + hash[:message] = commit.message + tab[i += 1] = hash + end + walker.reset + tab + rescue + 'node not found' + end + end + + #give the blob of a specific revision + def get_version node, group, oid + begin + repo, path = yield_repo_and_path(node, group) + repo = Git.open repo + unlock repo + repo.gtree(oid).files[path].contents + rescue + 'version not found' + ensure + lock repo + end + end + + #give a hash with the patch of a diff between 2 revision and the stats (added and deleted lines) + def get_diff node, group, oid1, oid2 + begin + diff_commits = nil + repo, path = yield_repo_and_path(node, group) + repo = Git.open repo + unlock repo + commit = repo.gcommit(oid1) + + if oid2 + commit_old = repo.gcommit(oid2) + diff = repo.diff(commit_old, commit) + stats = [diff.stats[:files][node.name][:insertions], diff.stats[:files][node.name][:deletions]] + diff.each do |patch| + if /#{node.name}\s+/.match(patch.patch.to_s.lines.first) + diff_commits = {:patch => patch.patch.to_s, :stat => stats} + break + end + end + else + stat = commit.parents[0].diff(commit).stats + stat = [stat[:files][node.name][:insertions],stat[:files][node.name][:deletions]] + patch = commit.parents[0].diff(commit).patch + diff_commits = {:patch => patch, :stat => stat} + end + lock repo + diff_commits + rescue + 'no diffs' + ensure + lock repo + end + end + + private + + def yield_repo_and_path(node, group) + repo, path = node.repo, node.name + + if group and @cfg.single_repo? + path = "#{group}/#{node.name}" + end + + [repo, path] + end + + def update repo, file, data + return if data.empty? + + if @opt[:group] + if @cfg.single_repo? + file = File.join @opt[:group], file + else + repo = if repo.is_a?(::String) + File.join File.dirname(repo), @opt[:group] + '.git' + else + repo[@opt[:group]] + end + end + end + + begin + update_repo repo, file, data, @msg, @user, @email + rescue Git::GitExecuteError, ArgumentError => open_error + Oxidized.logger.debug "open_error #{open_error} #{file}" + begin + grepo = Git.init repo + crypt_init grepo + rescue => create_error + raise GitCryptError, "first '#{open_error.message}' was raised while opening git repo, then '#{create_error.message}' was while trying to create git repo" + end + retry + end + end + + def update_repo repo, file, data, msg, user, email + grepo = Git.open repo + grepo.config('user.name', user) + grepo.config('user.email', email) + grepo.chdir do + unlock grepo + File.write(file, data) + grepo.add(file) + if grepo.status[file].nil? + grepo.commit(msg) + @commitref = grepo.log(1).first.objectish + true + elsif !grepo.status[file].type.nil? + grepo.commit(msg) + @commitref = grepo.log(1).first.objectish + true + end + lock grepo + end + end + end end -- cgit v1.2.1 From 09bcf46e276662ef518aac5fb11bc2eb4e127d36 Mon Sep 17 00:00:00 2001 From: rgnv Date: Thu, 12 Apr 2018 15:22:50 -0700 Subject: Added Cisco Spark hook --- lib/oxidized/hook/ciscosparkdiff.rb | 54 +++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 lib/oxidized/hook/ciscosparkdiff.rb (limited to 'lib') diff --git a/lib/oxidized/hook/ciscosparkdiff.rb b/lib/oxidized/hook/ciscosparkdiff.rb new file mode 100644 index 0000000..a1c9130 --- /dev/null +++ b/lib/oxidized/hook/ciscosparkdiff.rb @@ -0,0 +1,54 @@ +require 'cisco_spark' + +# defaults to posting a diff, if messageformat is supplied them a message will be posted too +# diffenable defaults to true +# Modified from slackdiff + +class CiscoSparkDiff < Oxidized::Hook + def validate_cfg! + raise KeyError, 'hook.accesskey is required' unless cfg.has_key?('accesskey') + raise KeyError, 'hook.space is required' unless cfg.has_key?('space') + end + + def run_hook(ctx) + if ctx.node + if ctx.event.to_s == "post_store" + log "Connecting to Cisco Spark" + CiscoSpark.configure do |config| + config.api_key = cfg.accesskey + config.proxy = cfg.proxy if cfg.has_key?('proxy') + end + space = cfg.space + client = CiscoSpark::Room.new(id: space) + client.fetch + log "Connected" + # diff snippet - default + diffenable = true + if cfg.has_key?('diff') == true + if cfg.diff == false + diffenable = false + end + end + if diffenable == true + gitoutput = ctx.node.output.new + diff = gitoutput.get_diff ctx.node, ctx.node.group, ctx.commitref, nil + title = "#{ctx.node.name.to_s}" + log "Posting diff as snippet to #{cfg.space}" + message = CiscoSpark::Message.new(text: 'Device ' + title + ' modified:' + "\n" + diff[:patch].lines.to_a[4..-1].join + ) + room = CiscoSpark::Room.new(id: space) + room.send_message(message) + end + # message custom formatted - optional + if cfg.has_key?('message') == true + log cfg.message + msg = 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.space}" + client.chat_postMessage(channel: cfg.channel, text: msg, as_user: true) + end + log "Finished" + end + end + end +end -- cgit v1.2.1 From ec90b081f0fed05497ce6ae21e4b4ba4d44ecc01 Mon Sep 17 00:00:00 2001 From: rgnv Date: Thu, 12 Apr 2018 15:41:31 -0700 Subject: fix formatting to comply with Rubocop --- lib/oxidized/hook/ciscosparkdiff.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/oxidized/hook/ciscosparkdiff.rb b/lib/oxidized/hook/ciscosparkdiff.rb index a1c9130..12094e6 100644 --- a/lib/oxidized/hook/ciscosparkdiff.rb +++ b/lib/oxidized/hook/ciscosparkdiff.rb @@ -22,7 +22,6 @@ class CiscoSparkDiff < Oxidized::Hook client = CiscoSpark::Room.new(id: space) client.fetch log "Connected" - # diff snippet - default diffenable = true if cfg.has_key?('diff') == true if cfg.diff == false @@ -34,12 +33,10 @@ class CiscoSparkDiff < Oxidized::Hook diff = gitoutput.get_diff ctx.node, ctx.node.group, ctx.commitref, nil title = "#{ctx.node.name.to_s}" log "Posting diff as snippet to #{cfg.space}" - message = CiscoSpark::Message.new(text: 'Device ' + title + ' modified:' + "\n" + diff[:patch].lines.to_a[4..-1].join - ) + message = CiscoSpark::Message.new(text: 'Device ' + title + ' modified:' + "\n" + diff[:patch].lines.to_a[4..-1].join) room = CiscoSpark::Room.new(id: space) room.send_message(message) end - # message custom formatted - optional if cfg.has_key?('message') == true log cfg.message msg = 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} -- cgit v1.2.1 From a26a1f78a71a03f5de7bbeee11a87d57be6a5343 Mon Sep 17 00:00:00 2001 From: Wild Kat Date: Sun, 15 Apr 2018 08:58:25 +0200 Subject: massage into rubocop compliance --- lib/oxidized/hook/ciscosparkdiff.rb | 66 ++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 34 deletions(-) (limited to 'lib') diff --git a/lib/oxidized/hook/ciscosparkdiff.rb b/lib/oxidized/hook/ciscosparkdiff.rb index 12094e6..d43ff81 100644 --- a/lib/oxidized/hook/ciscosparkdiff.rb +++ b/lib/oxidized/hook/ciscosparkdiff.rb @@ -11,41 +11,39 @@ class CiscoSparkDiff < Oxidized::Hook end def run_hook(ctx) - if ctx.node - if ctx.event.to_s == "post_store" - log "Connecting to Cisco Spark" - CiscoSpark.configure do |config| - config.api_key = cfg.accesskey - config.proxy = cfg.proxy if cfg.has_key?('proxy') - end - space = cfg.space - client = CiscoSpark::Room.new(id: space) - client.fetch - log "Connected" - diffenable = true - if cfg.has_key?('diff') == true - if cfg.diff == false - diffenable = false - end - end - if diffenable == true - gitoutput = ctx.node.output.new - diff = gitoutput.get_diff ctx.node, ctx.node.group, ctx.commitref, nil - title = "#{ctx.node.name.to_s}" - log "Posting diff as snippet to #{cfg.space}" - message = CiscoSpark::Message.new(text: 'Device ' + title + ' modified:' + "\n" + diff[:patch].lines.to_a[4..-1].join) - room = CiscoSpark::Room.new(id: space) - room.send_message(message) - end - if cfg.has_key?('message') == true - log cfg.message - msg = 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.space}" - client.chat_postMessage(channel: cfg.channel, text: msg, as_user: true) - end - log "Finished" + return unless ctx.node + return unless ctx.event.to_s == "post_store" + log "Connecting to Cisco Spark" + CiscoSpark.configure do |config| + config.api_key = cfg.accesskey + config.proxy = cfg.proxy if cfg.has_key?('proxy') + end + space = cfg.space + client = CiscoSpark::Room.new(id: space) + client.fetch + log "Connected" + diffenable = true + if cfg.has_key?('diff') == true + if cfg.diff == false + diffenable = false end end + if diffenable == true + gitoutput = ctx.node.output.new + diff = gitoutput.get_diff ctx.node, ctx.node.group, ctx.commitref, nil + title = ctx.node.name.to_s + log "Posting diff as snippet to #{cfg.space}" + message = CiscoSpark::Message.new(text: 'Device ' + title + ' modified:' + "\n" + diff[:patch].lines.to_a[4..-1].join) + room = CiscoSpark::Room.new(id: space) + room.send_message(message) + end + if cfg.has_key?('message') == true + log cfg.message + 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.space}" + client.chat_postMessage(channel: cfg.channel, text: msg, as_user: true) + end + log "Finished" end end -- cgit v1.2.1 From cc5c846b3b88cafd8c01c645e6ada3bab714ae91 Mon Sep 17 00:00:00 2001 From: Wild Kat Date: Sun, 15 Apr 2018 13:08:53 +0200 Subject: restructure xmppdiff.rb to comply with rubocop --- lib/oxidized/hook/xmppdiff.rb | 86 +++++++++++++++++++++---------------------- 1 file changed, 42 insertions(+), 44 deletions(-) (limited to 'lib') diff --git a/lib/oxidized/hook/xmppdiff.rb b/lib/oxidized/hook/xmppdiff.rb index 396d1b3..52cc0e0 100644 --- a/lib/oxidized/hook/xmppdiff.rb +++ b/lib/oxidized/hook/xmppdiff.rb @@ -7,54 +7,52 @@ class XMPPDiff < Oxidized::Hook raise KeyError, 'hook.password is required' unless cfg.has_key?('password') raise KeyError, 'hook.channel is required' unless cfg.has_key?('channel') raise KeyError, 'hook.nick is required' unless cfg.has_key?('nick') - end + end def run_hook(ctx) - if ctx.node - if ctx.event.to_s == "post_store" - begin - Timeout::timeout(15) do - gitoutput = ctx.node.output.new - diff = gitoutput.get_diff ctx.node, ctx.node.group, ctx.commitref, nil - - interesting = diff[:patch].lines.to_a[4..-1].any? { |line| - ["+", "-"].include?(line[0]) and not ["#", "!"].include?(line[1]) - } - interesting &&= diff[:patch].lines.to_a[5..-1].any? { |line| line[0] == '-' } - interesting &&= diff[:patch].lines.to_a[5..-1].any? { |line| line[0] == '+' } - - if interesting - log "Connecting to XMPP" - client = Jabber::Client.new(Jabber::JID.new(cfg.jid)) - client.connect - 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.to_s} #{ctx.node.group.to_s} #{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 - log "timed out" + return unless ctx.node + return unless ctx.event.to_s == "post_store" + begin + Timeout.timeout(15) do + gitoutput = ctx.node.output.new + diff = gitoutput.get_diff ctx.node, ctx.node.group, ctx.commitref, nil + + interesting = diff[:patch].lines.to_a[4..-1].any? do |line| + ["+", "-"].include?(line[0]) and not ["#", "!"].include?(line[1]) + end + interesting &&= diff[:patch].lines.to_a[5..-1].any? { |line| line[0] == '-' } + interesting &&= diff[:patch].lines.to_a[5..-1].any? { |line| line[0] == '+' } + + if interesting + log "Connecting to XMPP" + client = Jabber::Client.new(Jabber::JID.new(cfg.jid)) + client.connect + 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 + log "timed out" end end end -- cgit v1.2.1 From 140954f78e50bed1aaf3f8fd42f849e3892e55c0 Mon Sep 17 00:00:00 2001 From: Wild Kat Date: Sun, 15 Apr 2018 13:24:05 +0200 Subject: restructure slackdiff.rb to comply with rubocop --- lib/oxidized/hook/slackdiff.rb | 77 ++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 40 deletions(-) (limited to 'lib') diff --git a/lib/oxidized/hook/slackdiff.rb b/lib/oxidized/hook/slackdiff.rb index 7cd4465..e271d5f 100644 --- a/lib/oxidized/hook/slackdiff.rb +++ b/lib/oxidized/hook/slackdiff.rb @@ -10,47 +10,44 @@ class SlackDiff < Oxidized::Hook end def run_hook(ctx) - if ctx.node - if 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') - end - client = Slack::Client.new - client.auth_test - log "Connected" - # diff snippet - default - diffenable = true - if cfg.has_key?('diff') == true - if cfg.diff == false - diffenable = false - end - end - if diffenable == true - gitoutput = ctx.node.output.new - diff = gitoutput.get_diff ctx.node, ctx.node.group, ctx.commitref, nil - unless diff == "no diffs" - title = "#{ctx.node.name.to_s} #{ctx.node.group.to_s} #{ctx.node.model.class.name.to_s.downcase}" - log "Posting diff as snippet to #{cfg.channel}" - client.files_upload(channels: cfg.channel, as_user: true, - content: diff[:patch].lines.to_a[4..-1].join, - filetype: "diff", - title: title, - filename: "change" - ) - end - end - # message custom formatted - optional - if cfg.has_key?('message') == true - log cfg.message - msg = 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) - end - log "Finished" + return unless ctx.node + 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') + end + client = Slack::Client.new + client.auth_test + log "Connected" + # diff snippet - default + diffenable = true + if cfg.has_key?('diff') == true + if cfg.diff == false + diffenable = false + end + end + if diffenable == true + gitoutput = ctx.node.output.new + diff = gitoutput.get_diff ctx.node, ctx.node.group, ctx.commitref, nil + unless diff == "no diffs" + title = "#{ctx.node.name} #{ctx.node.group} #{ctx.node.model.class.name.to_s.downcase}" + log "Posting diff as snippet to #{cfg.channel}" + client.files_upload(channels: cfg.channel, as_user: true, + content: diff[:patch].lines.to_a[4..-1].join, + filetype: "diff", + title: title, + filename: "change") end end + # message custom formatted - optional + if cfg.has_key?('message') == true + log cfg.message + 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) + end + log "Finished" end end -- cgit v1.2.1 From b29550ce0cfaf6192652747d340da2dc777ac22b Mon Sep 17 00:00:00 2001 From: Zsolt Zsiros Date: Mon, 16 Apr 2018 14:48:43 +0200 Subject: model: netgear.rb support for older models (#1268) * Added support for older models (FW 5.x.y.z like on GS110TP, GS748Tv4, etc) * Fixed prompt regex * docs/Model-Notes/Netgear created * docs/Model-Notes/Netgear fixed typos --- lib/oxidized/model/netgear.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/oxidized/model/netgear.rb b/lib/oxidized/model/netgear.rb index 0ab1349..a32eb66 100644 --- a/lib/oxidized/model/netgear.rb +++ b/lib/oxidized/model/netgear.rb @@ -1,15 +1,16 @@ class Netgear < Oxidized::Model comment '!' - prompt /^(\([\w\-.]+\)\s[#>])$/ + prompt /^(\([\w\s\-.]+\)\s[#>])$/ cmd :secret do |cfg| cfg.gsub!(/password (\S+)/, 'password ') + cfg.gsub!(/encrypted (\S+)/, 'encrypted ') cfg end cfg :telnet do - username /^User:/ + username /^(User:|Applying Interface configuration, please wait ...)/ end cfg :telnet, :ssh do -- cgit v1.2.1 From 1b66348be97d4603566a262756d6ad5a2d21bd58 Mon Sep 17 00:00:00 2001 From: Wild Kat Date: Mon, 16 Apr 2018 21:03:35 +0200 Subject: restructure awssns.rb to comply with rubocop --- lib/oxidized/hook/awssns.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/oxidized/hook/awssns.rb b/lib/oxidized/hook/awssns.rb index dbc2d47..82c118e 100644 --- a/lib/oxidized/hook/awssns.rb +++ b/lib/oxidized/hook/awssns.rb @@ -19,9 +19,9 @@ class AwsSns < Oxidized::Hook :node => ctx.node.name.to_s ) end - topic.publish({ + topic.publish( message: message.to_json - }) + ) end end -- cgit v1.2.1 From 12c770dd3504748d3e67f99175b26d0515a3d283 Mon Sep 17 00:00:00 2001 From: Yuri Zubov Date: Thu, 19 Apr 2018 14:19:41 +0300 Subject: Basic support for NDMS OS (Zyxel Keenetic) --- lib/oxidized/model/ndms.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 lib/oxidized/model/ndms.rb (limited to 'lib') diff --git a/lib/oxidized/model/ndms.rb b/lib/oxidized/model/ndms.rb new file mode 100644 index 0000000..c632bb9 --- /dev/null +++ b/lib/oxidized/model/ndms.rb @@ -0,0 +1,25 @@ +class NDMS < Oxidized::Model + + # Pull config from Zyxel Keenetic devices from version NDMS >= 2.0 + + comment '! ' + + prompt /^([\w.@()-]+[#>]\s?)/m + + cmd 'show version' do |cfg| + cfg = cfg.each_line.to_a[1..-3].join + comment cfg + end + + cmd 'show running-config' do |cfg| + cfg = cfg.each_line.to_a[1..-2] + cfg = cfg.reject { |line| line.match /(clock date|checksum)/ }.join + cfg + end + + cfg :telnet do + username /^Login:/ + password /^Password:/ + pre_logout 'exit' + end +end -- cgit v1.2.1 From 72a4fb26446f74903e69b75a69c45d58500d6d19 Mon Sep 17 00:00:00 2001 From: ja-frog <31773963+ja-frog@users.noreply.github.com> Date: Mon, 9 Apr 2018 15:40:16 -0500 Subject: Add handling for devices that only prompt for a password via SSH An approach to handling devices that do not prompt for a username, only a password when connecting via ssh. The Calix B6 inspired this. --- lib/oxidized/input/ssh.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib') diff --git a/lib/oxidized/input/ssh.rb b/lib/oxidized/input/ssh.rb index 27e81e0..d84b349 100644 --- a/lib/oxidized/input/ssh.rb +++ b/lib/oxidized/input/ssh.rb @@ -123,6 +123,11 @@ module Oxidized cmd @node.auth[:username], password cmd @node.auth[:password] end + elsif @password + match = expect password, @node.prompt + if match == password + cmd @node.auth[:password] + end else expect @node.prompt end -- cgit v1.2.1 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') 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