oxidized 0.25.1 → 0.26.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 (105) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +30 -9
  3. data/.rubocop_todo.yml +16 -637
  4. data/.travis.yml +2 -3
  5. data/CHANGELOG.md +14 -0
  6. data/Dockerfile +7 -5
  7. data/README.md +18 -14
  8. data/Rakefile +2 -2
  9. data/bin/console +1 -1
  10. data/bin/oxidized +2 -2
  11. data/docs/Configuration.md +6 -0
  12. data/docs/Model-Notes/README.md +1 -0
  13. data/docs/Model-Notes/SmartAX-Huawei.md +35 -0
  14. data/docs/Supported-OS-Types.md +12 -0
  15. data/extra/nagios_check_failing_nodes.rb +1 -1
  16. data/extra/rest_client.rb +6 -8
  17. data/extra/syslog.rb +33 -33
  18. data/lib/oxidized/cli.rb +25 -26
  19. data/lib/oxidized/config.rb +9 -9
  20. data/lib/oxidized/config/vars.rb +3 -7
  21. data/lib/oxidized/core.rb +4 -7
  22. data/lib/oxidized/hook.rb +16 -17
  23. data/lib/oxidized/hook/awssns.rb +4 -4
  24. data/lib/oxidized/hook/exec.rb +16 -20
  25. data/lib/oxidized/hook/githubrepo.rb +8 -14
  26. data/lib/oxidized/hook/noophook.rb +1 -1
  27. data/lib/oxidized/hook/xmppdiff.rb +1 -1
  28. data/lib/oxidized/input/cli.rb +12 -12
  29. data/lib/oxidized/input/ftp.rb +8 -8
  30. data/lib/oxidized/input/http.rb +37 -14
  31. data/lib/oxidized/input/input.rb +6 -6
  32. data/lib/oxidized/input/ssh.rb +31 -31
  33. data/lib/oxidized/input/telnet.rb +24 -24
  34. data/lib/oxidized/input/tftp.rb +9 -10
  35. data/lib/oxidized/jobs.rb +7 -7
  36. data/lib/oxidized/manager.rb +13 -13
  37. data/lib/oxidized/model/acos.rb +2 -2
  38. data/lib/oxidized/model/aireos.rb +3 -3
  39. data/lib/oxidized/model/aos7.rb +1 -1
  40. data/lib/oxidized/model/aosw.rb +12 -14
  41. data/lib/oxidized/model/apc_aos.rb +1 -1
  42. data/lib/oxidized/model/aricentiss.rb +6 -8
  43. data/lib/oxidized/model/asa.rb +1 -1
  44. data/lib/oxidized/model/audiocodesmp.rb +28 -0
  45. data/lib/oxidized/model/awplus.rb +9 -9
  46. data/lib/oxidized/model/boss.rb +1 -1
  47. data/lib/oxidized/model/ciscosmb.rb +1 -1
  48. data/lib/oxidized/model/ciscovpn3k.rb +11 -0
  49. data/lib/oxidized/model/comware.rb +1 -1
  50. data/lib/oxidized/model/cumulus.rb +3 -1
  51. data/lib/oxidized/model/dellx.rb +5 -5
  52. data/lib/oxidized/model/edgeos.rb +1 -1
  53. data/lib/oxidized/model/edgeswitch.rb +1 -1
  54. data/lib/oxidized/model/fabricos.rb +1 -1
  55. data/lib/oxidized/model/fortios.rb +5 -5
  56. data/lib/oxidized/model/ftos.rb +1 -1
  57. data/lib/oxidized/model/gcombnps.rb +7 -7
  58. data/lib/oxidized/model/grandstream.rb +9 -0
  59. data/lib/oxidized/model/hatteras.rb +8 -8
  60. data/lib/oxidized/model/ios.rb +22 -40
  61. data/lib/oxidized/model/ironware.rb +1 -1
  62. data/lib/oxidized/model/junos.rb +1 -1
  63. data/lib/oxidized/model/mlnxos.rb +1 -1
  64. data/lib/oxidized/model/model.rb +32 -38
  65. data/lib/oxidized/model/netgearxs716.rb +23 -0
  66. data/lib/oxidized/model/netonix.rb +1 -1
  67. data/lib/oxidized/model/netscaler.rb +1 -1
  68. data/lib/oxidized/model/nos.rb +2 -2
  69. data/lib/oxidized/model/nxos.rb +1 -1
  70. data/lib/oxidized/model/openbsd.rb +3 -2
  71. data/lib/oxidized/model/outputs.rb +4 -4
  72. data/lib/oxidized/model/planet.rb +4 -4
  73. data/lib/oxidized/model/powerconnect.rb +8 -8
  74. data/lib/oxidized/model/procurve.rb +2 -1
  75. data/lib/oxidized/model/quantaos.rb +3 -3
  76. data/lib/oxidized/model/raisecom.rb +19 -0
  77. data/lib/oxidized/model/siklu.rb +1 -1
  78. data/lib/oxidized/model/slxos.rb +1 -1
  79. data/lib/oxidized/model/smartax.rb +25 -0
  80. data/lib/oxidized/model/sros.rb +4 -4
  81. data/lib/oxidized/model/tdre.rb +30 -0
  82. data/lib/oxidized/model/tmos.rb +3 -0
  83. data/lib/oxidized/model/trango.rb +17 -37
  84. data/lib/oxidized/model/voltaire.rb +1 -1
  85. data/lib/oxidized/model/voss.rb +1 -1
  86. data/lib/oxidized/model/vyatta.rb +1 -1
  87. data/lib/oxidized/model/xos.rb +1 -1
  88. data/lib/oxidized/model/zhoneolt.rb +1 -1
  89. data/lib/oxidized/node.rb +42 -46
  90. data/lib/oxidized/node/stats.rb +6 -6
  91. data/lib/oxidized/nodes.rb +42 -42
  92. data/lib/oxidized/output/file.rb +16 -20
  93. data/lib/oxidized/output/git.rb +68 -78
  94. data/lib/oxidized/output/gitcrypt.rb +77 -91
  95. data/lib/oxidized/output/http.rb +17 -19
  96. data/lib/oxidized/output/output.rb +1 -1
  97. data/lib/oxidized/source/csv.rb +3 -3
  98. data/lib/oxidized/source/http.rb +11 -14
  99. data/lib/oxidized/source/source.rb +3 -3
  100. data/lib/oxidized/source/sql.rb +16 -18
  101. data/lib/oxidized/string.rb +10 -10
  102. data/lib/oxidized/version.rb +4 -4
  103. data/lib/oxidized/worker.rb +15 -15
  104. data/oxidized.gemspec +6 -9
  105. metadata +32 -25
