oxidized 0.36.0 → 0.38.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE/bug_report.md +30 -4
- data/.github/ISSUE_TEMPLATE/feature_request.md +10 -3
- data/.github/ISSUE_TEMPLATE/support-request.md +30 -4
- data/.github/PULL_REQUEST_TEMPLATE.md +3 -1
- data/.github/workflows/codeql.yml +4 -4
- data/.github/workflows/publishdocker.yml +2 -2
- data/.github/workflows/ruby.yml +10 -3
- data/.github/workflows/stale.yml +1 -1
- data/.rubocop.yml +3 -0
- data/.rubocop_todo.yml +2 -8
- data/AGENTS.md +174 -0
- data/CHANGELOG.md +127 -0
- data/CONTRIBUTING.md +78 -44
- data/Dockerfile +8 -4
- data/README.md +8 -1
- data/Rakefile +1 -1
- data/docs/Configuration.md +10 -1
- data/docs/Creating-Models.md +6 -6
- data/docs/DeviceSimulation.md +80 -51
- data/docs/Docker.md +49 -0
- data/docs/Hooks.md +92 -67
- data/docs/Inputs.md +95 -16
- data/docs/Issues.md +49 -13
- data/docs/Model-Notes/FTD.md +64 -0
- data/docs/Model-Notes/GrandstreamHT8xx.md +8 -0
- data/docs/Model-Notes/HPEAruba.md +5 -0
- data/docs/Model-Notes/ITMGOS.md +40 -0
- data/docs/Model-Notes/PanOS_API.md +20 -1
- data/docs/Model-Notes/RouterOS.md +13 -0
- data/docs/Model-Notes/TPLink.md +75 -0
- data/docs/Model-Notes/TrueNAS.md +11 -7
- data/docs/Outputs.md +1 -0
- data/docs/Release.md +49 -22
- data/docs/Ruby-API.md +231 -9
- data/docs/Supported-OS-Types.md +10 -4
- data/docs/Troubleshooting.md +8 -9
- data/extra/device2yaml.rb +21 -5
- data/extra/hooks/modelrulesadvanced.rb +2 -4
- data/extra/oxidized.service +0 -1
- data/extra/syslog.rb +1 -1
- data/lib/oxidized/cli/support.rb +149 -0
- data/lib/oxidized/cli.rb +9 -0
- data/lib/oxidized/config/vars.rb +2 -1
- data/lib/oxidized/core.rb +20 -0
- data/lib/oxidized/hook/ciscosparkdiff.rb +1 -1
- data/lib/oxidized/hook/slackdiff.rb +1 -1
- data/lib/oxidized/hook/xmppdiff.rb +2 -2
- data/lib/oxidized/hook.rb +2 -0
- data/lib/oxidized/input/cli.rb +14 -2
- data/lib/oxidized/input/debugtext.rb +40 -0
- data/lib/oxidized/input/debugyaml.rb +82 -0
- data/lib/oxidized/input/exec.rb +1 -6
- data/lib/oxidized/input/ftp.rb +0 -4
- data/lib/oxidized/input/http.rb +23 -15
- data/lib/oxidized/input/scp.rb +3 -1
- data/lib/oxidized/input/ssh.rb +28 -21
- data/lib/oxidized/input/sshbase.rb +50 -24
- data/lib/oxidized/input/telnet.rb +14 -11
- data/lib/oxidized/input/tftp.rb +0 -4
- data/lib/oxidized/model/acos.rb +2 -2
- data/lib/oxidized/model/acsw.rb +1 -1
- data/lib/oxidized/model/adtran.rb +1 -1
- data/lib/oxidized/model/aireos.rb +3 -3
- data/lib/oxidized/model/aoscx.rb +20 -12
- data/lib/oxidized/model/aosw.rb +8 -13
- data/lib/oxidized/model/arbos.rb +1 -1
- data/lib/oxidized/model/aricentiss.rb +1 -1
- data/lib/oxidized/model/asa.rb +1 -1
- data/lib/oxidized/model/asternos.rb +1 -1
- data/lib/oxidized/model/audiocodesmp.rb +1 -1
- data/lib/oxidized/model/awplus.rb +4 -3
- data/lib/oxidized/model/bdcom.rb +1 -1
- data/lib/oxidized/model/br6910.rb +1 -1
- data/lib/oxidized/model/c4cmts.rb +1 -1
- data/lib/oxidized/model/ciscosmb.rb +0 -1
- data/lib/oxidized/model/cnos.rb +10 -1
- data/lib/oxidized/model/comnetms.rb +1 -1
- data/lib/oxidized/model/coriantgroove.rb +1 -1
- data/lib/oxidized/model/cumulus.rb +3 -3
- data/lib/oxidized/model/dellx.rb +1 -1
- data/lib/oxidized/model/dlink.rb +1 -1
- data/lib/oxidized/model/dlinknextgen.rb +2 -1
- data/lib/oxidized/model/dnos.rb +2 -2
- data/lib/oxidized/model/eatonnetwork.rb +33 -32
- data/lib/oxidized/model/eciapollo.rb +1 -1
- data/lib/oxidized/model/edgeos.rb +3 -3
- data/lib/oxidized/model/enterasys.rb +1 -1
- data/lib/oxidized/model/eos.rb +1 -0
- data/lib/oxidized/model/fastiron.rb +10 -1
- data/lib/oxidized/model/fiberdriver.rb +1 -1
- data/lib/oxidized/model/firelinuxos.rb +1 -1
- data/lib/oxidized/model/fortigate.rb +16 -3
- data/lib/oxidized/model/fortios.rb +1 -1
- data/lib/oxidized/model/ftd.rb +183 -0
- data/lib/oxidized/model/ftos.rb +2 -2
- data/lib/oxidized/model/garderos.rb +16 -5
- data/lib/oxidized/model/grandstreamht8xx.rb +19 -0
- data/lib/oxidized/model/hpebladesystem.rb +1 -1
- data/lib/oxidized/model/ibos.rb +1 -2
- data/lib/oxidized/model/ingate.rb +15 -1
- data/lib/oxidized/model/ios.rb +2 -0
- data/lib/oxidized/model/iosxr.rb +9 -3
- data/lib/oxidized/model/ironware.rb +1 -1
- data/lib/oxidized/model/itmgos.rb +74 -0
- data/lib/oxidized/model/junos.rb +10 -4
- data/lib/oxidized/model/kornfeldos.rb +2 -4
- data/lib/oxidized/model/lancom.rb +2 -2
- data/lib/oxidized/model/linuxgeneric.rb +4 -2
- data/lib/oxidized/model/masteros.rb +1 -1
- data/lib/oxidized/model/mlnxos.rb +1 -1
- data/lib/oxidized/model/model.rb +5 -2
- data/lib/oxidized/model/mtrlrfs.rb +1 -1
- data/lib/oxidized/model/ndms.rb +1 -1
- data/lib/oxidized/model/necix.rb +1 -1
- data/lib/oxidized/model/netgear.rb +1 -1
- data/lib/oxidized/model/netscaler.rb +1 -1
- data/lib/oxidized/model/nxos.rb +13 -1
- data/lib/oxidized/model/ocnos.rb +1 -1
- data/lib/oxidized/model/onefinity.rb +1 -1
- data/lib/oxidized/model/oneos.rb +0 -1
- data/lib/oxidized/model/openbsd.rb +1 -1
- data/lib/oxidized/model/os10.rb +2 -2
- data/lib/oxidized/model/os6.rb +3 -2
- data/lib/oxidized/model/panos.rb +1 -1
- data/lib/oxidized/model/panos_api.rb +42 -14
- data/lib/oxidized/model/procurve.rb +63 -31
- data/lib/oxidized/model/routeros.rb +6 -1
- data/lib/oxidized/model/screenos.rb +2 -2
- data/lib/oxidized/model/sgos.rb +1 -1
- data/lib/oxidized/model/siklu.rb +2 -2
- data/lib/oxidized/model/slxos.rb +1 -1
- data/lib/oxidized/model/sonicos.rb +2 -2
- data/lib/oxidized/model/tdre.rb +2 -2
- data/lib/oxidized/model/telco.rb +1 -1
- data/lib/oxidized/model/tmos.rb +11 -2
- data/lib/oxidized/model/tplink.rb +8 -10
- data/lib/oxidized/model/truenas.rb +56 -5
- data/lib/oxidized/model/viptela.rb +1 -1
- data/lib/oxidized/model/voltaire.rb +1 -1
- data/lib/oxidized/model/vrp.rb +14 -8
- data/lib/oxidized/model/vsololt.rb +93 -0
- data/lib/oxidized/model/vyatta.rb +3 -3
- data/lib/oxidized/model/vyos.rb +6 -1
- data/lib/oxidized/model/xos.rb +1 -1
- data/lib/oxidized/model/zhoneolt.rb +1 -1
- data/lib/oxidized/node.rb +9 -9
- data/lib/oxidized/nodes.rb +5 -13
- data/lib/oxidized/output/git.rb +72 -81
- data/lib/oxidized/output/gitcrypt.rb +13 -32
- data/lib/oxidized/redact.rb +18 -0
- data/lib/oxidized/signals.rb +2 -16
- data/lib/oxidized/source/source.rb +5 -1
- data/lib/oxidized/source/sql.rb +1 -0
- data/lib/oxidized/version.rb +2 -2
- data/lib/oxidized.rb +1 -0
- data/lib/refinements.rb +7 -3
- data/oxidized.gemspec +20 -11
- metadata +74 -29
data/lib/oxidized/input/http.rb
CHANGED
|
@@ -7,10 +7,10 @@ module Oxidized
|
|
|
7
7
|
def connect(node)
|
|
8
8
|
@node = node
|
|
9
9
|
@secure = false
|
|
10
|
+
@port = nil
|
|
10
11
|
@username = nil
|
|
11
12
|
@password = nil
|
|
12
13
|
@headers = {}
|
|
13
|
-
@log = File.open(Oxidized::Config::LOG + "/#{@node.ip}-http", "w") if Oxidized.config.input.debug?
|
|
14
14
|
@node.model.cfg["http"].each { |cb| instance_exec(&cb) }
|
|
15
15
|
|
|
16
16
|
return true unless @main_page && defined?(login)
|
|
@@ -42,8 +42,6 @@ module Oxidized
|
|
|
42
42
|
get_http path
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
-
private
|
|
46
|
-
|
|
47
45
|
def get_http(path)
|
|
48
46
|
res = perform_http_request(path, method: :get)
|
|
49
47
|
res.body
|
|
@@ -54,6 +52,13 @@ module Oxidized
|
|
|
54
52
|
res.body
|
|
55
53
|
end
|
|
56
54
|
|
|
55
|
+
def delete_http(path)
|
|
56
|
+
res = perform_http_request(path, method: :delete)
|
|
57
|
+
res.body
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
private
|
|
61
|
+
|
|
57
62
|
def perform_http_request(path, method: :get, body: nil, extra_headers: {})
|
|
58
63
|
uri = get_uri(path)
|
|
59
64
|
http_method = method.to_s.upcase
|
|
@@ -85,19 +90,23 @@ module Oxidized
|
|
|
85
90
|
|
|
86
91
|
def make_request(uri, ssl_verify, extra_headers = {}, method: :get, body: nil)
|
|
87
92
|
Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https", verify_mode: ssl_verify) do |http|
|
|
88
|
-
req_class =
|
|
93
|
+
req_class = case method
|
|
94
|
+
when :get
|
|
89
95
|
Net::HTTP::Get
|
|
90
|
-
|
|
96
|
+
when :post
|
|
91
97
|
Net::HTTP::Post
|
|
98
|
+
when :delete
|
|
99
|
+
Net::HTTP::Delete
|
|
92
100
|
else
|
|
93
101
|
raise Oxidized::OxidizedError, "Unsupported HTTP method: #{method.inspect}. " \
|
|
94
|
-
"Only :get and :
|
|
102
|
+
"Only :get, :post and :delete are supported"
|
|
95
103
|
end
|
|
96
104
|
req = req_class.new(uri)
|
|
97
|
-
@headers.merge(extra_headers)
|
|
105
|
+
headers = @headers.merge(extra_headers)
|
|
106
|
+
headers.each { |header, value| req.add_field(header, value) }
|
|
98
107
|
req.body = body if body
|
|
99
108
|
|
|
100
|
-
logger.debug "Sending #{method.to_s.upcase} request with headers: #{
|
|
109
|
+
logger.debug "Sending #{method.to_s.upcase} request with headers: #{headers_for_log(headers)}"
|
|
101
110
|
http.request(req)
|
|
102
111
|
end
|
|
103
112
|
end
|
|
@@ -106,22 +115,21 @@ module Oxidized
|
|
|
106
115
|
headers.keys.any? { |key| key.to_s.downcase == 'authorization' }
|
|
107
116
|
end
|
|
108
117
|
|
|
109
|
-
def
|
|
110
|
-
|
|
118
|
+
def headers_for_log(headers)
|
|
119
|
+
headers.map { |key, value| "#{key}: #{Redact.value(key, value)}" }.join(", ")
|
|
111
120
|
end
|
|
112
121
|
|
|
113
|
-
def
|
|
114
|
-
@
|
|
122
|
+
def basic_auth_header
|
|
123
|
+
"Basic " + ["#{@username}:#{@password}"].pack('m').delete("\r\n")
|
|
115
124
|
end
|
|
116
125
|
|
|
117
|
-
def disconnect
|
|
118
|
-
@log.close if Oxidized.config.input.debug?
|
|
119
|
-
end
|
|
126
|
+
def disconnect; end
|
|
120
127
|
|
|
121
128
|
def get_uri(path)
|
|
122
129
|
path = URI.parse(path)
|
|
123
130
|
uri_class = @secure ? URI::HTTPS : URI::HTTP
|
|
124
131
|
uri_class.build(host: @node.ip,
|
|
132
|
+
port: @port,
|
|
125
133
|
path: path.path,
|
|
126
134
|
query: path.query)
|
|
127
135
|
end
|
data/lib/oxidized/input/scp.rb
CHANGED
|
@@ -10,7 +10,9 @@ module Oxidized
|
|
|
10
10
|
|
|
11
11
|
class SCP < SSHBase
|
|
12
12
|
RESCUE_FAIL = {
|
|
13
|
-
Net::SCP::Error => :warn
|
|
13
|
+
Net::SCP::Error => :warn,
|
|
14
|
+
# net-scp raises ArgumentError on error replies missing the \2 prefix, see #3900
|
|
15
|
+
ArgumentError => :warn
|
|
14
16
|
}.freeze
|
|
15
17
|
|
|
16
18
|
def self.rescue_fail
|
data/lib/oxidized/input/ssh.rb
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
require 'timeout'
|
|
2
|
+
require_relative 'sshbase'
|
|
3
|
+
require_relative 'debugyaml'
|
|
4
|
+
require_relative 'debugtext'
|
|
4
5
|
|
|
6
|
+
module Oxidized
|
|
5
7
|
class SSH < SSHBase
|
|
6
8
|
class NoShell < OxidizedError; end
|
|
7
9
|
|
|
@@ -18,11 +20,9 @@ module Oxidized
|
|
|
18
20
|
@output = String.new('')
|
|
19
21
|
@pty_options = { term: "vt100" }
|
|
20
22
|
@node.model.cfg['ssh'].each { |cb| instance_exec(&cb) }
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
logger.debug "I/O Debuging to #{logfile}"
|
|
25
|
-
end
|
|
23
|
+
|
|
24
|
+
@yaml_debug = DebugYAML.new(Oxidized.config.input.debug, @node, config_name)
|
|
25
|
+
@text_debug = DebugText.new(Oxidized.config.input.debug, @node, config_name)
|
|
26
26
|
|
|
27
27
|
logger.debug "Connecting to #{@node.name}"
|
|
28
28
|
@ssh = Net::SSH.start(@node.ip, @node.auth[:username], make_ssh_opts)
|
|
@@ -38,25 +38,30 @@ module Oxidized
|
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
def cmd(cmd, expect = node.prompt)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
@log.flush
|
|
41
|
+
unless cmd.is_a?(String)
|
|
42
|
+
logger.error "cmd must be a String (#{cmd.class}): #{cmd.inspect} @ #{node.name}"
|
|
43
|
+
raise ArgumentError, "cmd must be a String"
|
|
45
44
|
end
|
|
45
|
+
logger.debug "Sending '#{cmd.dump}' @ #{node.name} with expect: #{expect.inspect}"
|
|
46
46
|
cmd_output = if @exec
|
|
47
|
+
@yaml_debug&.send_data(cmd)
|
|
48
|
+
@text_debug&.send_data(cmd)
|
|
47
49
|
@ssh.exec! cmd
|
|
48
50
|
else
|
|
49
51
|
cmd_shell(cmd, expect).gsub("\r\n", "\n")
|
|
50
52
|
end
|
|
53
|
+
|
|
54
|
+
# only logging @exec as cmd_shell is handled in the ssh loop
|
|
55
|
+
@yaml_debug&.receive_data(cmd_output) if @exec
|
|
56
|
+
@text_debug&.receive_data(cmd_output) if @exec
|
|
57
|
+
|
|
51
58
|
# Make sure we return a String
|
|
52
59
|
cmd_output.to_s
|
|
53
60
|
end
|
|
54
61
|
|
|
55
62
|
def send(data)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
@log.flush
|
|
59
|
-
end
|
|
63
|
+
@yaml_debug&.send_data(data)
|
|
64
|
+
@text_debug&.send_data(data)
|
|
60
65
|
@ses.send_data data
|
|
61
66
|
end
|
|
62
67
|
|
|
@@ -79,17 +84,16 @@ module Oxidized
|
|
|
79
84
|
rescue Timeout::Error
|
|
80
85
|
logger.debug "#{@node.name} timed out while disconnecting"
|
|
81
86
|
ensure
|
|
82
|
-
@
|
|
87
|
+
@yaml_debug&.close
|
|
88
|
+
@text_debug&.close
|
|
83
89
|
(@ssh.close rescue true) unless @ssh.closed? # rubocop:disable Style/RedundantParentheses
|
|
84
90
|
end
|
|
85
91
|
|
|
86
92
|
def shell_open(ssh)
|
|
87
93
|
@ses = ssh.open_channel do |ch|
|
|
88
94
|
ch.on_data do |_ch, data|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
@log.flush
|
|
92
|
-
end
|
|
95
|
+
@yaml_debug&.receive_data(data)
|
|
96
|
+
@text_debug&.receive_data(data)
|
|
93
97
|
@output << data
|
|
94
98
|
@output = @node.model.expects @output
|
|
95
99
|
end
|
|
@@ -111,6 +115,9 @@ module Oxidized
|
|
|
111
115
|
|
|
112
116
|
def cmd_shell(cmd, expect_re)
|
|
113
117
|
@output = String.new('')
|
|
118
|
+
|
|
119
|
+
@yaml_debug&.send_data(cmd + newline)
|
|
120
|
+
@text_debug&.send_data(cmd + newline)
|
|
114
121
|
@ses.send_data cmd + newline
|
|
115
122
|
@ses.process
|
|
116
123
|
expect expect_re if expect_re
|
|
@@ -1,16 +1,27 @@
|
|
|
1
1
|
module Oxidized
|
|
2
2
|
require 'net/ssh'
|
|
3
3
|
require 'net/ssh/proxy/command'
|
|
4
|
+
require 'resolv'
|
|
4
5
|
require 'timeout'
|
|
5
6
|
|
|
6
7
|
class SSHBase < Input
|
|
8
|
+
class InvalidVariable < OxidizedError; end
|
|
9
|
+
|
|
7
10
|
RESCUE_FAIL = {
|
|
8
11
|
Net::SSH::Disconnect => :debug,
|
|
9
12
|
Net::SSH::ConnectionTimeout => :debug,
|
|
10
13
|
Net::SSH::AuthenticationFailed => :warn,
|
|
11
|
-
Net::SSH::
|
|
14
|
+
Net::SSH::HostKeyError => :warn,
|
|
15
|
+
Net::SSH::UnsupportedKeyType => :warn,
|
|
16
|
+
InvalidVariable => :warn
|
|
12
17
|
}.freeze
|
|
13
18
|
|
|
19
|
+
PROXY_USER = /\A[A-Za-z0-9._][A-Za-z0-9._-]*\z/
|
|
20
|
+
# RFC 1123
|
|
21
|
+
HOST_LABEL = /[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?/
|
|
22
|
+
# Short hostname or FQDN, without trailing dot
|
|
23
|
+
HOSTNAME = /\A(?=.{1,253}\z)#{HOST_LABEL}(?:\.#{HOST_LABEL})*\z/
|
|
24
|
+
|
|
14
25
|
def self.rescue_fail
|
|
15
26
|
super.merge(RESCUE_FAIL)
|
|
16
27
|
end
|
|
@@ -18,7 +29,6 @@ module Oxidized
|
|
|
18
29
|
def connect(node) # rubocop:disable Naming/PredicateMethod
|
|
19
30
|
@node = node
|
|
20
31
|
@node.model.cfg[config_name].each { |cb| instance_exec(&cb) }
|
|
21
|
-
setup_debug_logging
|
|
22
32
|
logger.debug "Connecting to #{@node.name}"
|
|
23
33
|
@ssh = Net::SSH.start(@node.ip, @node.auth[:username], make_ssh_opts)
|
|
24
34
|
connected?
|
|
@@ -28,14 +38,6 @@ module Oxidized
|
|
|
28
38
|
@ssh && (not @ssh.closed?)
|
|
29
39
|
end
|
|
30
40
|
|
|
31
|
-
def setup_debug_logging
|
|
32
|
-
return unless Oxidized.config.input.debug?
|
|
33
|
-
|
|
34
|
-
logfile = Oxidized::Config::LOG + "/#{@node.ip}-#{config_name}"
|
|
35
|
-
@log = File.open(logfile, 'w')
|
|
36
|
-
logger.debug "I/O Debugging to #{logfile}"
|
|
37
|
-
end
|
|
38
|
-
|
|
39
41
|
def make_ssh_opts
|
|
40
42
|
ssh_opts = {
|
|
41
43
|
number_of_password_prompts: 0,
|
|
@@ -52,20 +54,28 @@ module Oxidized
|
|
|
52
54
|
ssh_opts[:auth_methods] = auth_methods
|
|
53
55
|
logger.debug "AUTH METHODS::#{auth_methods}"
|
|
54
56
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
proxy = make_ssh_proxy_command(vars(:ssh_proxy), vars(:ssh_proxy_port), must_secure?)
|
|
58
|
+
# net-ssh 8 raises ArgumentError on nil option values
|
|
59
|
+
ssh_opts[:proxy] = proxy if proxy
|
|
60
|
+
ssh_opts[:keys] = [vars(:ssh_keys)].flatten if vars(:ssh_keys)
|
|
61
|
+
ssh_opts[:kex] = vars(:ssh_kex).split(/,\s*/) if vars(:ssh_kex)
|
|
62
|
+
ssh_opts[:encryption] = vars(:ssh_encryption).split(/,\s*/) if vars(:ssh_encryption)
|
|
63
|
+
ssh_opts[:host_key] = vars(:ssh_host_key).split(/,\s*/) if vars(:ssh_host_key)
|
|
64
|
+
ssh_opts[:hmac] = vars(:ssh_hmac).split(/,\s*/) if vars(:ssh_hmac)
|
|
65
|
+
ssh_opts[:pubkey_algorithms] = vars(:ssh_pubkey_algorithms).split(/,\s*/) if vars(:ssh_pubkey_algorithms)
|
|
66
|
+
if vars(:ssh_minimum_dh_bits)
|
|
67
|
+
ssh_opts[:minimum_dh_bits] = integer_var(:ssh_minimum_dh_bits, vars(:ssh_minimum_dh_bits))
|
|
59
68
|
end
|
|
60
|
-
ssh_opts[:keys] = [vars(:ssh_keys)].flatten if vars(:ssh_keys)
|
|
61
|
-
ssh_opts[:kex] = vars(:ssh_kex).split(/,\s*/) if vars(:ssh_kex)
|
|
62
|
-
ssh_opts[:encryption] = vars(:ssh_encryption).split(/,\s*/) if vars(:ssh_encryption)
|
|
63
|
-
ssh_opts[:host_key] = vars(:ssh_host_key).split(/,\s*/) if vars(:ssh_host_key)
|
|
64
|
-
ssh_opts[:hmac] = vars(:ssh_hmac).split(/,\s*/) if vars(:ssh_hmac)
|
|
65
69
|
|
|
66
70
|
# Use our logger for Net::SSH
|
|
67
71
|
ssh_logger = SemanticLogger[Net::SSH]
|
|
68
|
-
|
|
72
|
+
config_debug = Oxidized.config.input.debug
|
|
73
|
+
if config_debug == true ||
|
|
74
|
+
(config_debug.is_a?(String) && config_debug.downcase.include?('library'))
|
|
75
|
+
ssh_logger.level = :debug
|
|
76
|
+
else
|
|
77
|
+
ssh_logger.level = :fatal
|
|
78
|
+
end
|
|
69
79
|
ssh_opts[:logger] = ssh_logger
|
|
70
80
|
|
|
71
81
|
ssh_opts
|
|
@@ -77,14 +87,32 @@ module Oxidized
|
|
|
77
87
|
|
|
78
88
|
def make_ssh_proxy_command(proxy_host, proxy_port, secure)
|
|
79
89
|
return nil unless !proxy_host.nil? && !proxy_host.empty?
|
|
90
|
+
raise InvalidVariable, "invalid ssh_proxy: #{proxy_host.inspect}" unless valid_proxy_host?(proxy_host)
|
|
80
91
|
|
|
81
92
|
proxy_command = "ssh "
|
|
82
93
|
proxy_command += "-o StrictHostKeyChecking=no " unless secure
|
|
83
|
-
proxy_command += "-p #{proxy_port} "
|
|
84
|
-
|
|
94
|
+
proxy_command += "-p #{integer_var(:ssh_proxy_port, proxy_port)} " if proxy_port
|
|
95
|
+
# net-ssh substitutes %h, %p... in the command, % may be in an IPv6 zone ID
|
|
96
|
+
proxy_command += "#{proxy_host.gsub('%', '%%')} -W [%h]:%p"
|
|
85
97
|
Net::SSH::Proxy::Command.new(proxy_command)
|
|
86
98
|
end
|
|
87
99
|
|
|
100
|
+
# [user@]host, where host is a hostname, an IPv4 or an IPv6 address
|
|
101
|
+
def valid_proxy_host?(proxy_host)
|
|
102
|
+
user, separator, host = proxy_host.rpartition('@')
|
|
103
|
+
return false unless separator.empty? || user.match?(PROXY_USER)
|
|
104
|
+
|
|
105
|
+
host.match?(HOSTNAME) ||
|
|
106
|
+
host.match?(Resolv::IPv4::Regex) ||
|
|
107
|
+
host.match?(Resolv::IPv6::Regex)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def integer_var(name, value)
|
|
111
|
+
Integer(value.to_s, 10)
|
|
112
|
+
rescue ArgumentError
|
|
113
|
+
raise InvalidVariable, "invalid #{name}: #{value.inspect}"
|
|
114
|
+
end
|
|
115
|
+
|
|
88
116
|
def disconnect
|
|
89
117
|
disconnect_cli
|
|
90
118
|
Timeout.timeout(@node.timeout) do
|
|
@@ -95,8 +123,6 @@ module Oxidized
|
|
|
95
123
|
"disconnecting, raising #{e.class} with #{e.message}"
|
|
96
124
|
rescue Timeout::Error
|
|
97
125
|
logger.debug "#{@node.name} timed out while disconnecting"
|
|
98
|
-
ensure
|
|
99
|
-
@log.close if Oxidized.config.input.debug?
|
|
100
126
|
end
|
|
101
127
|
|
|
102
128
|
# Methods to implement in subclasses
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
require_relative 'debugtext'
|
|
2
|
+
|
|
1
3
|
module Oxidized
|
|
2
4
|
require 'net/telnet'
|
|
3
5
|
class Telnet < Input
|
|
@@ -7,7 +9,9 @@ module Oxidized
|
|
|
7
9
|
@node = node
|
|
8
10
|
@timeout = @node.timeout
|
|
9
11
|
@node.model.cfg['telnet'].each { |cb| instance_exec(&cb) }
|
|
10
|
-
|
|
12
|
+
|
|
13
|
+
@text_debug = DebugText.new(Oxidized.config.input.debug, @node, config_name)
|
|
14
|
+
|
|
11
15
|
port = vars(:telnet_port) || 23
|
|
12
16
|
|
|
13
17
|
telnet_opts = {
|
|
@@ -15,7 +19,7 @@ module Oxidized
|
|
|
15
19
|
'Port' => port.to_i,
|
|
16
20
|
'Timeout' => @timeout,
|
|
17
21
|
'Model' => @node.model,
|
|
18
|
-
'Log' => @
|
|
22
|
+
'Log' => @text_debug
|
|
19
23
|
}
|
|
20
24
|
|
|
21
25
|
@telnet = Net::Telnet.new telnet_opts
|
|
@@ -38,12 +42,14 @@ module Oxidized
|
|
|
38
42
|
# create a string to be passed to oxidized_expect and modified _there_
|
|
39
43
|
# default to a single space so it shouldn't be coerced to nil by any models.
|
|
40
44
|
out = String(' ')
|
|
45
|
+
@text_debug&.send_data(cmd_str)
|
|
41
46
|
@telnet.puts(cmd_str)
|
|
42
47
|
@telnet.oxidized_expect(timeout: @timeout, expect: expect, out: out)
|
|
43
48
|
out
|
|
44
49
|
end
|
|
45
50
|
|
|
46
51
|
def send(data)
|
|
52
|
+
@text_debug&.send_data(data)
|
|
47
53
|
@telnet.write data
|
|
48
54
|
end
|
|
49
55
|
|
|
@@ -63,7 +69,7 @@ module Oxidized
|
|
|
63
69
|
rescue Errno::ECONNRESET, IOError
|
|
64
70
|
# This exception is intented and therefore not handled here
|
|
65
71
|
ensure
|
|
66
|
-
@
|
|
72
|
+
@text_debug&.close
|
|
67
73
|
(@telnet.close rescue true) unless @telnet.sock.closed? # rubocop:disable Style/RedundantParentheses
|
|
68
74
|
end
|
|
69
75
|
end
|
|
@@ -76,8 +82,8 @@ module Net
|
|
|
76
82
|
attr_reader :output
|
|
77
83
|
|
|
78
84
|
def oxidized_expect(options)
|
|
79
|
-
model
|
|
80
|
-
|
|
85
|
+
model = @options["Model"]
|
|
86
|
+
text_debug = @options["Log"]
|
|
81
87
|
|
|
82
88
|
expects = [options[:expect]].flatten
|
|
83
89
|
time_out = options[:timeout] || @options["Timeout"]
|
|
@@ -94,19 +100,16 @@ module Net
|
|
|
94
100
|
if Integer(c.rindex(/#{IAC}#{SE}/no) || 0) <
|
|
95
101
|
Integer(c.rindex(/#{IAC}#{SB}/no) || 0)
|
|
96
102
|
buf = preprocess(c[0...c.rindex(/#{IAC}#{SB}/no)])
|
|
97
|
-
rest = c[c.rindex(/#{IAC}#{SB}/no)
|
|
103
|
+
rest = c[c.rindex(/#{IAC}#{SB}/no)..]
|
|
98
104
|
elsif (pt = c.rindex(/#{IAC}[^#{IAC}#{AO}#{AYT}#{DM}#{IP}#{NOP}]?\z/no) ||
|
|
99
105
|
c.rindex(/\r\z/no))
|
|
100
106
|
buf = preprocess(c[0...pt])
|
|
101
|
-
rest = c[pt
|
|
107
|
+
rest = c[pt..]
|
|
102
108
|
else
|
|
103
109
|
buf = preprocess(c)
|
|
104
110
|
rest = ''
|
|
105
111
|
end
|
|
106
|
-
|
|
107
|
-
@log.print buf
|
|
108
|
-
@log.flush
|
|
109
|
-
end
|
|
112
|
+
text_debug&.receive_data buf
|
|
110
113
|
line += buf
|
|
111
114
|
line = model.expects line
|
|
112
115
|
# match is a regexp object. we need to return that for logins to work.
|
data/lib/oxidized/input/tftp.rb
CHANGED
|
@@ -20,7 +20,6 @@ module Oxidized
|
|
|
20
20
|
@node = node
|
|
21
21
|
|
|
22
22
|
@node.model.cfg['tftp'].each { |cb| instance_exec(&cb) }
|
|
23
|
-
@log = File.open(Oxidized::Config::LOG + "/#{@node.ip}-tftp", 'w') if Oxidized.config.input.debug?
|
|
24
23
|
@tftp = Net::TFTP.new @node.ip
|
|
25
24
|
end
|
|
26
25
|
|
|
@@ -36,9 +35,6 @@ module Oxidized
|
|
|
36
35
|
|
|
37
36
|
def disconnect
|
|
38
37
|
# TFTP uses UDP, there is no connection to close
|
|
39
|
-
true
|
|
40
|
-
ensure
|
|
41
|
-
@log.close if Oxidized.config.input.debug?
|
|
42
38
|
end
|
|
43
39
|
end
|
|
44
40
|
end
|
data/lib/oxidized/model/acos.rb
CHANGED
data/lib/oxidized/model/acsw.rb
CHANGED
|
@@ -35,7 +35,7 @@ class ACSW < Oxidized::Model
|
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
cmd 'show running-config' do |cfg|
|
|
38
|
-
cfg = cfg.each_line.to_a[3
|
|
38
|
+
cfg = cfg.each_line.to_a[3..]
|
|
39
39
|
cfg = cfg.reject { |line| line.match /^ntp clock-period / }.join
|
|
40
40
|
cfg.gsub! /^Current configuration : [^\n]*\n/, ''
|
|
41
41
|
cfg.gsub! /^ tunnel mpls traffic-eng bandwidth[^\n]*\n*(
|
|
@@ -5,7 +5,7 @@ class Aireos < Oxidized::Model
|
|
|
5
5
|
# Used in Cisco WLC 5500
|
|
6
6
|
|
|
7
7
|
comment '# ' # this complains too, can't find real comment char
|
|
8
|
-
prompt /^\([^)]+\)\s
|
|
8
|
+
prompt /^\([^)]+\)\s*[>#]/
|
|
9
9
|
|
|
10
10
|
cmd :all do |cfg|
|
|
11
11
|
cfg.cut_both
|
|
@@ -29,7 +29,7 @@ class Aireos < Oxidized::Model
|
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
cfg :telnet, :ssh do
|
|
32
|
-
username /^User:\s*/
|
|
32
|
+
username /^(User|Username):\s*/
|
|
33
33
|
password /^Password:\s*/
|
|
34
34
|
post_login 'config paging disable'
|
|
35
35
|
end
|
|
@@ -47,7 +47,7 @@ class Aireos < Oxidized::Model
|
|
|
47
47
|
next if line =~ /^\s*$/
|
|
48
48
|
next if line =~ /rogue (adhoc|client) (alert|Unknown) [\da-f]{2}:/
|
|
49
49
|
|
|
50
|
-
line = line[1
|
|
50
|
+
line = line[1..] if line[0] == "\r"
|
|
51
51
|
out << line.strip
|
|
52
52
|
end
|
|
53
53
|
out = out.join "\n"
|
data/lib/oxidized/model/aoscx.rb
CHANGED
|
@@ -24,7 +24,7 @@ class Aoscx < Oxidized::Model
|
|
|
24
24
|
cmd :secret do |cfg|
|
|
25
25
|
cfg.gsub! /^(user .* group .*(?: ciphertext)?) \S+/, '\\1 <secret hidden>'
|
|
26
26
|
cfg.gsub! /^(snmp-server community) \S+(.*)/, '\\1 <secret hidden> \\2'
|
|
27
|
-
cfg.gsub! /^(snmp-server host \S+) \S+(.*)/, '\\1 <secret hidden
|
|
27
|
+
cfg.gsub! /^(snmp-server host \S+ .*community) \S+(.*)/, '\\1 <secret hidden>\\2'
|
|
28
28
|
cfg.gsub! /^(snmpv3 user).*?(auth (?:md5|sha(?:\d{1,3})?) auth-pass ciphertext).*?(priv (?:des|aes(?:\d{1,3})?) priv-pass ciphertext).*/, '\\1 <user> \\2 <auth-pass> \\3 <priv-pass>'
|
|
29
29
|
cfg.gsub! /^(radius-server host \S+ key(?: ciphertext)?) \S+ (.*)/, '\\1 <secret hidden> \\2'
|
|
30
30
|
cfg.gsub! /^(radius-server key).*/, '\\1 <configuration removed>'
|
|
@@ -37,26 +37,31 @@ class Aoscx < Oxidized::Model
|
|
|
37
37
|
comment cfg
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
header + content
|
|
47
|
-
end
|
|
40
|
+
def with_section(cfg, section, &block)
|
|
41
|
+
cfg.sub!(/(show environment #{section}.*?-{10,}\n)(.*?)(?=\nshow environment|\z)/m) do
|
|
42
|
+
header = ::Regexp.last_match(1)
|
|
43
|
+
content = ::Regexp.last_match(2)
|
|
44
|
+
block.call(content) if block_given?
|
|
45
|
+
header + content
|
|
48
46
|
end
|
|
47
|
+
end
|
|
49
48
|
|
|
49
|
+
cmd 'show environment' do |cfg|
|
|
50
50
|
with_section(cfg, 'fan') do |content|
|
|
51
51
|
content.gsub!(/^((?:\S+ +){3})(slow |normal|medium|fast |max |N\/A ) (.*?)\d+ +$/, '\\1<speed> \\3<rpm>')
|
|
52
52
|
end
|
|
53
53
|
|
|
54
54
|
with_section(cfg, 'power-consumption') do |content|
|
|
55
|
-
content.gsub!(/^(.*?) (?:\d+\.\d+ +)+\d+\.\d
|
|
55
|
+
content.gsub!(/^(.*?) (?:\d+\.\d+ +)+\d+\.\d+(?: +N\/A)*$/, '\\1 <power hidden>')
|
|
56
|
+
content.gsub!(/^(Total Power Consumption +)\d+\.\d+$/, '\\1<power hidden>')
|
|
56
57
|
end
|
|
57
58
|
|
|
58
59
|
with_section(cfg, 'power-allocation') do |content|
|
|
59
|
-
content.gsub!(/^(.*) \d+ W$/, '\\1 <power>')
|
|
60
|
+
content.gsub!(/^(.*) \d+(?:\.\d+)? W$/, '\\1 <power>')
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
with_section(cfg, 'power-supply input-voltage') do |content|
|
|
64
|
+
content.gsub!(/^((?:\S+ +){3}\d+-\d+ +)\d+\.\d+ +\d+\.\d+/, '\\1<voltage hidden>')
|
|
60
65
|
end
|
|
61
66
|
|
|
62
67
|
with_section(cfg, 'temperature') do |content|
|
|
@@ -73,7 +78,10 @@ class Aoscx < Oxidized::Model
|
|
|
73
78
|
comment cfg
|
|
74
79
|
end
|
|
75
80
|
|
|
76
|
-
cmd 'show system
|
|
81
|
+
cmd 'show system' do |cfg|
|
|
82
|
+
cfg = cfg.reject_lines [
|
|
83
|
+
"Up Time", "CPU", "Memory", /Pkts .x/, "Lowest", "Missed"
|
|
84
|
+
]
|
|
77
85
|
comment cfg
|
|
78
86
|
end
|
|
79
87
|
|
data/lib/oxidized/model/aosw.rb
CHANGED
|
@@ -52,31 +52,31 @@ class AOSW < Oxidized::Model
|
|
|
52
52
|
/(Switch|AP) uptime/i,
|
|
53
53
|
/Reboot Time and Cause/i
|
|
54
54
|
]
|
|
55
|
-
|
|
55
|
+
clean_comment cfg
|
|
56
56
|
end
|
|
57
57
|
|
|
58
58
|
cmd 'show inventory' do |cfg|
|
|
59
59
|
# Don't show for unsupported devices (IAP and MAS)
|
|
60
60
|
cfg = "" if cfg =~ /(Invalid input detected at '\^' marker|Parse error)/
|
|
61
|
-
|
|
61
|
+
clean(cfg).rstrip_lines
|
|
62
62
|
end
|
|
63
63
|
|
|
64
64
|
cmd 'show slots' do |cfg|
|
|
65
65
|
# Don't show for unsupported devices (IAP and MAS)
|
|
66
66
|
cfg = "" if cfg =~ /(Invalid input detected at '\^' marker|Parse error)/
|
|
67
|
-
|
|
67
|
+
clean_comment cfg
|
|
68
68
|
end
|
|
69
69
|
|
|
70
70
|
cmd 'show license' do |cfg|
|
|
71
71
|
# Don't show for unsupported devices (IAP and MAS)
|
|
72
72
|
cfg = "" if cfg =~ /(Invalid input detected at '\^' marker|Parse error)/
|
|
73
|
-
|
|
73
|
+
clean_comment cfg
|
|
74
74
|
end
|
|
75
75
|
|
|
76
76
|
cmd 'show license passphrase' do |cfg|
|
|
77
77
|
# Don't show for unsupported devices (IAP and MAS)
|
|
78
78
|
cfg = "" if cfg.match /(Invalid input detected at '\^' marker|Parse error)/
|
|
79
|
-
|
|
79
|
+
clean_comment cfg
|
|
80
80
|
end
|
|
81
81
|
|
|
82
82
|
cmd 'show running-config' do |cfg|
|
|
@@ -84,7 +84,7 @@ class AOSW < Oxidized::Model
|
|
|
84
84
|
/^controller config \d+$/,
|
|
85
85
|
/^Building Configuration/
|
|
86
86
|
]
|
|
87
|
-
|
|
87
|
+
cfg.rstrip_lines
|
|
88
88
|
end
|
|
89
89
|
|
|
90
90
|
cfg :telnet do
|
|
@@ -105,13 +105,8 @@ class AOSW < Oxidized::Model
|
|
|
105
105
|
pre_logout 'exit'
|
|
106
106
|
end
|
|
107
107
|
|
|
108
|
-
def
|
|
109
|
-
|
|
110
|
-
cfg.each_line do |line|
|
|
111
|
-
out << line.rstrip
|
|
112
|
-
end
|
|
113
|
-
out = out.join "\n"
|
|
114
|
-
out << "\n"
|
|
108
|
+
def clean_comment(lines)
|
|
109
|
+
comment(lines).rstrip_lines
|
|
115
110
|
end
|
|
116
111
|
|
|
117
112
|
def clean(cfg)
|
data/lib/oxidized/model/arbos.rb
CHANGED
|
@@ -9,7 +9,7 @@ class ARBOS < Oxidized::Model
|
|
|
9
9
|
cmd 'system hardware' do |cfg|
|
|
10
10
|
cfg.gsub! /^Boot time:\s.+/, '' # Remove boot timer
|
|
11
11
|
cfg.gsub! /^Load averages:\s.+/, '' # Remove CPU load info
|
|
12
|
-
cfg = cfg.
|
|
12
|
+
cfg = cfg.cut_head(2)
|
|
13
13
|
comment cfg
|
|
14
14
|
end
|
|
15
15
|
|
|
@@ -27,7 +27,7 @@ class AricentISS < Oxidized::Model
|
|
|
27
27
|
# * Drop first line that contains the command, and the last line that
|
|
28
28
|
# contains a prompt
|
|
29
29
|
# * Strip carriage returns
|
|
30
|
-
cfg.delete("\r").
|
|
30
|
+
cfg.delete("\r").cut_both
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
cmd :secret do |cfg|
|
data/lib/oxidized/model/asa.rb
CHANGED
|
@@ -67,7 +67,7 @@ class ASA < Oxidized::Model
|
|
|
67
67
|
def single_context
|
|
68
68
|
# Single context mode
|
|
69
69
|
cmd 'more system:running-config' do |cfg|
|
|
70
|
-
cfg = cfg.
|
|
70
|
+
cfg = cfg.cut_head(3)
|
|
71
71
|
cfg.gsub! /^: [^\n]*\n/, ''
|
|
72
72
|
# backup any xml referenced in the configuration.
|
|
73
73
|
anyconnect_profiles = cfg.scan(Regexp.new('(\sdisk0:/.+\.xml)')).flatten
|
|
@@ -11,7 +11,7 @@ class AudioCodesMP < Oxidized::Model
|
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
cmd 'cf get' do |cfg|
|
|
14
|
-
lines = cfg.each_line.to_a
|
|
14
|
+
lines = cfg.each_line.to_a
|
|
15
15
|
# remove any garbage before ';**************' and after '; End of INI file.'
|
|
16
16
|
lines[lines.index(";**************\r\n")..lines.index("; End of INI file.\n")].join
|
|
17
17
|
end
|