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.
Files changed (159) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE/bug_report.md +30 -4
  3. data/.github/ISSUE_TEMPLATE/feature_request.md +10 -3
  4. data/.github/ISSUE_TEMPLATE/support-request.md +30 -4
  5. data/.github/PULL_REQUEST_TEMPLATE.md +3 -1
  6. data/.github/workflows/codeql.yml +4 -4
  7. data/.github/workflows/publishdocker.yml +2 -2
  8. data/.github/workflows/ruby.yml +10 -3
  9. data/.github/workflows/stale.yml +1 -1
  10. data/.rubocop.yml +3 -0
  11. data/.rubocop_todo.yml +2 -8
  12. data/AGENTS.md +174 -0
  13. data/CHANGELOG.md +127 -0
  14. data/CONTRIBUTING.md +78 -44
  15. data/Dockerfile +8 -4
  16. data/README.md +8 -1
  17. data/Rakefile +1 -1
  18. data/docs/Configuration.md +10 -1
  19. data/docs/Creating-Models.md +6 -6
  20. data/docs/DeviceSimulation.md +80 -51
  21. data/docs/Docker.md +49 -0
  22. data/docs/Hooks.md +92 -67
  23. data/docs/Inputs.md +95 -16
  24. data/docs/Issues.md +49 -13
  25. data/docs/Model-Notes/FTD.md +64 -0
  26. data/docs/Model-Notes/GrandstreamHT8xx.md +8 -0
  27. data/docs/Model-Notes/HPEAruba.md +5 -0
  28. data/docs/Model-Notes/ITMGOS.md +40 -0
  29. data/docs/Model-Notes/PanOS_API.md +20 -1
  30. data/docs/Model-Notes/RouterOS.md +13 -0
  31. data/docs/Model-Notes/TPLink.md +75 -0
  32. data/docs/Model-Notes/TrueNAS.md +11 -7
  33. data/docs/Outputs.md +1 -0
  34. data/docs/Release.md +49 -22
  35. data/docs/Ruby-API.md +231 -9
  36. data/docs/Supported-OS-Types.md +10 -4
  37. data/docs/Troubleshooting.md +8 -9
  38. data/extra/device2yaml.rb +21 -5
  39. data/extra/hooks/modelrulesadvanced.rb +2 -4
  40. data/extra/oxidized.service +0 -1
  41. data/extra/syslog.rb +1 -1
  42. data/lib/oxidized/cli/support.rb +149 -0
  43. data/lib/oxidized/cli.rb +9 -0
  44. data/lib/oxidized/config/vars.rb +2 -1
  45. data/lib/oxidized/core.rb +20 -0
  46. data/lib/oxidized/hook/ciscosparkdiff.rb +1 -1
  47. data/lib/oxidized/hook/slackdiff.rb +1 -1
  48. data/lib/oxidized/hook/xmppdiff.rb +2 -2
  49. data/lib/oxidized/hook.rb +2 -0
  50. data/lib/oxidized/input/cli.rb +14 -2
  51. data/lib/oxidized/input/debugtext.rb +40 -0
  52. data/lib/oxidized/input/debugyaml.rb +82 -0
  53. data/lib/oxidized/input/exec.rb +1 -6
  54. data/lib/oxidized/input/ftp.rb +0 -4
  55. data/lib/oxidized/input/http.rb +23 -15
  56. data/lib/oxidized/input/scp.rb +3 -1
  57. data/lib/oxidized/input/ssh.rb +28 -21
  58. data/lib/oxidized/input/sshbase.rb +50 -24
  59. data/lib/oxidized/input/telnet.rb +14 -11
  60. data/lib/oxidized/input/tftp.rb +0 -4
  61. data/lib/oxidized/model/acos.rb +2 -2
  62. data/lib/oxidized/model/acsw.rb +1 -1
  63. data/lib/oxidized/model/adtran.rb +1 -1
  64. data/lib/oxidized/model/aireos.rb +3 -3
  65. data/lib/oxidized/model/aoscx.rb +20 -12
  66. data/lib/oxidized/model/aosw.rb +8 -13
  67. data/lib/oxidized/model/arbos.rb +1 -1
  68. data/lib/oxidized/model/aricentiss.rb +1 -1
  69. data/lib/oxidized/model/asa.rb +1 -1
  70. data/lib/oxidized/model/asternos.rb +1 -1
  71. data/lib/oxidized/model/audiocodesmp.rb +1 -1
  72. data/lib/oxidized/model/awplus.rb +4 -3
  73. data/lib/oxidized/model/bdcom.rb +1 -1
  74. data/lib/oxidized/model/br6910.rb +1 -1
  75. data/lib/oxidized/model/c4cmts.rb +1 -1
  76. data/lib/oxidized/model/ciscosmb.rb +0 -1
  77. data/lib/oxidized/model/cnos.rb +10 -1
  78. data/lib/oxidized/model/comnetms.rb +1 -1
  79. data/lib/oxidized/model/coriantgroove.rb +1 -1
  80. data/lib/oxidized/model/cumulus.rb +3 -3
  81. data/lib/oxidized/model/dellx.rb +1 -1
  82. data/lib/oxidized/model/dlink.rb +1 -1
  83. data/lib/oxidized/model/dlinknextgen.rb +2 -1
  84. data/lib/oxidized/model/dnos.rb +2 -2
  85. data/lib/oxidized/model/eatonnetwork.rb +33 -32
  86. data/lib/oxidized/model/eciapollo.rb +1 -1
  87. data/lib/oxidized/model/edgeos.rb +3 -3
  88. data/lib/oxidized/model/enterasys.rb +1 -1
  89. data/lib/oxidized/model/eos.rb +1 -0
  90. data/lib/oxidized/model/fastiron.rb +10 -1
  91. data/lib/oxidized/model/fiberdriver.rb +1 -1
  92. data/lib/oxidized/model/firelinuxos.rb +1 -1
  93. data/lib/oxidized/model/fortigate.rb +16 -3
  94. data/lib/oxidized/model/fortios.rb +1 -1
  95. data/lib/oxidized/model/ftd.rb +183 -0
  96. data/lib/oxidized/model/ftos.rb +2 -2
  97. data/lib/oxidized/model/garderos.rb +16 -5
  98. data/lib/oxidized/model/grandstreamht8xx.rb +19 -0
  99. data/lib/oxidized/model/hpebladesystem.rb +1 -1
  100. data/lib/oxidized/model/ibos.rb +1 -2
  101. data/lib/oxidized/model/ingate.rb +15 -1
  102. data/lib/oxidized/model/ios.rb +2 -0
  103. data/lib/oxidized/model/iosxr.rb +9 -3
  104. data/lib/oxidized/model/ironware.rb +1 -1
  105. data/lib/oxidized/model/itmgos.rb +74 -0
  106. data/lib/oxidized/model/junos.rb +10 -4
  107. data/lib/oxidized/model/kornfeldos.rb +2 -4
  108. data/lib/oxidized/model/lancom.rb +2 -2
  109. data/lib/oxidized/model/linuxgeneric.rb +4 -2
  110. data/lib/oxidized/model/masteros.rb +1 -1
  111. data/lib/oxidized/model/mlnxos.rb +1 -1
  112. data/lib/oxidized/model/model.rb +5 -2
  113. data/lib/oxidized/model/mtrlrfs.rb +1 -1
  114. data/lib/oxidized/model/ndms.rb +1 -1
  115. data/lib/oxidized/model/necix.rb +1 -1
  116. data/lib/oxidized/model/netgear.rb +1 -1
  117. data/lib/oxidized/model/netscaler.rb +1 -1
  118. data/lib/oxidized/model/nxos.rb +13 -1
  119. data/lib/oxidized/model/ocnos.rb +1 -1
  120. data/lib/oxidized/model/onefinity.rb +1 -1
  121. data/lib/oxidized/model/oneos.rb +0 -1
  122. data/lib/oxidized/model/openbsd.rb +1 -1
  123. data/lib/oxidized/model/os10.rb +2 -2
  124. data/lib/oxidized/model/os6.rb +3 -2
  125. data/lib/oxidized/model/panos.rb +1 -1
  126. data/lib/oxidized/model/panos_api.rb +42 -14
  127. data/lib/oxidized/model/procurve.rb +63 -31
  128. data/lib/oxidized/model/routeros.rb +6 -1
  129. data/lib/oxidized/model/screenos.rb +2 -2
  130. data/lib/oxidized/model/sgos.rb +1 -1
  131. data/lib/oxidized/model/siklu.rb +2 -2
  132. data/lib/oxidized/model/slxos.rb +1 -1
  133. data/lib/oxidized/model/sonicos.rb +2 -2
  134. data/lib/oxidized/model/tdre.rb +2 -2
  135. data/lib/oxidized/model/telco.rb +1 -1
  136. data/lib/oxidized/model/tmos.rb +11 -2
  137. data/lib/oxidized/model/tplink.rb +8 -10
  138. data/lib/oxidized/model/truenas.rb +56 -5
  139. data/lib/oxidized/model/viptela.rb +1 -1
  140. data/lib/oxidized/model/voltaire.rb +1 -1
  141. data/lib/oxidized/model/vrp.rb +14 -8
  142. data/lib/oxidized/model/vsololt.rb +93 -0
  143. data/lib/oxidized/model/vyatta.rb +3 -3
  144. data/lib/oxidized/model/vyos.rb +6 -1
  145. data/lib/oxidized/model/xos.rb +1 -1
  146. data/lib/oxidized/model/zhoneolt.rb +1 -1
  147. data/lib/oxidized/node.rb +9 -9
  148. data/lib/oxidized/nodes.rb +5 -13
  149. data/lib/oxidized/output/git.rb +72 -81
  150. data/lib/oxidized/output/gitcrypt.rb +13 -32
  151. data/lib/oxidized/redact.rb +18 -0
  152. data/lib/oxidized/signals.rb +2 -16
  153. data/lib/oxidized/source/source.rb +5 -1
  154. data/lib/oxidized/source/sql.rb +1 -0
  155. data/lib/oxidized/version.rb +2 -2
  156. data/lib/oxidized.rb +1 -0
  157. data/lib/refinements.rb +7 -3
  158. data/oxidized.gemspec +20 -11
  159. metadata +74 -29