@@ -19,15 +19,15 @@ class PowerConnect < Oxidized::Model
19
19
  end
20
20
 
21
21
  cmd 'show version' do |cfg|
22
- if (@stackable.nil?)
23
- @stackable = true if cfg.match /(U|u)nit\s/
22
+ if @stackable.nil?
23
+ @stackable = true if cfg =~ /(U|u)nit\s/
24
24
  end
25
25
  cfg = cfg.split("\n").reject { |line| line[/Up\sTime/] }
26
26
  comment cfg.join("\n") + "\n"
27
27
  end
28
28
 
29
29
  cmd 'show system' do |cfg|
30
- @model = $1 if cfg.match /Power[C|c]onnect (\d{4})[P|F]?/
30
+ @model = Regexp.last_match(1) if cfg =~ /Power[C|c]onnect (\d{4})[P|F]?/
31
31
  clean cfg
32
32
  end
33
33
 
@@ -45,7 +45,7 @@ class PowerConnect < Oxidized::Model
45
45
  if vars(:enable) == true
46
46
  cmd "enable"
47
47
  elsif vars(:enable)
48
- cmd "enable", /^[pP]assword:/
48
+ cmd "enable", /[pP]assword:/
49
49
  cmd vars(:enable)
50
50
  end
51
51
  end
