diff --git a/CHANGELOG.md b/CHANGELOG.md index 8891d3911..38ff21841 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,10 +9,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ## Added - model for D-Link cisco like CLI (@mirackle-spb) - model for Ruijie Networks RGOS devices (@spike77453) +- added support for AricentISS 2.x firmware (@davromaniak) - model for Asterfusion Network Operating System (@avl-dev) - pagination for http source (@davama) - model for Ericsson Miniling 6600 series (@schouwenburg) - +- model for Mimosa B11 (@ritzbhuj) + Added ability to send mail with the Docker container + Documentation to send mail with hooks @@ -21,6 +22,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). - dlink: fixed prompt for other dlink switches, added additional uptime removal expressions (@mirackle-spb) - Collect VC info for juniper ex3400 (@ermuller) - adva: fix config content for recovery process, collect config delta instead of current (@MichiMeyer) +- iosxr: include last config changed by in model (@electrocret) +- Added support for Nokia SAR 7705 HMC in SROS model (@schouwenburg) ## Fixed @@ -31,8 +34,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). - fixed netscaler backups with hostname set #2828 (@electrocret) - Do not redirect stderr when fetching opnsense version since default shell (csh) doesn't support it (@spike77453) - Fixed fan RPM speeds included in Aruba CX diffs (@danpoltawski) +- Gitcrypt output refinements (@electrocret) - Remove constantly updating dates from backup of Adtran config (@davesbell) - fixed prompt for Cumulus to allow usernames with dots and dashes (@ktims) +- fixed source http when source is librenms (@davama) ## [0.29.1 - 2023-04-24] diff --git a/docs/Supported-OS-Types.md b/docs/Supported-OS-Types.md index 6f1c85df1..5e6960380 100644 --- a/docs/Supported-OS-Types.md +++ b/docs/Supported-OS-Types.md @@ -188,6 +188,8 @@ * Mikrotik * [RouterOS](/lib/oxidized/model/routeros.rb) * [SwOS and SwOS Lite](/lib/oxidized/model/swos.rb) +* Mimosa + * [Mimosa (B11)](/lib/oxidized/model/mimosab11.rb) * Motorola * [RFS](/lib/oxidized/model/mtrlrfs.rb) * MRV diff --git a/lib/oxidized/model/aoscx.rb b/lib/oxidized/model/aoscx.rb index 07ef3a89e..e7a5620eb 100644 --- a/lib/oxidized/model/aoscx.rb +++ b/lib/oxidized/model/aoscx.rb @@ -70,7 +70,7 @@ class Aoscx < Oxidized::Model comment cfg end - cmd 'show system | exclude "Up Time" | exclude "CPU" | exclude "Memory"' do |cfg| + cmd 'show system | exclude "Up Time|CPU|Memory|Pkts .x|Lowest|Missed"' do |cfg| comment cfg end diff --git a/lib/oxidized/model/aricentiss.rb b/lib/oxidized/model/aricentiss.rb index a8dfb9cea..bb49855e4 100644 --- a/lib/oxidized/model/aricentiss.rb +++ b/lib/oxidized/model/aricentiss.rb @@ -2,6 +2,10 @@ # #show version # Switch ID Hardware Version Firmware Version # 0 SSE-G48-TG4 (P2-01) 1.0.16-9 +# and +# # show version +# Switch ID Hardware Version Firmware Version +# 0 MBM-XEM-002 (B6-01) 2.1.3-25 class AricentISS < Oxidized::Model using Refinements @@ -13,6 +17,9 @@ class AricentISS < Oxidized::Model # 1.0.18-15 is known to include the corrected spelling post_login 'no cli pagination' post_login 'no cli pagignation' + # Starting firmware 2.0, pagination is done differently. + # This configuration is reset after the session ends. + post_login 'conf t; set cli pagination off; exit' pre_logout 'exit' end diff --git a/lib/oxidized/model/iosxr.rb b/lib/oxidized/model/iosxr.rb index 5e94c249f..74db58436 100644 --- a/lib/oxidized/model/iosxr.rb +++ b/lib/oxidized/model/iosxr.rb @@ -25,7 +25,7 @@ class IOSXR < Oxidized::Model end cmd 'show running-config' do |cfg| - cfg = cfg.each_line.to_a[3..-1].join + cfg = cfg.each_line.to_a[1..-1].join cfg end diff --git a/lib/oxidized/model/mimosab11.rb b/lib/oxidized/model/mimosab11.rb new file mode 100644 index 000000000..b7ac07143 --- /dev/null +++ b/lib/oxidized/model/mimosab11.rb @@ -0,0 +1,34 @@ +begin + # Mechanize has to be intialized here as the login needs a POST request + require "mechanize" +rescue LoadError + # Oxidized requires mechanize + raise Oxidized::OxidizedError, "mechanize not found: sudo gem install mechanize" +end + +class Mimosab11 < Oxidized::Model + using Refinements + # Callback cfg_cb function to login(POST) then get(GET) the configuration + cfg_cb = lambda do + @e = Mechanize.new + # Set login query endpoint(lqe) and login POST data(lqp) + lqe = "https://#{@node.ip}/?q=index.login&mimosa_ajax=1" + lgp = { "username" => "configure", "password" => @password } + # Set get request endpoint(gc) for config + gc = "https://#{@node.ip}/?q=preferences.configure&mimosa_action=download" + # Not to verify self signed + @e.verify_mode = 0 + @e.post(lqe, lgp) + cfg = @e.get(gc) + cfg.body + end + + cmd cfg_cb do |cfg| + cfg + end + + cfg :http do + @username = @node.auth[:username] + @password = @node.auth[:password] + end +end diff --git a/lib/oxidized/model/sros.rb b/lib/oxidized/model/sros.rb index 82191acf5..4e0c0aa47 100644 --- a/lib/oxidized/model/sros.rb +++ b/lib/oxidized/model/sros.rb @@ -75,14 +75,14 @@ class SROS < Oxidized::Model # # Show the running persistent indices. # - cmd 'admin display-config index' do |cfg| + cmd "admin display-config index\n" do |cfg| comment cfg end # # Show the running configuration. # - cmd 'admin display-config' do |cfg| + cmd "admin display-config\n" do |cfg| cfg end diff --git a/lib/oxidized/model/vrp.rb b/lib/oxidized/model/vrp.rb index 71de54c82..06ca4dfad 100644 --- a/lib/oxidized/model/vrp.rb +++ b/lib/oxidized/model/vrp.rb @@ -27,15 +27,17 @@ class VRP < Oxidized::Model end cmd 'display version' do |cfg| - cfg = cfg.each_line.reject { |l| l.match /uptime/ }.join + cfg = cfg.each_line.reject { |l| l.match /uptime|^\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d(\.\d\d\d)? ?(\+\d\d:\d\d)?$/ }.join comment cfg end cmd 'display device' do |cfg| + cfg = cfg.each_line.reject { |l| l.match /^\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d(\.\d\d\d)? ?(\+\d\d:\d\d)?$/ }.join comment cfg end cmd 'display current-configuration all' do |cfg| + cfg = cfg.each_line.reject { |l| l.match /^\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d(\.\d\d\d)? ?(\+\d\d:\d\d)?$/ }.join cfg end end diff --git a/lib/oxidized/output/gitcrypt.rb b/lib/oxidized/output/gitcrypt.rb index 08986d9d3..3d6a456ad 100644 --- a/lib/oxidized/output/gitcrypt.rb +++ b/lib/oxidized/output/gitcrypt.rb @@ -1,5 +1,6 @@ module Oxidized class GitCrypt < Output + using Refinements class GitCryptError < OxidizedError; end begin require 'git' diff --git a/lib/oxidized/source/http.rb b/lib/oxidized/source/http.rb index 32dbeb161..dd7986fee 100644 --- a/lib/oxidized/source/http.rb +++ b/lib/oxidized/source/http.rb @@ -6,6 +6,7 @@ def initialize end def setup + Oxidized.setup_logger return unless @cfg.url.empty? raise NoConfig, 'no source http url config, edit ~/.config/oxidized/config' @@ -18,8 +19,17 @@ def setup def load(node_want = nil) nodes = [] - data = read_http(node_want) - data.each do |node| + node_data = [] + uri = URI.parse(@cfg.url) + data = JSON.parse(read_http(uri, node_want)) + node_data = data + node_data = string_navigate(data, @cfg.hosts_location) if @cfg.hosts_location? + if @cfg.pagination? + node_data = pagination(data, node_want) + end + + # at this point we have all the nodes; pagination or not + node_data.each do |node| next if node.empty? # map node parameters @@ -44,14 +54,6 @@ def load(node_want = nil) private - def set_request(l_uri, l_headers, l_node_want) - req_uri = l_uri.request_uri - req_uri = "#{req_uri}/#{l_node_want}" if l_node_want - request = Net::HTTP::Get.new(req_uri, l_headers) - request.basic_auth(@cfg.user, @cfg.pass) if @cfg.user? && @cfg.pass? - request - end - def string_navigate(object, wants) wants = wants.split(".").map do |want| head, match, _tail = want.partition(/\[\d+\]/) @@ -63,31 +65,23 @@ def string_navigate(object, wants) object end - def check_pagination(response, http, headers, node_want) + def pagination(data, node_want) node_data = [] - if @cfg.pagination? - raise Oxidized::OxidizedError, "if using pagination, 'pagination_key_name' setting must be set" unless @cfg.pagination_key_name? - - next_key = @cfg.pagination_key_name - loop do - data = JSON.parse(response.body) - node_data += string_navigate(data, @cfg.hosts_location) if @cfg.hosts_location? - break if data[next_key].nil? - - new_uri = URI.parse(data[next_key]) if data.has_key?(next_key) - request = set_request(new_uri, headers, node_want) - response = http.request(request) - end - # since new feature; dont break curent configs - else - data = JSON.parse(response.body) - node_data += string_navigate(data, @cfg.hosts_location) if @cfg.hosts_location? + raise Oxidized::OxidizedError, "if using pagination, 'pagination_key_name' setting must be set" unless @cfg.pagination_key_name? + + next_key = @cfg.pagination_key_name + loop do + node_data += string_navigate(data, @cfg.hosts_location) if @cfg.hosts_location? + break if data[next_key].nil? + + new_uri = URI.parse(data[next_key]) if data.has_key?(next_key) + data = JSON.parse(read_http(new_uri, node_want)) + node_data += string_navigate(data, @cfg.hosts_location) if @cfg.hosts_location? end node_data end - def read_http(node_want) - uri = URI.parse(@cfg.url) + def read_http(uri, node_want) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true if uri.scheme == 'https' http.verify_mode = OpenSSL::SSL::VERIFY_NONE unless @cfg.secure @@ -101,10 +95,11 @@ def read_http(node_want) headers[header] = value end - request = set_request(uri, headers, node_want) - response = http.request(request) - - check_pagination(response, http, headers, node_want) + req_uri = uri.request_uri + req_uri = "#{req_uri}/#{node_want}" if node_want + request = Net::HTTP::Get.new(req_uri, headers) + request.basic_auth(@cfg.user, @cfg.pass) if @cfg.user? && @cfg.pass? + http.request(request).body end end end