oxidized 0.28.0 → 0.29.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (233) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +31 -0
  3. data/.github/workflows/codeql.yml +76 -0
  4. data/.github/workflows/publishdocker.yml +11 -2
  5. data/.github/workflows/ruby.yml +42 -0
  6. data/.github/workflows/stale.yml +16 -0
  7. data/.rubocop.yml +30 -10
  8. data/.rubocop_todo.yml +97 -43
  9. data/CHANGELOG.md +149 -2
  10. data/Dockerfile +15 -9
  11. data/README.md +63 -32
  12. data/Rakefile +2 -0
  13. data/docs/Configuration.md +49 -7
  14. data/docs/Creating-Models.md +24 -19
  15. data/docs/Hooks.md +35 -6
  16. data/docs/Model-Notes/ADVA.md +12 -0
  17. data/docs/Model-Notes/Cumulus.md +7 -1
  18. data/docs/Model-Notes/IOS.md +36 -0
  19. data/docs/Model-Notes/JunOS.md +3 -3
  20. data/docs/Model-Notes/LenovoNOS.md +29 -0
  21. data/docs/Model-Notes/LinksysSRW.md +15 -0
  22. data/docs/Model-Notes/Nokia.md +3 -0
  23. data/docs/Model-Notes/OS10.md +33 -0
  24. data/docs/Model-Notes/PanOS_API.md +28 -0
  25. data/docs/Model-Notes/README.md +2 -0
  26. data/docs/Ruby-API.md +12 -8
  27. data/docs/Sources.md +18 -0
  28. data/docs/Supported-OS-Types.md +51 -6
  29. data/docs/Troubleshooting.md +1 -1
  30. data/extra/gitdiff-msteams.sh +91 -0
  31. data/extra/nagios_check_failing_nodes.rb +6 -9
  32. data/extra/oxidized-report-git-commits +71 -14
  33. data/extra/oxidized.init +2 -5
  34. data/extra/oxidized.logrotate +1 -0
  35. data/extra/oxidized.runit +4 -1
  36. data/extra/oxidized.service +5 -8
  37. data/extra/rest_client.rb +1 -1
  38. data/extra/syslog.rb +2 -2
  39. data/lib/oxidized/cli.rb +1 -1
  40. data/lib/oxidized/config/vars.rb +5 -2
  41. data/lib/oxidized/config.rb +6 -3
  42. data/lib/oxidized/core.rb +1 -1
  43. data/lib/oxidized/hook/exec.rb +6 -6
  44. data/lib/oxidized/hook/githubrepo.rb +42 -11
  45. data/lib/oxidized/hook/slackdiff.rb +2 -2
  46. data/lib/oxidized/hook/xmppdiff.rb +45 -25
  47. data/lib/oxidized/hook.rb +4 -8
  48. data/lib/oxidized/input/exec.rb +1 -1
  49. data/lib/oxidized/input/input.rb +1 -0
  50. data/lib/oxidized/input/ssh.rb +23 -20
  51. data/lib/oxidized/input/telnet.rb +52 -44
  52. data/lib/oxidized/job.rb +1 -0
  53. data/lib/oxidized/jobs.rb +11 -6
  54. data/lib/oxidized/manager.rb +1 -0
  55. data/lib/oxidized/model/acmepacket.rb +40 -0
  56. data/lib/oxidized/model/acos.rb +3 -1
  57. data/lib/oxidized/model/acsw.rb +2 -0
  58. data/lib/oxidized/model/adtran.rb +7 -3
  59. data/lib/oxidized/model/adva.rb +68 -0
  60. data/lib/oxidized/model/aen.rb +2 -0
  61. data/lib/oxidized/model/aireos.rb +2 -0
  62. data/lib/oxidized/model/airfiber.rb +3 -1
  63. data/lib/oxidized/model/airos.rb +2 -0
  64. data/lib/oxidized/model/alteonos.rb +2 -0
  65. data/lib/oxidized/model/alvarion.rb +2 -0
  66. data/lib/oxidized/model/aos.rb +2 -0
  67. data/lib/oxidized/model/aos7.rb +2 -0
  68. data/lib/oxidized/model/aoscx.rb +98 -0
  69. data/lib/oxidized/model/aosw.rb +4 -2
  70. data/lib/oxidized/model/apc_aos.rb +2 -0
  71. data/lib/oxidized/model/arbos.rb +2 -0
  72. data/lib/oxidized/model/aricentiss.rb +2 -0
  73. data/lib/oxidized/model/asa.rb +4 -0
  74. data/lib/oxidized/model/asyncos.rb +2 -0
  75. data/lib/oxidized/model/audiocodes.rb +2 -0
  76. data/lib/oxidized/model/audiocodesmp.rb +2 -0
  77. data/lib/oxidized/model/awplus.rb +3 -1
  78. data/lib/oxidized/model/axos.rb +2 -0
  79. data/lib/oxidized/model/bdcom.rb +51 -0
  80. data/lib/oxidized/model/boss.rb +3 -1
  81. data/lib/oxidized/model/br6910.rb +2 -0
  82. data/lib/oxidized/model/c4cmts.rb +2 -0
  83. data/lib/oxidized/model/cambium.rb +2 -0
  84. data/lib/oxidized/model/cambiumepmp.rb +19 -0
  85. data/lib/oxidized/model/casa.rb +6 -1
  86. data/lib/oxidized/model/catos.rb +2 -0
  87. data/lib/oxidized/model/ciscoce.rb +14 -0
  88. data/lib/oxidized/model/cisconga.rb +2 -0
  89. data/lib/oxidized/model/ciscosma.rb +2 -0
  90. data/lib/oxidized/model/ciscosmb.rb +4 -0
  91. data/lib/oxidized/model/ciscovpn3k.rb +2 -0
  92. data/lib/oxidized/model/cnos.rb +2 -0
  93. data/lib/oxidized/model/comnetms.rb +2 -0
  94. data/lib/oxidized/model/comtrol.rb +2 -0
  95. data/lib/oxidized/model/comware.rb +17 -1
  96. data/lib/oxidized/model/coriant8600.rb +2 -0
  97. data/lib/oxidized/model/coriantgroove.rb +2 -0
  98. data/lib/oxidized/model/corianttmos.rb +2 -0
  99. data/lib/oxidized/model/cumulus.rb +60 -44
  100. data/lib/oxidized/model/datacom.rb +2 -0
  101. data/lib/oxidized/model/dcnos.rb +2 -0
  102. data/lib/oxidized/model/dellx.rb +3 -3
  103. data/lib/oxidized/model/dlink.rb +4 -1
  104. data/lib/oxidized/model/dnos.rb +2 -0
  105. data/lib/oxidized/model/eciapollo.rb +2 -0
  106. data/lib/oxidized/model/edgecos.rb +24 -2
  107. data/lib/oxidized/model/edgeos.rb +2 -0
  108. data/lib/oxidized/model/edgeswitch.rb +6 -4
  109. data/lib/oxidized/model/eltex.rb +50 -0
  110. data/lib/oxidized/model/enterasys.rb +20 -3
  111. data/lib/oxidized/model/enterasys800.rb +31 -0
  112. data/lib/oxidized/model/eos.rb +4 -1
  113. data/lib/oxidized/model/fabricos.rb +3 -1
  114. data/lib/oxidized/model/fastiron.rb +5 -2
  115. data/lib/oxidized/model/fiberdriver.rb +2 -0
  116. data/lib/oxidized/model/firebrick.rb +2 -0
  117. data/lib/oxidized/model/firelinuxos.rb +2 -0
  118. data/lib/oxidized/model/firewareos.rb +2 -0
  119. data/lib/oxidized/model/fortios.rb +26 -11
  120. data/lib/oxidized/model/fortiwlc.rb +26 -0
  121. data/lib/oxidized/model/ftos.rb +2 -0
  122. data/lib/oxidized/model/fujitsupy.rb +2 -0
  123. data/lib/oxidized/model/gaiaos.rb +42 -3
  124. data/lib/oxidized/model/gcombnps.rb +2 -0
  125. data/lib/oxidized/model/grandstream.rb +2 -0
  126. data/lib/oxidized/model/h3c.rb +42 -0
  127. data/lib/oxidized/model/hatteras.rb +4 -2
  128. data/lib/oxidized/model/hios.rb +40 -0
  129. data/lib/oxidized/model/hirschmann.rb +2 -0
  130. data/lib/oxidized/model/hpebladesystem.rb +3 -1
  131. data/lib/oxidized/model/hpemsa.rb +2 -0
  132. data/lib/oxidized/model/hpmsm.rb +2 -0
  133. data/lib/oxidized/model/ibos.rb +2 -0
  134. data/lib/oxidized/model/icotera.rb +2 -0
  135. data/lib/oxidized/model/ios.rb +15 -10
  136. data/lib/oxidized/model/iosxe.rb +1 -1
  137. data/lib/oxidized/model/iosxr.rb +2 -0
  138. data/lib/oxidized/model/ipos.rb +2 -0
  139. data/lib/oxidized/model/ironware.rb +10 -4
  140. data/lib/oxidized/model/isam.rb +2 -0
  141. data/lib/oxidized/model/junos.rb +7 -1
  142. data/lib/oxidized/model/lancom.rb +25 -0
  143. data/lib/oxidized/model/lenovonos.rb +84 -0
  144. data/lib/oxidized/model/linksyssrw.rb +73 -0
  145. data/lib/oxidized/model/linuxgeneric.rb +2 -0
  146. data/lib/oxidized/model/masteros.rb +2 -0
  147. data/lib/oxidized/model/mlnxos.rb +4 -0
  148. data/lib/oxidized/model/model.rb +35 -8
  149. data/lib/oxidized/model/mtrlrfs.rb +2 -0
  150. data/lib/oxidized/model/ndms.rb +3 -1
  151. data/lib/oxidized/model/necix.rb +32 -0
  152. data/lib/oxidized/model/netgear.rb +7 -2
  153. data/lib/oxidized/model/netonix.rb +2 -0
  154. data/lib/oxidized/model/netscaler.rb +40 -1
  155. data/lib/oxidized/model/nodegrid.rb +25 -0
  156. data/lib/oxidized/model/nos.rb +2 -0
  157. data/lib/oxidized/model/nsxconfig.rb +2 -0
  158. data/lib/oxidized/model/nsxfirewall.rb +2 -0
  159. data/lib/oxidized/model/nxos.rb +5 -2
  160. data/lib/oxidized/model/oneos.rb +2 -0
  161. data/lib/oxidized/model/openbsd.rb +11 -0
  162. data/lib/oxidized/model/opengear.rb +3 -1
  163. data/lib/oxidized/model/openwrt.rb +2 -0
  164. data/lib/oxidized/model/opnsense.rb +14 -4
  165. data/lib/oxidized/model/os10.rb +2 -0
  166. data/lib/oxidized/model/outputs.rb +2 -0
  167. data/lib/oxidized/model/panos.rb +2 -0
  168. data/lib/oxidized/model/panos_api.rb +73 -0
  169. data/lib/oxidized/model/pfsense.rb +14 -7
  170. data/lib/oxidized/model/planet.rb +2 -0
  171. data/lib/oxidized/model/powerconnect.rb +3 -3
  172. data/lib/oxidized/model/procurve.rb +4 -2
  173. data/lib/oxidized/model/purityos.rb +10 -1
  174. data/lib/oxidized/model/qtech.rb +2 -0
  175. data/lib/oxidized/model/quantaos.rb +3 -5
  176. data/lib/oxidized/model/raisecom.rb +2 -0
  177. data/lib/oxidized/model/routeros.rb +17 -2
  178. data/lib/oxidized/model/saos.rb +2 -0
  179. data/lib/oxidized/model/screenos.rb +2 -0
  180. data/lib/oxidized/model/sgos.rb +2 -0
  181. data/lib/oxidized/model/siklu.rb +2 -0
  182. data/lib/oxidized/model/slxos.rb +3 -0
  183. data/lib/oxidized/model/smartax.rb +2 -0
  184. data/lib/oxidized/model/smartcs.rb +42 -0
  185. data/lib/oxidized/model/sonicos.rb +11 -1
  186. data/lib/oxidized/model/speedtouch.rb +2 -0
  187. data/lib/oxidized/model/sros.rb +3 -1
  188. data/lib/oxidized/model/srosmd.rb +99 -0
  189. data/lib/oxidized/model/stoneos.rb +8 -2
  190. data/lib/oxidized/model/supermicro.rb +1 -1
  191. data/lib/oxidized/model/swos.rb +11 -0
  192. data/lib/oxidized/model/tdre.rb +2 -0
  193. data/lib/oxidized/model/telco.rb +2 -0
  194. data/lib/oxidized/model/timos.rb +1 -1
  195. data/lib/oxidized/model/tmos.rb +5 -2
  196. data/lib/oxidized/model/tplink.rb +4 -0
  197. data/lib/oxidized/model/trango.rb +13 -11
  198. data/lib/oxidized/model/truenas.rb +22 -0
  199. data/lib/oxidized/model/ucs.rb +2 -0
  200. data/lib/oxidized/model/viptela.rb +2 -0
  201. data/lib/oxidized/model/voltaire.rb +2 -0
  202. data/lib/oxidized/model/voss.rb +2 -0
  203. data/lib/oxidized/model/vrp.rb +3 -1
  204. data/lib/oxidized/model/vyatta.rb +2 -0
  205. data/lib/oxidized/model/weos.rb +2 -0
  206. data/lib/oxidized/model/xos.rb +6 -3
  207. data/lib/oxidized/model/yamaha.rb +59 -0
  208. data/lib/oxidized/model/zhoneolt.rb +2 -0
  209. data/lib/oxidized/model/zteolt.rb +54 -0
  210. data/lib/oxidized/model/zy1308.rb +13 -0
  211. data/lib/oxidized/model/zynos.rb +2 -0
  212. data/lib/oxidized/model/zynoscli.rb +2 -0
  213. data/lib/oxidized/model/zynosgs.rb +2 -0
  214. data/lib/oxidized/node/stats.rb +1 -0
  215. data/lib/oxidized/node.rb +16 -11
  216. data/lib/oxidized/nodes.rb +7 -6
  217. data/lib/oxidized/output/file.rb +2 -1
  218. data/lib/oxidized/output/git.rb +5 -3
  219. data/lib/oxidized/output/gitcrypt.rb +5 -8
  220. data/lib/oxidized/output/http.rb +2 -0
  221. data/lib/oxidized/source/csv.rb +1 -0
  222. data/lib/oxidized/source/http.rb +4 -0
  223. data/lib/oxidized/source/source.rb +7 -2
  224. data/lib/oxidized/source/sql.rb +15 -5
  225. data/lib/oxidized/version.rb +2 -2
  226. data/lib/oxidized/worker.rb +5 -5
  227. data/lib/oxidized.rb +1 -1
  228. data/lib/refinements.rb +43 -0
  229. data/oxidized.gemspec +22 -16
  230. metadata +120 -31
  231. data/.github/no-response.yml +0 -13
  232. data/.travis.yml +0 -10
  233. data/lib/oxidized/string.rb +0 -36