@@ -56,18 +56,18 @@ class PowerConnect < Oxidized::Model
56
56
  pre_logout "exit"
57
57
  end
58
58
 
59
- def clean cfg
59
+ def clean(cfg)
60
60
  out = []
61
61
  skip_blocks = 0
62
62
  cfg.each_line do |line|
63
63
  # If this is a stackable switch we should skip this block of information
64
- if (line.match /Up\sTime|Temperature|Power Suppl(ies|y)|Fans/i and @stackable == true)
64
+ if line.match(/Up\sTime|Temperature|Power Suppl(ies|y)|Fans/i) && (@stackable == true)
65
65
  skip_blocks = 1
66
66
  # Some switches have another empty line. This is identified by this line having a colon
67
- skip_blocks = 2 if line.match /:/
67
+ skip_blocks = 2 if line =~ /:/
68
68
  end
69
69
  # If we have lines to skip do this until we reach and empty line
70
- if skip_blocks > 0
70
+ if skip_blocks.positive?
71
71
  skip_blocks -= 1 if /\S/ !~ line
72
72
  next
73
73
  end
@@ -28,6 +28,7 @@ class Procurve < Oxidized::Model
28
28
  cmd :all do |cfg|
29
29
  cfg = cfg.cut_both
30
30
  cfg = cfg.gsub /^\r/, ''
31
+ cfg
31
32
  end
32
33
 
33
34
  cmd :secret do |cfg|
@@ -93,6 +94,6 @@ class Procurve < Oxidized::Model
93
94
  end
94
95
 
95
96
  cfg :ssh do
96
- pty_options({ chars_wide: 1000 })
97
+ pty_options(chars_wide: 1000)
97
98
  end
98
99
  end
@@ -4,9 +4,9 @@ class QuantaOS < Oxidized::Model
4
4
 
5
5
  cmd 'show run' do |cfg|
6
6
  cfg.each_line.select do |line|