@@ -97,12 +97,11 @@ In some situations, you may need to make changes to the git repository of
97
97
  oxidized. Stop oxidized, make backups, and be sure you know exactly what you
98
98
  are doing. You have been warned.
99
99
 
100
- If you simply clone the git repository, make changes and push them, oxidized
101
- will ignore these modifications. This is because oxidized caches the HEAD tree
102
- in the index and `git push` does not update the index because the repository is
103
- a bare repo and not a working directory repository.
104
-
105
- So, you have to update the index manually. For this, go into oxidized repo, and
106
- run `git ls-tree -r HEAD | git update-index --index-info`. While you're at it,
107
- consider running `git gc`, as oxidized cannot garbage collect the repo (this
108
- is not supported in [Rugged](https://github.com/libgit2/rugged)).
100
+ Oxidized 0.37.0 and older cached the HEAD tree in the git index and
101
+ ignored changes pushed to the repository. If you use such a version, update
102
+ the index manually after pushing: go into the oxidized repo and run
103
+ `git ls-tree -r HEAD | git update-index --index-info`.
104
+
105
+ Consider running `git gc` from time to time, as oxidized cannot garbage
106
+ collect the repo (this is not supported in
107
+ [Rugged](https://github.com/libgit2/rugged)).
data/extra/device2yaml.rb CHANGED
@@ -129,7 +129,7 @@ optparse = OptionParser.new do |opts|
129
129
  command2
130
130
  command3" [options]
131
131
 
132
- -i and -c are mutualy exclusive, one must be specified
132
+ -i and -c are mutually exclusive, one must be specified
133
133
 
134
134
  [options]:
135
135
  HEREDOC
@@ -143,10 +143,19 @@ optparse = OptionParser.new do |opts|
143
143
  opts.on('-o', '--output file', 'Specify an output YAML-file') do |file|
144
144
  options[:output] = file
145
145
  end
146
+ opts.on('-p', '--port port', Integer, 'Specify SSH port (default: 22)') do |port|
147
+ options[:port] = port
148
+ end
146
149
  opts.on('-t', '--timeout value', Integer,
147
- 'Specify the idle timeout beween commands (default: 5 seconds)') do |timeout|
150
+ 'Specify the idle timeout between commands (default: 5 seconds)') do |timeout|
148
151
  options[:timeout] = timeout
149
152
  end
153
+ opts.on('-n', '--newline value',
154
+ 'Line terminator appended to each command (default: \n). ' \
155
+ 'Accepts the escapes \n and \r, e.g. -n "\r\n" for ' \
156
+ 'devices that submit a command only on a carriage return.') do |newline|
157
+ options[:newline] = newline.gsub('\n', "\n").gsub('\r', "\r")
158
+ end
150
159
  opts.on('-e', '--exec-mode', 'Run ssh in exec mode (without tty)') { @exec_mode = true }
151
160
  opts.on('-u', '--unordered', 'The YAML simulation should not enforce an order of the commands') do
152
161
  @sequence_prepend_command = ''
@@ -194,8 +203,10 @@ elsif options[:input]
194
203
  end
195
204
 
196
205
  puts "Running #{ssh_commands} on #{ssh_user}@#{ssh_host}"
197
- # Add \n to each command
198
- ssh_commands.map! { |s| s + "\n" }
206
+ # Append the line terminator to each command (default "\n", overridable with -n
207
+ # for devices that submit a command only on a carriage return)
208
+ command_newline = options[:newline] || "\n"
209
+ ssh_commands.map! { |s| s + command_newline }
199
210
 
200
211
  # Defaut idle timeout: 5 seconds, as tests showed that 2 seconds is too short
201
212
  @idle_timeout = options[:timeout] || 5
@@ -206,7 +217,8 @@ ssh_commands.map! { |s| s + "\n" }
206
217
 
207
218
  @ssh = Net::SSH.start(ssh_host,
208
219
  ssh_user,
209
- { timeout: 10,
220
+ { port: options[:port] || 22,
221
+ timeout: 10,
210
222
  append_all_supported_algorithms: true })
211
223
 
212
224
  @ssh_output = ''
@@ -235,6 +247,10 @@ end
235
247
 
236
248
  # YAML begin of file
237
249
  @output&.puts '---'
250
+ # Record the line terminator appended to each command, so it is clear how the
251
+ # simulation was captured (some CLIs submit a command only on "\r"). Consumers
252
+ # that don't need it (e.g. the model unit tests) simply ignore this key.
253
+ @output&.puts "command_newline: #{command_newline.dump}"
238
254
 
239
255
  if @exec_mode
240
256
  # init prompt does not exist and is empty in exec mode
@@ -70,7 +70,6 @@
70
70
  # resolve_dns: false
71
71
  # interval: 3600
72
72
  # rest: 0.0.0.0:8888
73
- # log: /home/oxidized/.config/oxidized/logs/oxidized.log
74
73
  # debug: true # optional – enables detailed logging from the hook
75
74
  #
76
75
  # source:
@@ -158,9 +157,8 @@ class Modelrulesadvanced < Oxidized::Hook
158
157
  node[:model] = matched_model
159
158
  logger.debug "ModelRulesAdvanced: changed model from #{old_model.inspect} to #{matched_model.inspect}"
160
159
  else
161
- # rubocop:disable Layout/LineLength
162
- logger.debug "ModelRulesAdvanced: no rule matched, keeping existing model: #{node[:model] || node['model'].inspect}"
163
- # rubocop:enable Layout/LineLength
160
+ model = node[:model] || node["model"]
161
+ logger.debug "ModelRulesAdvanced: no rule matched, keeping existing model: #{model.inspect}"
164
162
  end
165
163
 
166
164
  node
@@ -13,7 +13,6 @@ Wants=network-online.target
13
13
  [Service]
14
14
  ExecStart=/usr/local/bin/oxidized
15
15
  User=oxidized
16
- KillSignal=SIGKILL
17
16
  #Environment="OXIDIZED_HOME=/etc/oxidized"
18
17
  Restart=on-failure
19
18
  RestartSec=300s
data/extra/syslog.rb CHANGED
@@ -99,7 +99,7 @@ module Oxidized
99
99
  def junos(log, index, **opts)
100
100
  # TODO: we need to fetch 'ip/name' in mode == :file here
101
101
  opts[:user] = log[index + 2][1..-2]
102
- opts[:msg] = log[(index + 6)..-1].join(' ')[10..-2]
102
+ opts[:msg] = log[(index + 6)..].join(' ')[10..-2]
103
103
  opts.delete(:msg) if opts[:msg] == 'none'
104
104
  opts
105
105
  end
@@ -0,0 +1,149 @@
1
+ require 'time'
2
+ require_relative '../redact'
3
+
4
+ module Oxidized
5
+ class CLI
6
+ module Support
7
+ ROOT_GEMS = %w[oxidized oxidized-web].freeze
8
+ EXPLICIT_ENV_KEYS = %w[
9
+ OXIDIZED_HOME
10
+ OXIDIZED_LOGS
11
+ CONFIG_RELOAD_INTERVAL
12
+ UPDATE_CA_CERTIFICATES
13
+ ].freeze
14
+
15
+ private
16
+
17
+ def show_support_details
18
+ print_intro
19
+ print_environment
20
+ print_config_files
21
+ print_rugged_support
22
+ print_installed_gems
23
+ end
24
+
25
+ def print_intro
26
+ os_release = read_os_release
27
+ runit_path = '/etc/service/oxidized/run'
28
+
29
+ puts '> :warning:'
30
+ puts '> The --support option is intended for diagnostic purposes and may include sensitive information.'
31
+ puts '> Remove any sensitive data before sharing this output.'
32
+ puts
33
+ puts '## Oxidized Support Data'
34
+ puts "- Timestamp: #{Time.now.utc.iso8601}"
35
+ puts "- Oxidized version: #{Oxidized::VERSION_FULL}"
36
+ puts "- OS release: #{os_release}" if os_release
37
+ puts "- Container hint (#{runit_path} exists): #{File.exist?(runit_path)}"
38
+ puts "- Ruby engine: #{defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'}"
39
+ puts "- Ruby version: #{RUBY_VERSION}p#{RUBY_PATCHLEVEL} (#{RUBY_PLATFORM})"
40
+ puts "- Working directory: #{Dir.pwd}"
41
+ puts "- Gem paths: #{Gem.path.join(', ')}"
42
+ puts
43
+ end
44
+
45
+ def print_environment
46
+ puts '### Environment Variables'
47
+ keys = (ENV.keys.grep(/^OXIDIZED_/) + EXPLICIT_ENV_KEYS).uniq.sort
48
+
49
+ keys.each do |key|
50
+ next unless ENV.has_key?(key)
51
+
52
+ value = ENV.fetch(key)
53
+ puts "#{key}=#{Redact.value(key, value)}"
54
+ end
55
+
56
+ puts
57
+ end
58
+
59
+ def print_config_files
60
+ puts '### Configuration Files'
61
+ config_paths.each do |path|
62
+ config_path = File.expand_path(path)
63
+ exists = File.exist?(config_path)
64
+ puts "- #{config_path} exists: #{exists ? 'yes' : 'no'}"
65
+ next unless exists
66
+
67
+ print_sanitized_config(config_path)
68
+ end
69
+ puts
70
+ end
71
+
72
+ def print_rugged_support
73
+ puts '### Rugged'
74
+ begin
75
+ require 'rugged'
76
+ puts "- Rugged version: #{Rugged::VERSION}"
77
+
78
+ ssh_supported = Rugged.respond_to?(:features) && Rugged.features.include?(:ssh)
79
+ puts "- Rugged SSH support: #{ssh_supported}"
80
+ rescue LoadError
81
+ puts '- Rugged: not available'
82
+ puts '- Rugged SSH support: false'
83
+ end
84
+ puts
85
+ end
86
+
87
+ def print_installed_gems
88
+ puts '### Relevant Installed Gems'
89
+ relevant_gem_names.each do |name|
90
+ versions = Gem::Specification.find_all_by_name(name).sort_by(&:version).map { |s| s.version.to_s }
91
+ puts "- #{name} (#{versions.join(', ')})" unless versions.empty?
92
+ end
93
+ end
94
+
95
+ def relevant_gem_names
96
+ names = ROOT_GEMS.select { |name| Gem::Specification.any? { |s| s.name == name } }
97
+
98
+ root_specs = names.flat_map { |name| Gem::Specification.find_all_by_name(name) }
99
+ runtime_deps = root_specs.flat_map { |spec| spec.dependencies }
100
+ names.concat(runtime_deps.map(&:name))
101
+ names.sort.uniq
102
+ end
103
+
104
+ def config_paths
105
+ user_default = File.join(Dir.home, '.config', 'oxidized', 'config')
106
+ home_from_env = File.join(File.expand_path(Oxidized::Config::ROOT), 'config')
107
+
108
+ [
109
+ '/etc/oxidized/config',
110
+ user_default,
111
+ home_from_env
112
+ ].uniq
113
+ end
114
+
115
+ def print_sanitized_config(path)
116
+ content = File.read(path)
117
+ puts '```yaml'
118
+ content.each_line(chomp: true) do |line|
119
+ key, separator, = line.partition(':')
120
+
121
+ if separator.empty? || key.empty?
122
+ puts line
123
+ next
124
+ end
125
+
126
+ if Redact.sensitive?(key)
127
+ puts "#{key}: #{Redact::REDACTED}"
128
+ else
129
+ puts line
130
+ end
131
+ end
132
+ puts '```'
133
+ rescue StandardError => e
134
+ puts " <failed to read: #{e.class}: #{e.message}>"
135
+ end
136
+
137
+ def read_os_release
138
+ return nil unless File.exist?('/etc/os-release')
139
+
140
+ line = File.foreach('/etc/os-release').find { |entry| entry.start_with?('PRETTY_NAME=') }
141
+ return nil unless line
142
+
143
+ line.split('=', 2).last.to_s.strip.gsub(/^"|"$/, '')
144
+ rescue StandardError
145
+ nil
146
+ end
147
+ end
148
+ end
149
+ end
data/lib/oxidized/cli.rb CHANGED
@@ -1,8 +1,10 @@
1
1
  require 'semantic_logger'
2
+ require_relative 'cli/support'
2
3
 
3
4
  module Oxidized
4
5
  class CLI
5
6
  include SemanticLogger::Loggable
7
+ include Support
6
8
 
7
9
  require 'slop'
8
10
  require 'oxidized'
@@ -48,6 +50,7 @@ module Oxidized
48
50
  opts = Slop.parse do |opt|
49
51
  opt.on '-d', '--debug', 'turn on debugging'
50
52
  opt.on '--daemonize', 'Daemonize/fork the process'
53
+ opt.on '--support', 'show support diagnostics and exit'
51
54
  opt.string '--home-dir', 'Oxidized home dir', default: nil
52
55
  opt.string '--config-file', 'Oxidized config file', default: nil
53
56
  opt.on '-h', '--help', 'show usage' do
@@ -64,6 +67,12 @@ module Oxidized
64
67
  Kernel.exit
65
68
  end
66
69
  end
70
+
71
+ if opts[:support]
72
+ show_support_details
73
+ Kernel.exit
74
+ end
75
+
67
76
  [opts.arguments, opts]
68
77
  end
69
78
 
@@ -25,7 +25,8 @@ module Oxidized
25
25
  if val.nil?
26
26
  Oxidized.logger.debug "vars.rb: scope #{scope_name} has key #{name} with value nil, ignoring scope"
27
27
  else
28
- Oxidized.logger.debug "vars.rb: scope #{scope_name} has key #{name} with value #{val}, using scope"
28
+ Oxidized.logger.debug "vars.rb: scope #{scope_name} has key #{name} " \
29
+ "with value #{Redact.value(name, val)}, using scope"
29
30
  return val
30
31
  end
31
32
  end
data/lib/oxidized/core.rb CHANGED
@@ -10,6 +10,8 @@ module Oxidized
10
10
 
11
11
  class NoNodesFound < OxidizedError; end
12
12
 
13
+ MIN_WEB_VERSION = '0.17.0'.freeze
14
+
13
15
  def initialize(_args)
14
16
  Oxidized.mgr = Manager.new
15
17
  Oxidized.hooks = HookManager.from_config(Oxidized.config)
@@ -56,6 +58,7 @@ module Oxidized
56
58
  'configuration'
57
59
  end
58
60
  @rest = API::Web.new nodes, configuration
61
+ check_web_version
59
62
  @rest.run
60
63
  end
61
64
  run
@@ -63,6 +66,23 @@ module Oxidized
63
66
 
64
67
  private
65
68
 
69
+ # WEB_VERSION is defined by oxidized/web/webapp, loaded by API::Web.new.
70
+ # Extracted from check_web_version so that core_spec can stub it in tests.
71
+ def web_version
72
+ API::WEB_VERSION if API.const_defined?(:WEB_VERSION)
73
+ end
74
+
75
+ def check_web_version
76
+ version = web_version
77
+ return if version.nil? || Gem::Version.new(version) >= Gem::Version.new(MIN_WEB_VERSION)
78
+
79
+ logger.warn(
80
+ "oxidized-web #{version} is older than #{MIN_WEB_VERSION}: " \
81
+ 'the display of node versions and diffs fails, and puma may ' \
82
+ 'override the signal handlers. Please update oxidized-web'
83
+ )
84
+ end
85
+
66
86
  def reload
67
87
  logger.info("Reloading node list")
68
88
  @worker.reload
@@ -28,7 +28,7 @@ class CiscoSparkDiff < Oxidized::Hook
28
28
  title = ctx.node.name.to_s
29
29
  logger.info "Posting diff as snippet to #{cfg.space}"
30
30
  room.send_message CiscoSpark::Message.new(text: "Device #{title} modified:\n" +
31
- diff[:patch].lines.to_a[4..-1].join)
31
+ diff[:patch].lines.to_a[4..].join)
32
32
  end
33
33
 
34
34
  if cfg.message?
@@ -65,7 +65,7 @@ class SlackDiff < Oxidized::Hook
65
65
  diff = gitoutput.get_diff ctx.node, ctx.node.group, ctx.commitref, nil
66
66
  unless diff == "no diffs"
67
67
  title = "#{ctx.node.name} #{ctx.node.group} #{ctx.node.model.class.name.to_s.downcase}"
68
- content = diff[:patch].lines.to_a[4..-1].join
68
+ content = diff[:patch].lines.to_a[4..].join
69
69
  slack_upload(client, title, content, cfg.channel, cfg.has_key?('proxy') ? cfg.proxy : nil)
70
70
  end
71
71
  end
@@ -56,7 +56,7 @@ class XMPPDiff < Oxidized::Hook
56
56
  gitoutput = ctx.node.output.new
57
57
  diff = gitoutput.get_diff ctx.node, ctx.node.group, ctx.commitref, nil
58
58
 
59
- interesting = diff[:patch].lines.to_a[4..-1].any? do |line|
59
+ interesting = diff[:patch].lines.to_a[4..].any? do |line|
60
60
  ["+", "-"].include?(line[0]) && (not ["#", "!"].include?(line[1]))
61
61
  end
62
62
 
@@ -68,7 +68,7 @@ class XMPPDiff < Oxidized::Hook
68
68
  title = "#{ctx.node.name} #{ctx.node.group} #{ctx.node.model.class.name.to_s.downcase}"
69
69
  logger.info "Posting diff as snippet to #{cfg.channel}"
70
70
 
71
- @muc.say(title + "\n\n" + diff[:patch].lines.to_a[4..-1].join)
71
+ @muc.say(title + "\n\n" + diff[:patch].lines.to_a[4..].join)
72
72
  end
73
73
  end
74
74
  end
data/lib/oxidized/hook.rb CHANGED
@@ -6,6 +6,8 @@ module Oxidized
6
6
  def from_config(cfg)
7
7
  mgr = new
8
8
  cfg.hooks.each do |name, h_cfg|
9
+ raise("Please specify an hook type in the configuration") unless h_cfg.type?
10
+
9
11
  h_cfg.events.each do |event|
10
12
  mgr.register event.to_sym, name, h_cfg.type, h_cfg
11
13
  end
@@ -62,11 +62,23 @@ module Oxidized
62
62
  match_re << @username if @username
63
63
  match_re << @password if @password
64
64
  until (match = expect(match_re)) == @node.prompt
65
- cmd(@node.auth[:username], nil) if match == @username
66
- cmd(@node.auth[:password], nil) if match == @password
65
+ send_credential(:username) if match == @username
66
+ send_credential(:password) if match == @password
67
67
  match_re.delete match
68
68
  end
69
69
  end
70
+
71
+ private
72
+
73
+ def send_credential(type)
74
+ credential = @node.auth[type]
75
+ unless credential.is_a?(String)
76
+ logger.error "Missing #{type} for CLI login at #{@node.name}"
77
+ raise ArgumentError, "missing #{type} for CLI login"
78
+ end
79
+
80
+ cmd credential, nil
81
+ end
70
82
  end
71
83
  end
72
84
  end
@@ -0,0 +1,40 @@
1
+ module Oxidized
2
+ class DebugText
3
+ include SemanticLogger::Loggable
4
+
5
+ def initialize(config_debug, node, input_name)
6
+ return unless config_debug == true ||
7
+ (config_debug.is_a?(String) && config_debug.downcase.include?('text'))
8
+
9
+ @log = File.open(logfile(node, input_name), 'w')
10
+ end
11
+
12
+ # Separate method to ease unit tests
13
+ def logfile(node, input_name)
14
+ timestamp = Time.now.strftime('%Y%m%d-%H%M%S')
15
+ file = Oxidized::Config::LOG + "/#{node&.ip}-#{input_name}-#{timestamp}.txt"
16
+ logger.debug "Writing I/O Debugging to #{file}"
17
+ file
18
+ end
19
+
20
+ def send_data(data)
21
+ return unless @log
22
+
23
+ @log.puts "sent cmd #{data.dump}"
24
+ @log.flush
25
+ end
26
+
27
+ def receive_data(data)
28
+ return unless @log
29
+
30
+ @log.puts "received #{data.dump}"
31
+ @log.flush
32
+ end
33
+
34
+ def close
35
+ return unless @log
36
+
37
+ @log.close
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,82 @@
1
+ module Oxidized
2
+ class DebugYAML
3
+ include SemanticLogger::Loggable
4
+
5
+ def initialize(config_debug, node, input_name)
6
+ return unless config_debug == true ||
7
+ (config_debug.is_a?(String) && config_debug.downcase.include?('yaml'))
8
+
9
+ @log = File.open(logfile(node, input_name), 'w')
10
+
11
+ @partial_line = false
12
+ @first_line = true
13
+ @commands_started = false
14
+
15
+ @log.puts '---'
16
+ @log.puts 'init_prompt: |-'
17
+ @log.flush
18
+ end
19
+
20
+ # Separate method to ease unit tests
21
+ def logfile(node, input_name)
22
+ timestamp = Time.now.strftime('%Y%m%d-%H%M%S')
23
+ file = Oxidized::Config::LOG + "/#{node&.ip}-#{input_name}-#{timestamp}.yaml"
24
+ logger.debug "Writing YAML Simulation to #{file}"
25
+ file
26
+ end
27
+
28
+ def send_data(data)
29
+ return unless @log
30
+
31
+ @log.puts
32
+ @log.puts 'commands:' unless @commands_started
33
+ @log.puts " - #{data.dump}: |-"
34
+ @first_line = true
35
+ @partial_line = false
36
+ @commands_started = true
37
+ @log.flush
38
+ end
39
+
40
+ def receive_data(data)
41
+ return unless @log
42
+ return if data.empty?
43
+
44
+ lines = data.split("\n", -1)
45
+
46
+ lines.each_with_index do |line, idx|
47
+ is_last = idx == lines.length - 1
48
+ full_line = is_last ? (data[-1] == "\n") : true
49
+ # Escape line and strip surrounding double quotes
50
+ line = line.dump[1..-2]
51
+ if @first_line
52
+ # Make sure the leading space of the first line (if present)
53
+ # is coded with \0x20 or YAML block scalars won't work
54
+ line.sub!(/^ /, '\x20')
55
+ @first_line = false
56
+ end
57
+
58
+ # Make sure trailing white spaces are coded with \0x20
59
+ line.gsub!(/ $/, '\x20')
60
+
61
+ output = @partial_line ? line : (' ' + line)
62
+ @partial_line = false
63
+
64
+ if full_line
65
+ @log.puts output
66
+ else
67
+ @log.write output
68
+ end
69
+ end
70
+
71
+ @partial_line = data[-1] != "\n"
72
+
73
+ @log.flush
74
+ end
75
+
76
+ def close
77
+ return unless @log
78
+
79
+ @log.close
80
+ end
81
+ end
82
+ end
@@ -2,7 +2,6 @@ module Oxidized
2
2
  class Exec < Input
3
3
  def connect(node)
4
4
  @node = node
5
- @log = File.open(Oxidized::Config::LOG + "/#{@node.ip}-exec", "w") if Oxidized.config.input.debug?
6
5
  @node.model.cfg["exec"].each { |cb| instance_exec(&cb) }
7
6
  end
8
7
 
@@ -15,10 +14,6 @@ module Oxidized
15
14
 
16
15
  private
17
16
 
18
- def disconnect
19
- true
20
- ensure
21
- @log.close if Oxidized.config.input.debug?
22
- end
17
+ def disconnect; end
23
18
  end
24
19
  end
@@ -5,7 +5,6 @@ module Oxidized
5
5
  def connect(node) # rubocop:disable Naming/PredicateMethod
6
6
  @node = node
7
7
  @node.model.cfg['ftp'].each { |cb| instance_exec(&cb) }
8
- @log = File.open(Oxidized::Config::LOG + "/#{@node.ip}-ftp", 'w') if Oxidized.config.input.debug?
9
8
  @ftp = Net::FTP.new(@node.ip)
10
9
  @ftp.passive = Oxidized.config.input.ftp.passive
11
10
  @ftp.login @node.auth[:username], @node.auth[:password]
@@ -34,9 +33,6 @@ module Oxidized
34
33
 
35
34
  def disconnect
36
35
  @ftp.close
37
- # rescue Errno::ECONNRESET, IOError
38
- ensure
39
- @log.close if Oxidized.config.input.debug?
40
36
  end
41
37
  end
42
38
  end