@@ -0,0 +1,54 @@
1
+ class ZTEOLT < Oxidized::Model
2
+ using Refinements
3
+
4
+ # Tested with C320 and C300 olt, firware 1.2.5P3 and 2.1.0
5
+
6
+ prompt /^([\w.@()-]+[#>]\s?)$/
7
+ comment '! '
8
+
9
+ cmd :all do |cfg|
10
+ cfg.gsub! /^% Invalid input detected at '\^' marker\.$|^\s+\^$/, ''
11
+ cfg.cut_both
12
+ end
13
+
14
+ cmd :secret do |cfg|
15
+ cfg.gsub! /^(snmp-server community).*/, '\\1 <configuration removed>'
16
+ cfg.gsub! /^(tacacs-server (.+ )?key) .+/, '\\1 <secret hidden>'
17
+ cfg.gsub! /^username (\S+) privilege (\d+) (\S+).*/, '<secret hidden>'
18
+ cfg.gsub! /^(enable (password|secret)( level \d+)? \d) .+/, '\\1 <secret hidden>'
19
+ cfg
20
+ end
21
+
22
+ cmd 'show version-running' do |cfg|
23
+ comment cfg
24
+ end
25
+
26
+ cmd 'show patch-running' do |cfg|
27
+ comment cfg
28
+ end
29
+
30
+ cmd 'show running-config' do |cfg|
31
+ cfg.gsub! /^timestamp_write: .*\n/, ''
32
+ cfg
33
+ end
34
+
35
+ cfg :telnet do
36
+ username /^Username:/i
37
+ password /^Password:/i
38
+ end
39
+
40
+ cfg :telnet, :ssh do
41
+ # preferred way to handle additional passwords
42
+ post_login do
43
+ if vars(:enable) == true
44
+ cmd "enable"
45
+ elsif vars(:enable)
46
+ cmd "enable", /^[pP]assword:/
47
+ cmd vars(:enable)
48
+ end
49
+ end
50
+ post_login 'terminal length 0'
51
+ pre_logout 'disable'
52
+ pre_logout 'exit'
53
+ end
54
+ end
@@ -0,0 +1,13 @@
1
+ # For Zyxel OLTs series 1308
2
+ class Zy1308 < Oxidized::Model
3
+ using Refinements
4
+
5
+ # For Zyxel OLTs series 1308
6
+
7
+ cmd '/config_OLT-1308S-22.log'
8
+ cfg :http do
9
+ @username = @node.auth[:username]
10
+ @password = @node.auth[:password]
11
+ @secure = false
12
+ end
13
+ end
@@ -1,4 +1,6 @@
1
1
  class ZyNOS < Oxidized::Model
2
+ using Refinements
3
+
2
4
  # Used in Zyxel DSLAMs, such as SAM1316
3
5
 
4
6
  comment '! '
@@ -1,4 +1,6 @@
1
1
  class ZyNOSCLI < Oxidized::Model
2
+ using Refinements
3
+
2
4
  # Used in Zyxel DSLAMs, such as SAM1316
3
5
 
4
6
  # Typical prompt "XGS4600#"
@@ -1,4 +1,6 @@
1
1
  class ZyNOSGS < Oxidized::Model
2
+ using Refinements
3
+
2
4
  # Used in Zyxel GS1900 switches, tested with GS1900-8
3
5
  prompt /^.*# $/
4
6
  comment '! '
@@ -2,6 +2,7 @@ module Oxidized
2
2
  class Node
3
3
  class Stats
4
4
  attr_reader :mtimes
5
+
5
6
  MAX_STAT = 10
6
7
 
7
8
  # @param [Job] job job whose information add to stats
data/lib/oxidized/node.rb CHANGED
@@ -4,9 +4,10 @@ module Oxidized
4
4
  require_relative 'node/stats'
5
5
  class MethodNotFound < OxidizedError; end
6
6
  class ModelNotFound < OxidizedError; end
7
+
7
8
  class Node
8
9
  attr_reader :name, :ip, :model, :input, :output, :group, :auth, :prompt, :vars, :last, :repo
9
- attr_accessor :running, :user, :email, :msg, :from, :stats, :retry
10
+ attr_accessor :running, :user, :email, :msg, :from, :stats, :retry, :err_type, :err_reason
10
11
  alias running? running
11
12
 
12
13
  def initialize(opt)
@@ -28,6 +29,8 @@ module Oxidized
28
29
  @stats = Stats.new
29
30
  @retry = 0
30
31
  @repo = resolve_repo opt
32
+ @err_type = nil
33
+ @err_reason = nil
31
34
 
32
35
  # model instance needs to access node instance
33
36
  @model.node = self
@@ -73,6 +76,8 @@ module Oxidized
73
76
  resc = " (rescued #{resc})"
74
77
  end
75
78
  Oxidized.logger.send(level, '%s raised %s%s with msg "%s"' % [ip, err.class, resc, err.message])
79
+ @err_type = err.class.to_s
80
+ @err_reason = err.message.to_s
76
81
  false
77
82
  rescue StandardError => err
78
83
  crashdir = Oxidized.config.crash.directory
@@ -86,6 +91,8 @@ module Oxidized
86
91
  fh.puts err.backtrace
87
92
  end
88
93
  Oxidized.logger.error '%s raised %s with msg "%s", %s saved' % [ip, err.class, err.message, crashfile]
94
+ @err_type = err.class.to_s
95
+ @err_reason = err.message.to_s
89
96
  false
90
97
  end
91
98
  end
@@ -153,6 +160,7 @@ module Oxidized
153
160
  inputs = resolve_key :input, opt, Oxidized.config.input.default
154
161
  inputs.split(/\s*,\s*/).map do |input|
155
162
  Oxidized.mgr.add_input(input) || raise(MethodNotFound, "#{input} not found for node #{ip}") unless Oxidized.mgr.input[input]
163
+
156
164
  Oxidized.mgr.input[input]
157
165
  end
158
166
  end
@@ -160,6 +168,7 @@ module Oxidized
160
168
  def resolve_output(opt)
161
169
  output = resolve_key :output, opt, Oxidized.config.output.default
162
170
  Oxidized.mgr.add_output(output) || raise(MethodNotFound, "#{output} not found for node #{ip}") unless Oxidized.mgr.output[output]
171
+
163
172
  Oxidized.mgr.output[output]
164
173
  end
165
174
 
@@ -202,19 +211,15 @@ module Oxidized
202
211
  end
203
212
 
204
213
  # group
205
- if Oxidized.config.groups.has_key?(@group)
206
- if Oxidized.config.groups[@group].has_key?(key_str)
207
- value = Oxidized.config.groups[@group][key_str]
208
- Oxidized.logger.debug "node.rb: setting node key '#{key}' to value '#{value}' from group"
209
- end
214
+ if Oxidized.config.groups.has_key?(@group) && Oxidized.config.groups[@group].has_key?(key_str)
215
+ value = Oxidized.config.groups[@group][key_str]
216
+ Oxidized.logger.debug "node.rb: setting node key '#{key}' to value '#{value}' from group"
210
217
  end
211
218
 
212
219
  # model
213
- if Oxidized.config.models.has_key?(@model.class.name.to_s.downcase)
214
- if Oxidized.config.models[@model.class.name.to_s.downcase].has_key?(key_str)
215
- value = Oxidized.config.models[@model.class.name.to_s.downcase][key_str]
216
- Oxidized.logger.debug "node.rb: setting node key '#{key}' to value '#{value}' from model"
217
- end
220
+ if Oxidized.config.models.has_key?(@model.class.name.to_s.downcase) && Oxidized.config.models[@model.class.name.to_s.downcase].has_key?(key_str)
221
+ value = Oxidized.config.models[@model.class.name.to_s.downcase][key_str]
222
+ Oxidized.logger.debug "node.rb: setting node key '#{key}' to value '#{value}' from model"
218
223
  end
219
224
 
220
225
  # node
@@ -3,6 +3,7 @@ module Oxidized
3
3
  require 'oxidized/node'
4
4
  class Oxidized::NotSupported < OxidizedError; end
5
5
  class Oxidized::NodeNotFound < OxidizedError; end
6
+
6
7
  class Nodes < Array
7
8
  attr_accessor :source, :jobs
8
9
  alias put unshift
@@ -36,6 +37,7 @@ module Oxidized
36
37
 
37
38
  node_want_ip = (IPAddr.new(node_want) rescue false)
38
39
  name_is_ip = (IPAddr.new(node[:name]) rescue false)
40
+ # rubocop:todo Lint/DuplicateBranch
39
41
  if name_is_ip && (node_want_ip == node[:name])
40
42
  true
41
43
  elsif node[:ip] && (node_want_ip == node[:ip])
@@ -43,6 +45,7 @@ module Oxidized
43
45
  elsif node_want.match node[:name]
44
46
  true unless name_is_ip
45
47
  end
48
+ # rubocop:enable Lint/DuplicateBranch
46
49
  end
47
50
 
48
51
  def list
@@ -159,13 +162,11 @@ module Oxidized
159
162
  old = dup
160
163
  replace(nodes)
161
164
  each do |node|
162
- begin
163
- if (i = old.find_node_index(node.name))
164
- node.stats = old[i].stats
165
- node.last = old[i].last
166
- end
167
- rescue Oxidized::NodeNotFound
165
+ if (i = old.find_node_index(node.name))
166
+ node.stats = old[i].stats
167
+ node.last = old[i].last
168
168
  end
169
+ rescue Oxidized::NodeNotFound
169
170
  end
170
171
  sort_by! { |x| x.last.nil? ? Time.new(0) : x.last.end }
171
172
  end
@@ -5,6 +5,7 @@ module Oxidized
5
5
  attr_reader :commitref
6
6
 
7
7
  def initialize
8
+ super
8
9
  @cfg = Oxidized.config.output.file
9
10
  end
10
11
 
@@ -21,7 +22,7 @@ module Oxidized
21
22
  file = File.join File.dirname(file), opt[:group] if opt[:group]
22
23
  FileUtils.mkdir_p file
23
24
  file = File.join file, node
24
- File.open(file, 'w') { |fh| fh.write outputs.to_cfg }
25
+ File.write(file, outputs.to_cfg)
25
26
  @commitref = file
26
27
  end
27
28
 
@@ -10,6 +10,7 @@ module Oxidized
10
10
  attr_reader :commitref
11
11
 
12
12
  def initialize
13
+ super
13
14
  @cfg = Oxidized.config.output.git
14
15
  end
15
16
 
@@ -78,7 +79,8 @@ module Oxidized
78
79
  i = -1
79
80
  tab = []
80
81
  walker.each do |commit|
81
- next if commit.diff(paths: [path]).size.zero?
82
+ # Diabled rubocop because the suggested .empty? does not work here.
83
+ next if commit.diff(paths: [path]).size.zero? # rubocop:disable Style/ZeroLengthPredicate
82
84
 
83
85
  hash = {}
84
86
  hash[:date] = commit.time.to_s
@@ -158,11 +160,11 @@ module Oxidized
158
160
  begin
159
161
  repo = Rugged::Repository.new repo
160
162
  update_repo repo, file, data
161
- rescue Rugged::OSError, Rugged::RepositoryError => open_error
163
+ rescue Rugged::OSError, Rugged::RepositoryError => e
162
164
  begin
163
165
  Rugged::Repository.init_at repo, :bare
164
166
  rescue StandardError => create_error
165
- raise GitError, "first '#{open_error.message}' was raised while opening git repo, then '#{create_error.message}' was while trying to create git repo"
167
+ raise GitError, "first '#{e.message}' was raised while opening git repo, then '#{create_error.message}' was while trying to create git repo"
166
168
  end
167
169
  retry
168
170
  end
@@ -10,6 +10,7 @@ module Oxidized
10
10
  attr_reader :commitref
11
11
 
12
12
  def initialize
13
+ super
13
14
  @cfg = Oxidized.config.output.gitcrypt
14
15
  @gitcrypt_cmd = "/usr/bin/git-crypt"
15
16
  @gitcrypt_init = @gitcrypt_cmd + " init"
@@ -194,13 +195,13 @@ module Oxidized
194
195
 
195
196
  begin
196
197
  update_repo repo, file, data, @msg, @user, @email
197
- rescue Git::GitExecuteError, ArgumentError => open_error
198
- Oxidized.logger.debug "open_error #{open_error} #{file}"
198
+ rescue Git::GitExecuteError, ArgumentError => e
199
+ Oxidized.logger.debug "open_error #{e} #{file}"
199
200
  begin
200
201
  grepo = Git.init repo
201
202
  crypt_init grepo
202
203
  rescue StandardError => create_error
203
- raise GitCryptError, "first '#{open_error.message}' was raised while opening git repo, then '#{create_error.message}' was while trying to create git repo"
204
+ raise GitCryptError, "first '#{e.message}' was raised while opening git repo, then '#{create_error.message}' was while trying to create git repo"
204
205
  end
205
206
  retry
206
207
  end
@@ -214,11 +215,7 @@ module Oxidized
214
215
  unlock grepo
215
216
  File.write(file, data)
216
217
  grepo.add(file)
217
- if grepo.status[file].nil?
218
- grepo.commit(msg)
219
- @commitref = grepo.log(1).first.objectish
220
- true
221
- elsif !grepo.status[file].type.nil?
218
+ if grepo.status[file].nil? || !grepo.status[file].type.nil?
222
219
  grepo.commit(msg)
223
220
  @commitref = grepo.log(1).first.objectish
224
221
  true
@@ -1,7 +1,9 @@
1
1
  module Oxidized
2
2
  class Http < Output
3
3
  attr_reader :commitref
4
+
4
5
  def initialize
6
+ super
5
7
  @cfg = Oxidized.config.output.http
6
8
  end
7
9
 
@@ -32,6 +32,7 @@ module Oxidized
32
32
  keys[key.to_sym] = node_var_interpolate data[position]
33
33
  end
34
34
  keys[:model] = map_model keys[:model] if keys.has_key? :model
35
+ keys[:group] = map_group keys[:group] if keys.has_key? :group
35
36
 
36
37
  # map node specific vars
37
38
  vars = {}
@@ -29,6 +29,7 @@ module Oxidized
29
29
  keys[key.to_sym] = node_var_interpolate string_navigate(node, want_position)
30
30
  end
31
31
  keys[:model] = map_model keys[:model] if keys.has_key? :model
32
+ keys[:group] = map_group keys[:group] if keys.has_key? :group
32
33
 
33
34
  # map node specific vars
34
35
  vars = {}
@@ -61,6 +62,9 @@ module Oxidized
61
62
  http.use_ssl = true if uri.scheme == 'https'
62
63
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE unless @cfg.secure
63
64
 
65
+ # Add read_timeout to handle case of big list of nodes (default value is 60 seconds)
66
+ http.read_timeout = Integer(@cfg.read_timeout) if @cfg.has_key? "read_timeout"
67
+
64
68
  # map headers
65
69
  headers = {}
66
70
  @cfg.headers.each do |header, value|
@@ -3,11 +3,16 @@ module Oxidized
3
3
  class NoConfig < OxidizedError; end
4
4
 
5
5
  def initialize
6
- @map = (Oxidized.config.model_map || {})
6
+ @model_map = (Oxidized.config.model_map || {})
7
+ @group_map = (Oxidized.config.group_map || {})
7
8
  end
8
9
 
9
10
  def map_model(model)
10
- @map.has_key?(model) ? @map[model] : model
11
+ @model_map.has_key?(model) ? @model_map[model] : model
12
+ end
13
+
14
+ def map_group(group)
15
+ @group_map.has_key?(group) ? @group_map[group] : group
11
16
  end
12
17
 
13
18
  def node_var_interpolate(var)
@@ -31,6 +31,7 @@ module Oxidized
31
31
  keys = {}
32
32
  @cfg.map.each { |key, sql_column| keys[key.to_sym] = node_var_interpolate node[sql_column.to_sym] }
33
33
  keys[:model] = map_model keys[:model] if keys.has_key? :model
34
+ keys[:group] = map_group keys[:group] if keys.has_key? :group
34
35
 
35
36
  # map node specific vars
36
37
  vars = {}
@@ -53,11 +54,20 @@ module Oxidized
53
54
  end
54
55
 
55
56
  def connect
56
- Sequel.connect(adapter: @cfg.adapter,
57
- host: @cfg.host?,
58
- user: @cfg.user?,
59
- password: @cfg.password?,
60
- database: @cfg.database)
57
+ options = {
58
+ adapter: @cfg.adapter,
59
+ host: @cfg.host?,
60
+ user: @cfg.user?,
61
+ password: @cfg.password?,
62
+ database: @cfg.database,
63
+ ssl_mode: @cfg.ssl_mode?
64
+ }
65
+ if @cfg.with_ssl?
66
+ options.merge!(sslca: @cfg.ssl_ca?,
67
+ sslcert: @cfg.ssl_cert?,
68
+ sslkey: @cfg.ssl_key?)
69
+ end
70
+ Sequel.connect(options)
61
71
  rescue Sequel::AdapterNotFound => error
62
72
  raise OxidizedError, "SQL adapter gem not installed: " + error.message
63
73
  end
@@ -1,6 +1,6 @@
1
1
  module Oxidized
2
- VERSION = '0.28.0'.freeze
3
- VERSION_FULL = '0.28.0'.freeze
2
+ VERSION = '0.29.1'.freeze
3
+ VERSION_FULL = '0.29.1'.freeze
4
4
  def self.version_set
5
5
  version_full = %x(git describe --tags).chop rescue ""
6
6
  version = %x(git describe --tags --abbrev=0).chop rescue ""
@@ -5,7 +5,7 @@ module Oxidized
5
5
  def initialize(nodes)
6
6
  @jobs_done = 0
7
7
  @nodes = nodes
8
- @jobs = Jobs.new(Oxidized.config.threads, Oxidized.config.interval, @nodes)
8
+ @jobs = Jobs.new(Oxidized.config.threads, Oxidized.config.use_max_threads, Oxidized.config.interval, @nodes)
9
9
  @nodes.jobs = @jobs
10
10
  Thread.abort_on_exception = true
11
11
  end
@@ -56,7 +56,7 @@ module Oxidized
56
56
 
57
57
  def process_success(node, job)
58
58
  @jobs_done += 1 # needed for :nodes_done hook
59
- Oxidized.Hooks.handle :node_success, node: node,
59
+ Oxidized.hooks.handle :node_success, node: node,
60
60
  job: job
61
61
  msg = "update #{node.group}/#{node.name}"
62
62
  msg += " from #{node.from}" if node.from
@@ -66,7 +66,7 @@ module Oxidized
66
66
  msg: msg, email: node.email, user: node.user, group: node.group
67
67
  node.modified
68
68
  Oxidized.logger.info "Configuration updated for #{node.group}/#{node.name}"
69
- Oxidized.Hooks.handle :post_store, node: node,
69
+ Oxidized.hooks.handle :post_store, node: node,
70
70
  job: job,
71
71
  commitref: output.commitref
72
72
  end
@@ -87,7 +87,7 @@ module Oxidized
87
87
  @jobs_done += 1
88
88
  msg += ", retries exhausted, giving up"
89
89
  node.retry = 0
90
- Oxidized.Hooks.handle :node_fail, node: node,
90
+ Oxidized.hooks.handle :node_fail, node: node,
91
91
  job: job
92
92
  end
93
93
  Oxidized.logger.warn msg
@@ -103,7 +103,7 @@ module Oxidized
103
103
 
104
104
  def run_done_hook
105
105
  Oxidized.logger.debug "lib/oxidized/worker.rb: Running :nodes_done hook"
106
- Oxidized.Hooks.handle :nodes_done
106
+ Oxidized.hooks.handle :nodes_done
107
107
  rescue StandardError => e
108
108
  # swallow the hook erros and continue as normal
109
109
  Oxidized.logger.error "lib/oxidized/worker.rb: #{e.message}"
data/lib/oxidized.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'fileutils'
2
+ require 'refinements'
2
3
 
3
4
  module Oxidized
4
5
  class OxidizedError < StandardError; end
@@ -6,7 +7,6 @@ module Oxidized
6
7
  Directory = File.expand_path(File.join(File.dirname(__FILE__), '../'))
7
8
 
8
9
  require 'oxidized/version'
9
- require 'oxidized/string'
10
10
  require 'oxidized/config'
11
11
  require 'oxidized/config/vars'
12
12
  require 'oxidized/worker'
@@ -0,0 +1,43 @@
1
+ module Refinements
2
+ # Use the 'refine' keyword to define refinements for the String class
3
+ refine String do
4
+ attr_accessor :type, :cmd, :name
5
+
6
+ # @return [String] copy of self with last line removed
7
+ def cut_tail(lines = 1)
8
+ return "" if length.zero?
9
+
10
+ each_line.to_a[0..(-1 - lines)].join
11
+ end
12
+
13
+ # @return [String] copy of self with first line removed
14
+ def cut_head(lines = 1)
15
+ return "" if length.zero?
16
+
17
+ each_line.to_a[lines..-1].join
18
+ end
19
+
20
+ # @return [String] copy of self with first and last lines removed
21
+ def cut_both(head = 1, tail = 1)
22
+ return "" if length.zero?
23
+
24
+ each_line.to_a[head..(-1 - tail)].join
25
+ end
26
+
27
+ # sets @cmd and @name unless @name is already set
28
+ def set_cmd(command)
29
+ @cmd = command
30
+ @name ||= @cmd.to_s.strip.gsub(/\s+/, '_') # what to do when command is proc? #to_s seems ghetto
31
+ end
32
+
33
+ # Initializes the String instance variables from another String instance
34
+ # when the given str is an instance of String with Oxidized refinements applied
35
+ def init_from_string(str = '')
36
+ raise TypeError unless str.instance_of?(String)
37
+
38
+ @cmd = str.instance_variable_get(:@cmd)
39
+ @name = str.instance_variable_get(:@name)
40
+ @type = str.instance_variable_get(:@type)
41
+ end
42
+ end
43
+ end
data/oxidized.gemspec CHANGED
@@ -17,22 +17,28 @@ Gem::Specification.new do |s|
17
17
  s.executables = %w[oxidized]
18
18
  s.require_path = 'lib'
19
19
 
20
- s.required_ruby_version = '>= 2.3'
21
- s.add_runtime_dependency 'asetus', '~> 0.1'
20
+ s.metadata['rubygems_mfa_required'] = 'true'
21
+
22
+ s.required_ruby_version = '>= 3.0'
23
+
24
+ s.add_runtime_dependency 'asetus', '~> 0.1'
22
25
  s.add_runtime_dependency 'bcrypt_pbkdf', '~> 1.0'
23
- s.add_runtime_dependency 'ed25519', '~> 1.2'
24
- s.add_runtime_dependency 'net-ssh', '~> 5'
25
- s.add_runtime_dependency 'net-telnet', '~> 0.2'
26
- s.add_runtime_dependency 'rugged', '~> 0.28.0'
27
- s.add_runtime_dependency 'slop', '~> 4.6'
26
+ s.add_runtime_dependency 'ed25519', '~> 1.2'
27
+ s.add_runtime_dependency 'net-ssh', '~> 7.1'
28
+ s.add_runtime_dependency 'net-telnet', '~> 0.2'
29
+ s.add_runtime_dependency 'rugged', '~> 1.6'
30
+ s.add_runtime_dependency 'slop', '~> 4.6'
28
31
 
29
- s.add_development_dependency 'bundler', '~> 2.0'
30
- s.add_development_dependency 'codecov' if ENV['CI'] == 'true'
31
- s.add_development_dependency 'git', '~> 1'
32
- s.add_development_dependency 'minitest', '~> 5.8'
33
- s.add_development_dependency 'mocha', '~> 1.1'
34
- s.add_development_dependency 'pry', '~> 0'
35
- s.add_development_dependency 'rake', '~> 10.0'
36
- s.add_development_dependency 'rubocop', '~> 0.80.0'
37
- s.add_development_dependency 'simplecov'
32
+ s.add_development_dependency 'bundler', '~> 2.2'
33
+ s.add_development_dependency 'git', '~> 1'
34
+ s.add_development_dependency 'minitest', '~> 5.18'
35
+ s.add_development_dependency 'mocha', '~> 1.2'
36
+ s.add_development_dependency 'pry', '~> 0.14.2'
37
+ s.add_development_dependency 'rake', '~> 13.0'
38
+ s.add_development_dependency 'rubocop', '~> 1.48.0'
39
+ s.add_development_dependency 'rubocop-minitest', '~> 0.29.0'
40
+ s.add_development_dependency 'rubocop-rake', '~> 0.6.0'
41
+ s.add_development_dependency 'simplecov', '~> 0.22.0'
42
+ s.add_development_dependency 'simplecov-cobertura', '~> 2.1.0'
43
+ s.add_development_dependency 'simplecov-html', '~> 0.12.3'
38
44
  end