7
- not line.match /^!.*$/ and
8
- not line.match /^\((\w|\S)+\) (>|#)$/ and
9
- not line.match /^show run$/
7
+ (not line.match /^!.*$/) &&
8
+ (not line.match /^\((\w|\S)+\) (>|#)$/) &&
9
+ (not line.match /^show run$/)
10
10
  end.join
11
11
  end
12
12
 
@@ -0,0 +1,19 @@
1
+ class RAISECOM < Oxidized::Model
2
+ comment '! '
3
+ prompt /([\w.@-]+[#>]\s?)$/
4
+
5
+ cmd 'show version' do |cfg|
6
+ cfg.gsub! /\s(System uptime is ).*/, ' \\1 <removed>'
7
+ comment cfg
8
+ end
9
+
10
+ cmd 'show running-config' do |cfg|
11
+ cfg.gsub! /\s(^radius-encrypt-key ).*/, ' \\1 <removed>'
12
+ cfg
13
+ end
14
+
15
+ cfg :ssh do
16
+ post_login 'terminal page-break disable'
17
+ pre_logout 'exit'
18
+ end
19
+ end
@@ -1,7 +1,7 @@
1
1
  class Siklu < Oxidized::Model
2
2
  # Siklu EtherHaul #
3
3
 
4
- prompt /^[\w-]+>$/
4
+ prompt /^[\^M\s]{0,}[\w\-\s\.\"]+>$/
5
5
 
6
6
  cmd 'copy startup-configuration display' do |cfg|
7
7
  cfg.each_line.to_a[2..2].join
@@ -10,7 +10,7 @@ class SLXOS < Oxidized::Model
10
10
  end
11
11
 
12
12
  cmd 'show chassis' do |cfg|
13
- cfg.encode!("UTF-8", :invalid => :replace, :undef => :replace) # sometimes ironware returns broken encoding
13
+ cfg.encode!("UTF-8", invalid: :replace, undef: :replace) # sometimes ironware returns broken encoding
14
14
  cfg.gsub! /.*Power Usage.*/, '' # remove unwanted lines power usage
15
15
  cfg.gsub! /Time A(live|wake).*/, '' # remove unwanted lines time alive/awake
16
16
  cfg.gsub! /([\[]*)1([\]]*)<->([\[]*)2([\]]*)(<->([\[]*)3([\]]*))*/, ''
@@ -0,0 +1,25 @@
1
+ class SmartAX < Oxidized::Model
2
+ # Huawei SmartAX GPON/EPON/DOCSIS network access devices
3
+ prompt /^([\w.-]+[>#])$/
4
+
5
+ comment '#'
6
+
7
+ cfg :telnet do
8
+ username /^>>User name:$/
9
+ password /^>>User password:$/
10
+ end
11
+
12
+ cfg :ssh, :telnet do
13
+ post_login "enable"
14
+ post_login "undo interactive"
15
+ post_login "undo smart"
16
+ post_login "scroll"
17
+ pre_logout "quit"
18
+ end
19
+
20
+ # 'display current-configuration' returns current configuration stored in memory
21
+ # 'display saved-configuration' returns configuration stored in the file system which is used upon reboot
22
+ cmd 'display current-configuration' do |cfg|
23
+ cfg.cut_both
24
+ end
25
+ end
@@ -51,7 +51,7 @@ class SROS < Oxidized::Model
51
51
  #
52
52
  # Strip carriage returns and backspaces.
53
53
  #
54
- cfg.gsub! /\r/, ''
54
+ cfg.delete! "\r"
55
55
  cfg.gsub! /[\b][\b][\b]/, "\n"
56
56
  cfg.gsub! /# Finished .*/, ''
57
57
  cfg.gsub! /# Generated .*/, ''
@@ -74,7 +74,7 @@ class SROS < Oxidized::Model
74
74
  #
75
75
  # Strip carriage returns.
76
76
  #
77
- cfg.gsub! /\r/, ''
77
+ cfg.delete! "\r"
78
78
  cfg.gsub! /# Finished .*/, ''
79
79
  cfg.gsub! /# Generated .*/, ''
80
80
  comment cfg
@@ -87,7 +87,7 @@ class SROS < Oxidized::Model
87
87
  #
88
88
  # Strip carriage returns.
89
89
  #
90
- cfg.gsub! /\r/, ''
90
+ cfg.delete! "\r"
91
91
  cfg.gsub! /# Finished .*/, ''
92
92
  cfg.gsub! /# Generated .*/, ''
93
93
  comment cfg
@@ -100,7 +100,7 @@ class SROS < Oxidized::Model
100
100
  #
101
101
  # Strip carriage returns.
102
102
  #
103
- cfg.gsub! /\r/, ''
103
+ cfg.delete! "\r"
104
104
  cfg.gsub! /# Finished .*/, ''
105
105
  cfg.gsub! /# Generated .*/, ''
106
106
  end
@@ -0,0 +1,30 @@
1
+ class TDRE < Oxidized::Model
2
+ prompt /^>$/
3
+ cmd "get -f"
4
+
5
+ def ssh
6
+ @input.class.to_s.match(/SSH/)
7
+ end
8
+
9
+ expect /^>.+$/ do |data, re|
10
+ send "\r" if ssh
11
+ data.sub re, ''
12
+ end
13
+
14
+ cmd :all do |cfg|
15
+ if ssh
16
+ cfg.lines.to_a[5..-4].join
17
+ else
18
+ cfg.lines.to_a[1..-4].join
19
+ end
20
+ end
21
+
22
+ cfg :telnet do
23
+ username /^Username:/
24
+ password /^Password:/
25
+ end
26
+
27
+ cfg :telnet, :ssh do
28
+ pre_logout "DISCONNECT\r"
29
+ end
30
+ end
@@ -26,6 +26,9 @@ class TMOS < Oxidized::Model
26
26
  cmd 'tmsh -q list' do |cfg|
27
27
  cfg.gsub!(/state (up|down|checking|irule-down)/, '')
28
28
  cfg.gsub!(/errors (\d+)/, '')
29
+ cfg.gsub!(/^\s+bandwidth-bps (\d+)/, '')
30
+ cfg.gsub!(/^\s+bandwidth-cps (\d+)/, '')
31
+ cfg.gsub!(/^\s+bandwidth-pps (\d+)\n/, '')
29
32
  cfg
30
33
  end
31
34
 
@@ -8,48 +8,28 @@ class Trango < Oxidized::Model
8
8
  out = []
9
9
  comments = []
10
10
  cfg.each_line do |line|
11
- if line.match /\[Opmode\] (off|on) \[Default Opmode\] (off|on)/
11
+ if line =~ /\[Opmode\] (off|on) \[Default Opmode\] (off|on)/
12
12
  out << "opmode " + Regexp.last_match[1]
13
13
  out << "defaultopmode " + Regexp.last_match[2]
14
14
  end
15
- if line.match /\[Tx Power\] ([\-\d]+) dBm/
16
- out << "power " + Regexp.last_match[1]
17
- end
18
- if line.match /\[Active Channel\] (\d+) (v|h)/
19
- out << "freq " + Regexp.last_match[1] + ' ' + Regexp.last_match[2]
20
- end
21
- if line.match /\[Peer ID\] ([A-F0-9]+)/
22
- out << "peerid " + Regexp.last_match[1]
23
- end
24
- if line.match /\[Unit Type\] (\S+)/
25
- out << "utype " + Regexp.last_match[1]
26
- end
27
- if line.match /\[(Hardware Version|Firmware Version|Model|S\/N)\] (\S+)/
28
- comments << '# ' + Regexp.last_match[1] + ': ' + Regexp.last_match[2]
29
- end
30
- if line.match /\[Remarks\] (\S+)/
31
- out << "remarks " + Regexp.last_match[1]
32
- end
33
- if line.match /\[RSSI LED\] (on|off)/
34
- out << "rssiled " + Regexp.last_match[1]
35
- end
36
- if line.match /\[Speed\] (\d+) Mbps/
37
- speed = Regexp.last_match[1]
38
- end
39
- if line.match /\[Tx MIR\] (\d+) Kbps/
40
- out << "mir ".concat(Regexp.last_match[1])
41
- end
42
- if line.match /\[Auto Rate Shift\] (on|off)/
15
+ out << "power " + Regexp.last_match[1] if line =~ /\[Tx Power\] ([\-\d]+) dBm/
16
+ out << "freq " + Regexp.last_match[1] + ' ' + Regexp.last_match[2] if line =~ /\[Active Channel\] (\d+) (v|h)/
17
+ out << "peerid " + Regexp.last_match[1] if line =~ /\[Peer ID\] ([A-F0-9]+)/
18
+ out << "utype " + Regexp.last_match[1] if line =~ /\[Unit Type\] (\S+)/
19
+ comments << '# ' + Regexp.last_match[1] + ': ' + Regexp.last_match[2] if line =~ /\[(Hardware Version|Firmware Version|Model|S\/N)\] (\S+)/
20
+ out << "remarks " + Regexp.last_match[1] if line =~ /\[Remarks\] (\S+)/
21
+ out << "rssiled " + Regexp.last_match[1] if line =~ /\[RSSI LED\] (on|off)/
22
+ speed = Regexp.last_match[1] if line =~ /\[Speed\] (\d+) Mbps/
23
+ out << "mir ".concat(Regexp.last_match[1]) if line =~ /\[Tx MIR\] (\d+) Kbps/
24
+ if line =~ /\[Auto Rate Shift\] (on|off)/
43
25
  out << "autorateshift ".concat(Regexp.last_match[1])
44
- if Regexp.last_match[1].eql? 'off'
45
- out << "speed $speed"
46
- end
47
- end
48
- if line.match /\[IP\] (\S+) \[Subnet Mask\] (\S+) \[Gateway\] (\S+)/
49
- out << "ipconfig " + Regexp.last_match[1] + ' ' +
50
- Regexp.last_match[2] + ' ' +
51
- Regexp.last_match[3]
26
+ out << "speed #{speed}" if Regexp.last_match[1].eql? 'off'
52
27
  end
28
+ next unless line =~ /\[IP\] (\S+) \[Subnet Mask\] (\S+) \[Gateway\] (\S+)/
29
+
30
+ out << "ipconfig " + Regexp.last_match[1] + ' ' +
31
+ Regexp.last_match[2] + ' ' +
32
+ Regexp.last_match[3]
53
33
  end
54
34
  comments.push(*out).join "\n"
55
35
  end
@@ -16,7 +16,7 @@ class VOLTAIRE < Oxidized::Model
16
16
  cfg.gsub! /^System memory:\s.+/, '' # Omit constantly changing memory info
17
17
  cfg.gsub! /^Uptime:\s.+/, '' # Omit constantly changing uptime info
18
18
  cfg.gsub! /.+Generated at\s\d+.+/, '' # Omit constantly changing generation time info
19
- cfg = cfg.lines.to_a[2..-3].join
19
+ cfg.lines.to_a[2..-3].join
20
20
  end
21
21
 
22
22
  cmd :secret do |cfg|
@@ -23,9 +23,9 @@ class Voss < Oxidized::Model
23
23
 
24
24
  # more the config rather than doing a show run
25
25
  cmd 'more config.cfg' do |cfg|
26
- cfg
27
26
  cfg.gsub! /^[^\s#>]+[#>]$/, ''
28
27
  cfg.gsub! /^more config.cfg/, '# more config.cfg'
28
+ cfg
29
29
  end
30
30
 
31
31
  cfg :telnet do
@@ -4,7 +4,7 @@ class Vyatta < Oxidized::Model
4
4
  prompt /@.*?:~\$\s/
5
5
 
6
6
  cmd :all do |cfg|
7
- cfg = cfg.lines.to_a[1..-2].join
7
+ cfg.lines.to_a[1..-2].join
8
8
  end
9
9
 
10
10
  cmd :secret do |cfg|
@@ -23,7 +23,7 @@ class XOS < Oxidized::Model
23
23
  end
24
24
 
25
25
  cmd 'show switch' do |cfg|
26
- comment cfg.each_line.reject { |line| line.match /Time:/ or line.match /boot/i }.join
26
+ comment cfg.each_line.reject { |line| line.match(/Time:/) || line.match(/boot/i) }.join
27
27
  end
28
28
 
29
29
  cmd 'show configuration' do |cfg|
@@ -39,7 +39,7 @@ class ZhoneOLT < Oxidized::Model
39
39
  end
40
40
 
41
41
  cmd 'dump console' do |cfg|
42
- cfg = cfg.each_line.reject { |line| line.match /To Abort the operation enter Ctrl-C/ }.join
42
+ cfg.each_line.reject { |line| line.match /To Abort the operation enter Ctrl-C/ }.join
43
43
  end
44
44
 
45
45
  # zhone technically supports ssh, but it locks up a ton. Especially when
@@ -7,12 +7,12 @@ module Oxidized
7
7
  class Node
8
8
  attr_reader :name, :ip, :model, :input, :output, :group, :auth, :prompt, :vars, :last, :repo
9
9
  attr_accessor :running, :user, :email, :msg, :from, :stats, :retry
10
- alias :running? :running
10
+ alias running? running
11
11
 
12
- def initialize opt
12
+ def initialize(opt)
13
13
  Oxidized.logger.debug 'resolving DNS for %s...' % opt[:name]
14
14
  # remove the prefix if an IP Address is provided with one as IPAddr converts it to a network address.
15
- ip_addr, _ = opt[:ip].to_s.split("/")
15
+ ip_addr, = opt[:ip].to_s.split("/")
16
16
  Oxidized.logger.debug 'IPADDR %s' % ip_addr.to_s
17
17
  @name = opt[:name]
18
18
  @ip = IPAddr.new(ip_addr).to_s rescue nil
@@ -38,10 +38,10 @@ module Oxidized
38
38
  @input.each do |input|
39
39
  # don't try input if model is missing config block, we may need strong config to class_name map
40
40
  cfg_name = input.to_s.split('::').last.downcase
41
- next unless @model.cfg[cfg_name] and not @model.cfg[cfg_name].empty?
41
+ next unless @model.cfg[cfg_name] && (not @model.cfg[cfg_name].empty?)
42
42
 
43
43
  @model.input = input = input.new
44
- if config = run_input(input)
44
+ if (config = run_input(input))
45
45
  Oxidized.logger.debug "lib/oxidized/node.rb: #{input.class.name} ran for #{name} successfully"
46
46
  status = :success
47
47
  break
@@ -54,7 +54,7 @@ module Oxidized
54
54
  [status, config]
55
55
  end
56
56
 
57
- def run_input input
57
+ def run_input(input)
58
58
  rescue_fail = {}
59
59
  [input.class::RescueFail, input.class.superclass::RescueFail].each do |hash|
60
60
  hash.each do |level, errors|
@@ -64,56 +64,56 @@ module Oxidized
64
64
  end
65
65
  end
66
66
  begin
67
- input.connect(self) and input.get
67
+ input.connect(self) && input.get
68
68
  rescue *rescue_fail.keys => err
69
69
  resc = ''
70
- if not level = rescue_fail[err.class]
71
- resc = err.class.ancestors.find { |e| rescue_fail.keys.include? e }
70
+ unless (level = rescue_fail[err.class])
71
+ resc = err.class.ancestors.find { |e| rescue_fail.has_key?(e) }
72
72
  level = rescue_fail[resc]
73
73
  resc = " (rescued #{resc})"
74
74
  end
75
- Oxidized.logger.send(level, '%s raised %s%s with msg "%s"' % [self.ip, err.class, resc, err.message])
75
+ Oxidized.logger.send(level, '%s raised %s%s with msg "%s"' % [ip, err.class, resc, err.message])
76
76
  return false
77
- rescue => err
77
+ rescue StandardError => err
78
78
  crashdir = Oxidized.config.crash.directory
79
- crashfile = Oxidized.config.crash.hostnames? ? self.name : self.ip.to_s
79
+ crashfile = Oxidized.config.crash.hostnames? ? name : ip.to_s
80
80
  FileUtils.mkdir_p(crashdir) unless File.directory?(crashdir)
81
81
 
82
- open File.join(crashdir, crashfile), 'w' do |fh|
82
+ File.open File.join(crashdir, crashfile), 'w' do |fh|
83
83
  fh.puts Time.now.utc
84
84
  fh.puts err.message + ' [' + err.class.to_s + ']'
85
85
  fh.puts '-' * 50
86
86
  fh.puts err.backtrace
87
87
  end
88
- Oxidized.logger.error '%s raised %s with msg "%s", %s saved' % [self.ip, err.class, err.message, crashfile]
88
+ Oxidized.logger.error '%s raised %s with msg "%s", %s saved' % [ip, err.class, err.message, crashfile]
89
89
  return false
90
90
  end
91
91
  end
92
92
 
93
93
  def serialize
94
94
  h = {
95
- :name => @name,
96
- :full_name => @name,
97
- :ip => @ip,
98
- :group => @group,
99
- :model => @model.class.to_s,
100
- :last => nil,
101
- :vars => @vars,
102
- :mtime => @stats.mtime,
95
+ name: @name,
96
+ full_name: @name,
97
+ ip: @ip,
98
+ group: @group,
99
+ model: @model.class.to_s,
100
+ last: nil,
101
+ vars: @vars,
102
+ mtime: @stats.mtime
103
103
  }
104
104
  h[:full_name] = [@group, @name].join('/') if @group
105
105
  if @last
106
106
  h[:last] = {
107
- :start => @last.start,
108
- :end => @last.end,
109
- :status => @last.status,
110
- :time => @last.time,
107
+ start: @last.start,
108
+ end: @last.end,
109
+ status: @last.status,
110
+ time: @last.time
111
111
  }
112
112
  end
113
113
  h
114
114
  end
115
115
 
116
- def last= job
116
+ def last=(job)
117
117
  if job
118
118
  ostruct = OpenStruct.new
119
119
  ostruct.start = job.start
@@ -137,46 +137,42 @@ module Oxidized
137
137
 
138
138
  private
139
139
 
140
- def resolve_prompt opt
140
+ def resolve_prompt(opt)
141
141
  opt[:prompt] || @model.prompt || Oxidized.config.prompt
142
142
  end
143
143
 
144
- def resolve_auth opt
144
+ def resolve_auth(opt)
145
145
  # Resolve configured username/password
146
146
  {
147
- username: resolve_key(:username, opt),
148
- password: resolve_key(:password, opt),
147
+ username: resolve_key(:username, opt),
148
+ password: resolve_key(:password, opt)
149
149
  }
150
150
  end
151
151
 
152
- def resolve_input opt
152
+ def resolve_input(opt)
153
153
  inputs = resolve_key :input, opt, Oxidized.config.input.default
154
154
  inputs.split(/\s*,\s*/).map do |input|
155
- if not Oxidized.mgr.input[input]
156
- Oxidized.mgr.add_input input or raise MethodNotFound, "#{input} not found for node #{ip}"
157
- end
155
+ Oxidized.mgr.add_input(input) || raise(MethodNotFound, "#{input} not found for node #{ip}") unless Oxidized.mgr.input[input]
158
156
  Oxidized.mgr.input[input]
159
157
  end
160
158
  end
161
159
 
162
- def resolve_output opt
160
+ def resolve_output(opt)
163
161
  output = resolve_key :output, opt, Oxidized.config.output.default
164
- if not Oxidized.mgr.output[output]
165
- Oxidized.mgr.add_output output or raise MethodNotFound, "#{output} not found for node #{ip}"
166
- end
162
+ Oxidized.mgr.add_output(output) || raise(MethodNotFound, "#{output} not found for node #{ip}") unless Oxidized.mgr.output[output]
167
163
  Oxidized.mgr.output[output]
168
164
  end
169
165
 
170
- def resolve_model opt
166
+ def resolve_model(opt)
171
167
  model = resolve_key :model, opt
172
- if not Oxidized.mgr.model[model]
168
+ unless Oxidized.mgr.model[model]
173
169
  Oxidized.logger.debug "lib/oxidized/node.rb: Loading model #{model.inspect}"
174
- Oxidized.mgr.add_model model or raise ModelNotFound, "#{model} not found for node #{ip}"
170
+ Oxidized.mgr.add_model(model) || raise(ModelNotFound, "#{model} not found for node #{ip}")
175
171
  end
176
172
  Oxidized.mgr.model[model].new
177
173
  end
178
174
 
179
- def resolve_repo opt
175
+ def resolve_repo(opt)
180
176
  type = git_type opt
181
177
  return nil unless type
182
178
 
@@ -192,7 +188,7 @@ module Oxidized
192
188
  end
193
189
  end
194
190
 
195
- def resolve_key key, opt, global = nil
191
+ def resolve_key(key, opt, global = nil)
196
192
  # resolve key, first get global, then get group then get node config
197
193
  key_sym = key.to_sym
198
194
  key_str = key.to_s
@@ -200,7 +196,7 @@ module Oxidized
200
196
  Oxidized.logger.debug "node.rb: resolving node key '#{key}', with passed global value of '#{value}' and node value '#{opt[key_sym]}'"
201
197
 
202
198
  # global
203
- if not value and Oxidized.config.has_key?(key_str)
199
+ if (not value) && Oxidized.config.has_key?(key_str)
204
200
  value = Oxidized.config[key_str]
205
201
  Oxidized.logger.debug "node.rb: setting node key '#{key}' to value '#{value}' from global"
206
202
  end
@@ -227,7 +223,7 @@ module Oxidized
227
223
  value
228
224
  end
229
225
 
230
- def git_type opt
226
+ def git_type(opt)
231
227
  type = opt[:output] || Oxidized.config.output.default
232
228
  return nil unless type[0..2] == "git"
233
229