Skip to content

Commit

Permalink
Merge branch 'ytti:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
sugresmax committed Oct 26, 2023
2 parents a0cfb48 + 52c1f98 commit 8f77be5
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 40 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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]

Expand Down
2 changes: 2 additions & 0 deletions docs/Supported-OS-Types.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/oxidized/model/aoscx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions lib/oxidized/model/aricentiss.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/oxidized/model/iosxr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
34 changes: 34 additions & 0 deletions lib/oxidized/model/mimosab11.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions lib/oxidized/model/sros.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion lib/oxidized/model/vrp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions lib/oxidized/output/gitcrypt.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module Oxidized
class GitCrypt < Output
using Refinements
class GitCryptError < OxidizedError; end
begin
require 'git'
Expand Down
63 changes: 29 additions & 34 deletions lib/oxidized/source/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand All @@ -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+\]/)
Expand All @@ -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
Expand All @@ -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

0 comments on commit 8f77be5

Please sign in to comment.