oxidized 0.24.0 → 0.25.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +4 -0
  3. data/.rubocop.yml +3 -0
  4. data/CHANGELOG.md +26 -2
  5. data/Dockerfile +8 -32
  6. data/README.md +17 -5
  7. data/bin/oxidized +1 -1
  8. data/docs/Configuration.md +41 -3
  9. data/docs/Hooks.md +26 -0
  10. data/docs/Model-Notes/AireOS.md +1 -2
  11. data/docs/Model-Notes/ArbOS.md +1 -2
  12. data/docs/Model-Notes/Comware.md +1 -2
  13. data/docs/Model-Notes/EOS.md +1 -2
  14. data/docs/Model-Notes/JunOS.md +1 -2
  15. data/docs/Model-Notes/Netgear.md +5 -6
  16. data/docs/Model-Notes/Nokia.md +9 -0
  17. data/docs/Model-Notes/README.md +3 -2
  18. data/docs/Model-Notes/VRP-Huawei.md +1 -2
  19. data/docs/Model-Notes/Viptela.md +12 -0
  20. data/docs/Model-Notes/XGS4600-Zyxel.md +1 -2
  21. data/docs/Ruby-API.md +54 -2
  22. data/docs/Supported-OS-Types.md +12 -0
  23. data/extra/oxidized.service +7 -0
  24. data/lib/oxidized/cli.rb +7 -0
  25. data/lib/oxidized/config.rb +3 -0
  26. data/lib/oxidized/core.rb +1 -0
  27. data/lib/oxidized/hook/ciscosparkdiff.rb +11 -17
  28. data/lib/oxidized/hook/slackdiff.rb +5 -11
  29. data/lib/oxidized/hook/xmppdiff.rb +1 -0
  30. data/lib/oxidized/input/ssh.rb +43 -27
  31. data/lib/oxidized/input/telnet.rb +1 -0
  32. data/lib/oxidized/model/acos.rb +2 -2
  33. data/lib/oxidized/model/acsw.rb +6 -6
  34. data/lib/oxidized/model/adtran.rb +22 -0
  35. data/lib/oxidized/model/aen.rb +2 -2
  36. data/lib/oxidized/model/aireos.rb +3 -2
  37. data/lib/oxidized/model/alteonos.rb +2 -2
  38. data/lib/oxidized/model/aos.rb +1 -1
  39. data/lib/oxidized/model/aos7.rb +1 -1
  40. data/lib/oxidized/model/aosw.rb +5 -3
  41. data/lib/oxidized/model/apc_aos.rb +1 -1
  42. data/lib/oxidized/model/arbos.rb +2 -2
  43. data/lib/oxidized/model/asa.rb +8 -2
  44. data/lib/oxidized/model/awplus.rb +1 -1
  45. data/lib/oxidized/model/axos.rb +16 -0
  46. data/lib/oxidized/model/c4cmts.rb +3 -5
  47. data/lib/oxidized/model/casa.rb +1 -1
  48. data/lib/oxidized/model/catos.rb +1 -1
  49. data/lib/oxidized/model/ciscosma.rb +1 -1
  50. data/lib/oxidized/model/ciscosmb.rb +10 -4
  51. data/lib/oxidized/model/comtrol.rb +41 -0
  52. data/lib/oxidized/model/comware.rb +1 -1
  53. data/lib/oxidized/model/coriantgroove.rb +4 -6
  54. data/lib/oxidized/model/cumulus.rb +14 -1
  55. data/lib/oxidized/model/datacom.rb +1 -2
  56. data/lib/oxidized/model/dcnos.rb +1 -1
  57. data/lib/oxidized/model/dellx.rb +76 -0
  58. data/lib/oxidized/model/dlink.rb +2 -2
  59. data/lib/oxidized/model/dnos.rb +3 -1
  60. data/lib/oxidized/model/eciapollo.rb +34 -0
  61. data/lib/oxidized/model/edgecos.rb +1 -0
  62. data/lib/oxidized/model/edgeos.rb +6 -1
  63. data/lib/oxidized/model/eos.rb +3 -2
  64. data/lib/oxidized/model/fiberdriver.rb +1 -1
  65. data/lib/oxidized/model/firebrick.rb +31 -0
  66. data/lib/oxidized/model/firewareos.rb +1 -1
  67. data/lib/oxidized/model/fortios.rb +5 -4
  68. data/lib/oxidized/model/ftos.rb +4 -1
  69. data/lib/oxidized/model/fujitsupy.rb +3 -3
  70. data/lib/oxidized/model/gaiaos.rb +1 -1
  71. data/lib/oxidized/model/gcombnps.rb +3 -1
  72. data/lib/oxidized/model/hatteras.rb +1 -1
  73. data/lib/oxidized/model/hirschmann.rb +2 -2
  74. data/lib/oxidized/model/hpebladesystem.rb +1 -1
  75. data/lib/oxidized/model/ios.rb +21 -13
  76. data/lib/oxidized/model/ipos.rb +3 -3
  77. data/lib/oxidized/model/ironware.rb +3 -3
  78. data/lib/oxidized/model/isam.rb +1 -1
  79. data/lib/oxidized/model/junos.rb +1 -1
  80. data/lib/oxidized/model/masteros.rb +2 -3
  81. data/lib/oxidized/model/mlnxos.rb +5 -5
  82. data/lib/oxidized/model/model.rb +3 -0
  83. data/lib/oxidized/model/ndms.rb +1 -2
  84. data/lib/oxidized/model/netgear.rb +7 -9
  85. data/lib/oxidized/model/netonix.rb +1 -1
  86. data/lib/oxidized/model/netscaler.rb +6 -1
  87. data/lib/oxidized/model/nos.rb +2 -2
  88. data/lib/oxidized/model/oneos.rb +1 -1
  89. data/lib/oxidized/model/openbsd.rb +8 -22
  90. data/lib/oxidized/model/openwrt.rb +1 -0
  91. data/lib/oxidized/model/opnsense.rb +1 -1
  92. data/lib/oxidized/model/panos.rb +9 -9
  93. data/lib/oxidized/model/pfsense.rb +2 -1
  94. data/lib/oxidized/model/planet.rb +1 -1
  95. data/lib/oxidized/model/powerconnect.rb +7 -4
  96. data/lib/oxidized/model/procurve.rb +7 -5
  97. data/lib/oxidized/model/routeros.rb +1 -1
  98. data/lib/oxidized/model/saos.rb +1 -1
  99. data/lib/oxidized/model/screenos.rb +3 -3
  100. data/lib/oxidized/model/sros.rb +2 -2
  101. data/lib/oxidized/model/stoneos.rb +1 -1
  102. data/lib/oxidized/model/tmos.rb +2 -0
  103. data/lib/oxidized/model/tplink.rb +4 -0
  104. data/lib/oxidized/model/viptela.rb +29 -0
  105. data/lib/oxidized/model/voltaire.rb +5 -5
  106. data/lib/oxidized/model/voss.rb +4 -4
  107. data/lib/oxidized/model/vrp.rb +1 -1
  108. data/lib/oxidized/model/vyatta.rb +1 -1
  109. data/lib/oxidized/model/weos.rb +1 -1
  110. data/lib/oxidized/model/xos.rb +9 -2
  111. data/lib/oxidized/node.rb +20 -31
  112. data/lib/oxidized/nodes.rb +3 -0
  113. data/lib/oxidized/output/git.rb +17 -20
  114. data/lib/oxidized/output/gitcrypt.rb +2 -1
  115. data/lib/oxidized/output/http.rb +19 -12
  116. data/lib/oxidized/source/csv.rb +15 -8
  117. data/lib/oxidized/source/http.rb +26 -22
  118. data/lib/oxidized/string.rb +9 -4
  119. data/lib/oxidized/version.rb +2 -2
  120. data/lib/oxidized/worker.rb +44 -36
  121. data/oxidized.gemspec +1 -4
  122. metadata +26 -16
@@ -1,5 +1,4 @@
1
- ZynOS Configuration
2
- ===================
1
+ # ZynOS Configuration
3
2
 
4
3
  ## FTP
5
4
 
@@ -43,6 +43,8 @@ it at least once is required for a model to work.
43
43
  The block may contain commands to change some behaviour for the given methods
44
44
  (e.g. calling `post_login` to disable the pager).
45
45
 
46
+ Supports [monkey patching](#monkey-patching).
47
+
46
48
  #### `cmd`
47
49
 
48
50
  Is used to specify commands that should be executed on a model in order to
@@ -75,6 +77,8 @@ string.
75
77
  Execution order is `:all`, `:secret`, and lastly the command specific block, if
76
78
  given.
77
79
 
80
+ Supports [monkey patching](#monkey-patching).
81
+
78
82
  #### `comment`
79
83
 
80
84
  Called with a single string containing the string to prepend for comments in
@@ -99,6 +103,8 @@ The passed data is replaced by the return value of the block.
99
103
  `expect` can be used to, for example, strip escape sequences from output before
100
104
  it's further processed.
101
105
 
106
+ Supports [monkey patching](#monkey-patching).
107
+
102
108
  ### At the second level
103
109
 
104
110
  The following methods are available:
@@ -119,7 +125,11 @@ Used inside `cfg` invocations to specify commands to run once Oxidized has
119
125
  logged in to the device. Takes one argument that is either a block (taking zero
120
126
  parameters) or a string containing a command to execute.
121
127
 
122
- This allows `post_login` to be used for any model-specific items prior to running the regular commands. This could include disabling the output pager or timestamp outputs that would cause constant differences.
128
+ This allows `post_login` to be used for any model-specific items prior to
129
+ running the regular commands. This could include disabling the output pager
130
+ or timestamp outputs that would cause constant differences.
131
+
132
+ Supports [monkey patching](#monkey-patching).
123
133
 
124
134
  #### `pre_logout`
125
135
 
@@ -127,9 +137,51 @@ Used to specify commands to run before Oxidized closes the connection to the
127
137
  device. Takes one argument that is either a block (taking zero parameters) or a
128
138
  string containing a command to execute.
129
139
 
130
- This allows `pre_logout` to be used to 'undo' any changes that may have been needed via `post_login` (restore pager output, etc.)
140
+ This allows `pre_logout` to be used to 'undo' any changes that may have been
141
+ needed via `post_login` (restore pager output, etc.)
142
+
143
+ Supports [monkey patching](#monkey-patching).
131
144
 
132
145
  #### `send`
133
146
 
134
147
  Usually used inside `expect` or blocks passed to `post_login`/`pre_logout`.
135
148
  Takes a single parameter: a string to be sent to the device.
149
+
150
+ ### Monkey patching
151
+
152
+ Several model blocks accept behavior-modifying arguments that make monkey
153
+ patching existing blocks easier. This is primarily useful when a user-supplied
154
+ model aims to override or extend existing behavior of a model included in Oxidized.
155
+
156
+ This functionality is supported by `cfg`, `cmd`, `pre_*`, `post_*`, and `expect`
157
+ blocks.
158
+
159
+ #### `clear: true`
160
+
161
+ Resets the existing block, allowing the user to completely override its contents.
162
+
163
+ #### `prepend: true`
164
+
165
+ Ensures that the contents of the block are prepended, rather than appended (the
166
+ default) to an existing block.
167
+
168
+ ### `String` convenience methods
169
+
170
+ Since configuration processing tasks are occasionally similar across models,
171
+ Oxidized provides an extended [`String`](/lib/oxidized/string.rb) class with the
172
+ intention of providing convenience methods and eliminating code duplication.
173
+
174
+ #### `cut_tail`
175
+
176
+ Returns a multi-line string without the last line, or an empty string if only a
177
+ single line was present.
178
+
179
+ #### `cut_head`
180
+
181
+ Returns a multi-line string without the first line, or an empty string if only a
182
+ single line was present.
183
+
184
+ #### `cut_both`
185
+
186
+ Returns a multi-line string without the first and last lines, or an empty string
187
+ if fewer than three lines were present.
@@ -6,6 +6,8 @@
6
6
  * [ACOS](/lib/oxidized/model/acos.rb)
7
7
  * Accedian Performance Elements (NIDs)
8
8
  * [AEN](/lib/oxidized/model/aen.rb)
9
+ * Adtran
10
+ * [Total Access (AOS)](/lib/oxidized/model/adtran.rb)
9
11
  * Alcatel-Lucent
10
12
  * [AOS](/lib/oxidized/model/aos.rb)
11
13
  * [AOS7](/lib/oxidized/model/aos7.rb)
@@ -38,6 +40,8 @@
38
40
  * [Vyatta](/lib/oxidized/model/vyatta.rb)
39
41
  * [6910](/lib/oxidized/model/br6910.rb)
40
42
  * [SLX-OS](/lib/oxidized/model/slxos.rb)
43
+ * Calix
44
+ * [AXOS](/lib/oxidized/model/axos.rb)
41
45
  * Casa
42
46
  * [Casa](/lib/oxidized/model/casa.rb)
43
47
  * Check Point
@@ -65,6 +69,8 @@
65
69
  * [Groove](/lib/oxidized/model/coriantgroove.rb)
66
70
  * ComNet
67
71
  * [ComNet Microsemi Switch](/lib/oxidized/model/comnetms.rb)
72
+ * Comtrol
73
+ * [RocketLinx](/lib/oxidized/model/comtrol.rb)
68
74
  * Cumulus
69
75
  * [Linux](/lib/oxidized/model/cumulus.rb)
70
76
  * DataCom
@@ -74,8 +80,11 @@
74
80
  * DELL
75
81
  * [PowerConnect](/lib/oxidized/model/powerconnect.rb)
76
82
  * [AOSW](/lib/oxidized/model/aosw.rb)
83
+ * [DellX](/lib/oxidized/model/dellx.rb)
77
84
  * D-Link
78
85
  * [D-Link](/lib/oxidized/model/dlink.rb)
86
+ * ECI Telecom
87
+ * [ECIapollo](/lib/oxidized/model/eciapollo.rb)
79
88
  * EdgeCore
80
89
  * [ES3528M](/lib/oxidized/model/edgecos.rb)
81
90
  * Ericsson/Redback
@@ -84,10 +93,13 @@
84
93
  * [Enterasys](/lib/oxidized/model/enterasys.rb)
85
94
  * [WM](/lib/oxidized/model/mtrlrfs.rb)
86
95
  * [XOS](/lib/oxidized/model/xos.rb)
96
+ * [ExtremeWare](/lib/oxidized/model/xos.rb)
87
97
  * F5
88
98
  * [TMOS](/lib/oxidized/model/tmos.rb)
89
99
  * Fiberstore
90
100
  * [S3800](/lib/oxidized/model/gcombnps.rb)
101
+ * Firebrick
102
+ * [FBxxxx](/lib/oxidized/model/firebrick.rb)
91
103
  * Force10
92
104
  * [DNOS](/lib/oxidized/model/dnos.rb)
93
105
  * [FTOS](/lib/oxidized/model/ftos.rb)
@@ -1,4 +1,10 @@
1
1
  #For debian 8 put it in /lib/systemd/system/
2
+ #To set OXIDIZED_HOME instead of the default:
3
+ # ~${oxidized_user}/.config/oxidized in debian 8, then uncomment
4
+ #(and modify as required) the "Environment" variable below so
5
+ #systemd sets the correct environment. Tested only on Debian 8.8.
6
+ #YMMV otherwise.
7
+ #
2
8
  #For RHEL / CentOS 7 put it in /etc/systemd/system/
3
9
  #and call it with systemctl start oxidized.service
4
10
 
@@ -11,6 +17,7 @@ Wants=network-online.target
11
17
  ExecStart=/usr/local/bin/oxidized
12
18
  User=oxidized
13
19
  KillSignal=SIGKILL
20
+ #Environment="OXIDIZED_HOME=/etc/oxidized"
14
21
 
15
22
  [Install]
16
23
  WantedBy=multi-user.target
@@ -43,6 +43,11 @@ module Oxidized
43
43
  opts = Slop.new(:help => true) do
44
44
  on 'd', 'debug', 'turn on debugging'
45
45
  on 'daemonize', 'Daemonize/fork the process'
46
+ on 'show-exhaustive-config', 'output entire configuration, including defaults' do
47
+ asetus = Config.load
48
+ puts asetus.to_yaml asetus.cfg
49
+ Kernel.exit
50
+ end
46
51
  on 'v', 'version', 'show version' do
47
52
  puts Oxidized::VERSION_FULL
48
53
  Kernel.exit
@@ -85,8 +90,10 @@ module Oxidized
85
90
 
86
91
  def pid_status(pidfile)
87
92
  return :exited unless File.exists?(pidfile)
93
+
88
94
  pid = ::File.read(pidfile).to_i
89
95
  return :dead if pid == 0
96
+
90
97
  Process.kill(0, pid)
91
98
  :running
92
99
  rescue Errno::ESRCH
@@ -35,6 +35,9 @@ module Oxidized
35
35
  asetus.default.models = {} # model level configuration
36
36
  asetus.default.pid = File.join(Oxidized::Config::Root, 'pid')
37
37
 
38
+ asetus.default.crash.directory = File.join(Oxidized::Config::Root, 'crashes')
39
+ asetus.default.crash.hostnames = false
40
+
38
41
  asetus.default.stats.history_size = 10
39
42
  asetus.default.input.default = 'ssh, telnet'
40
43
  asetus.default.input.debug = false # or String for session log file
@@ -13,6 +13,7 @@ module Oxidized
13
13
  Oxidized.Hooks = HookManager.from_config(Oxidized.config)
14
14
  nodes = Nodes.new
15
15
  raise NoNodesFound, 'source returns no usable nodes' if nodes.size == 0
16
+
16
17
  @worker = Worker.new nodes
17
18
  trap('HUP') { nodes.load }
18
19
  if Oxidized.config.rest?
@@ -1,7 +1,7 @@
1
1
  require 'cisco_spark'
2
2
 
3
3
  # defaults to posting a diff, if messageformat is supplied them a message will be posted too
4
- # diffenable defaults to true
4
+ # diff defaults to true
5
5
  # Modified from slackdiff
6
6
 
7
7
  class CiscoSparkDiff < Oxidized::Hook
@@ -13,37 +13,31 @@ class CiscoSparkDiff < Oxidized::Hook
13
13
  def run_hook(ctx)
14
14
  return unless ctx.node
15
15
  return unless ctx.event.to_s == "post_store"
16
+
16
17
  log "Connecting to Cisco Spark"
17
18
  CiscoSpark.configure do |config|
18
19
  config.api_key = cfg.accesskey
19
20
  config.proxy = cfg.proxy if cfg.has_key?('proxy')
20
21
  end
21
- space = cfg.space
22
- client = CiscoSpark::Room.new(id: space)
23
- client.fetch
22
+ room = CiscoSpark::Room.new(id: cfg.space)
24
23
  log "Connected"
25
- diffenable = true
26
- if cfg.has_key?('diff') == true
27
- if cfg.diff == false
28
- diffenable = false
29
- end
30
- end
31
- if diffenable == true
24
+
25
+ if cfg.has_key?("diff") ? cfg.diff : true
32
26
  gitoutput = ctx.node.output.new
33
27
  diff = gitoutput.get_diff ctx.node, ctx.node.group, ctx.commitref, nil
34
28
  title = ctx.node.name.to_s
35
29
  log "Posting diff as snippet to #{cfg.space}"
36
- message = CiscoSpark::Message.new(text: 'Device ' + title + ' modified:' + "\n" + diff[:patch].lines.to_a[4..-1].join)
37
- room = CiscoSpark::Room.new(id: space)
38
- room.send_message(message)
30
+ room.send_message CiscoSpark::Message.new(text: 'Device ' + title + ' modified:' + "\n" + diff[:patch].lines.to_a[4..-1].join)
39
31
  end
40
- if cfg.has_key?('message') == true
32
+
33
+ if cfg.message?
41
34
  log cfg.message
42
- msg = cfg.message % { :node => ctx.node.name.to_s, :group => ctx.node.group.to_s, :commitref => ctx.commitref, :model => ctx.node.model.class.name.to_s.downcase }
35
+ msg = cfg.message % { node: ctx.node.name.to_s, group: ctx.node.group.to_s, commitref: ctx.commitref, model: ctx.node.model.class.name.to_s.downcase }
43
36
  log msg
44
37
  log "Posting message to #{cfg.space}"
45
- client.chat_postMessage(channel: cfg.channel, text: msg, as_user: true)
38
+ room.send_message CiscoSpark::Message.new(text: msg)
46
39
  end
40
+
47
41
  log "Finished"
48
42
  end
49
43
  end
@@ -1,7 +1,7 @@
1
1
  require 'slack'
2
2
 
3
3
  # defaults to posting a diff, if messageformat is supplied them a message will be posted too
4
- # diffenable defaults to true
4
+ # diff defaults to true
5
5
 
6
6
  class SlackDiff < Oxidized::Hook
7
7
  def validate_cfg!
@@ -12,6 +12,7 @@ class SlackDiff < Oxidized::Hook
12
12
  def run_hook(ctx)
13
13
  return unless ctx.node
14
14
  return unless ctx.event.to_s == "post_store"
15
+
15
16
  log "Connecting to slack"
16
17
  Slack.configure do |config|
17
18
  config.token = cfg.token
@@ -20,14 +21,7 @@ class SlackDiff < Oxidized::Hook
20
21
  client = Slack::Client.new
21
22
  client.auth_test
22
23
  log "Connected"
23
- # diff snippet - default
24
- diffenable = true
25
- if cfg.has_key?('diff') == true
26
- if cfg.diff == false
27
- diffenable = false
28
- end
29
- end
30
- if diffenable == true
24
+ if cfg.has_key?("diff") ? cfg.diff : true
31
25
  gitoutput = ctx.node.output.new
32
26
  diff = gitoutput.get_diff ctx.node, ctx.node.group, ctx.commitref, nil
33
27
  unless diff == "no diffs"
@@ -41,9 +35,9 @@ class SlackDiff < Oxidized::Hook
41
35
  end
42
36
  end
43
37
  # message custom formatted - optional
44
- if cfg.has_key?('message') == true
38
+ if cfg.message?
45
39
  log cfg.message
46
- msg = cfg.message % { :node => ctx.node.name.to_s, :group => ctx.node.group.to_s, :commitref => ctx.commitref, :model => ctx.node.model.class.name.to_s.downcase }
40
+ msg = cfg.message % { node: ctx.node.name.to_s, group: ctx.node.group.to_s, commitref: ctx.commitref, model: ctx.node.model.class.name.to_s.downcase }
47
41
  log msg
48
42
  log "Posting message to #{cfg.channel}"
49
43
  client.chat_postMessage(channel: cfg.channel, text: msg, as_user: true)
@@ -12,6 +12,7 @@ class XMPPDiff < Oxidized::Hook
12
12
  def run_hook(ctx)
13
13
  return unless ctx.node
14
14
  return unless ctx.event.to_s == "post_store"
15
+
15
16
  begin
16
17
  Timeout.timeout(15) do
17
18
  gitoutput = ctx.node.output.new
@@ -21,36 +21,10 @@ module Oxidized
21
21
  @output = ''
22
22
  @pty_options = { term: "vt100" }
23
23
  @node.model.cfg['ssh'].each { |cb| instance_exec(&cb) }
24
- secure = Oxidized.config.input.ssh.secure
25
24
  @log = File.open(Oxidized::Config::Log + "/#{@node.ip}-ssh", 'w') if Oxidized.config.input.debug?
26
- port = vars(:ssh_port) || 22
27
-
28
- ssh_opts = {
29
- port: port.to_i,
30
- paranoid: secure,
31
- keepalive: true,
32
- password: @node.auth[:password], :timeout => Oxidized.config.timeout,
33
- number_of_password_prompts: 0,
34
- }
35
-
36
- auth_methods = vars(:auth_methods) || %w(none publickey password)
37
- ssh_opts[:auth_methods] = auth_methods
38
- Oxidized.logger.debug "AUTH METHODS::#{auth_methods}"
39
-
40
- if proxy_host = vars(:ssh_proxy)
41
- proxy_command = "ssh "
42
- proxy_command += "-o StrictHostKeyChecking=no " unless secure
43
- proxy_command += "#{proxy_host} -W %h:%p"
44
- proxy = Net::SSH::Proxy::Command.new(proxy_command)
45
- ssh_opts[:proxy] = proxy
46
- end
47
-
48
- ssh_opts[:keys] = vars(:ssh_keys).is_a?(Array) ? vars(:ssh_keys) : [vars(:ssh_keys)] if vars(:ssh_keys)
49
- ssh_opts[:kex] = vars(:ssh_kex).split(/,\s*/) if vars(:ssh_kex)
50
- ssh_opts[:encryption] = vars(:ssh_encryption).split(/,\s*/) if vars(:ssh_encryption)
51
25
 
52
26
  Oxidized.logger.debug "lib/oxidized/input/ssh.rb: Connecting to #{@node.name}"
53
- @ssh = Net::SSH.start(@node.ip, @node.auth[:username], ssh_opts)
27
+ @ssh = Net::SSH.start(@node.ip, @node.auth[:username], make_ssh_opts)
54
28
  unless @exec
55
29
  shell_open @ssh
56
30
  begin
@@ -111,6 +85,7 @@ module Oxidized
111
85
  end
112
86
  ch.request_pty (@pty_options) do |_ch, success_pty|
113
87
  raise NoShell, "Can't get PTY" unless success_pty
88
+
114
89
  ch.send_channel_request 'shell' do |_ch, success_shell|
115
90
  raise NoShell, "Can't get shell" unless success_shell
116
91
  end
@@ -138,9 +113,50 @@ module Oxidized
138
113
  sleep 0.1
139
114
  match = regexps.find { |regexp| @output.match regexp }
140
115
  return match if match
116
+
141
117
  true
142
118
  end
143
119
  end
144
120
  end
121
+
122
+ def make_ssh_opts
123
+ secure = Oxidized.config.input.ssh.secure?
124
+ ssh_opts = {
125
+ port: (vars(:ssh_port) || 22).to_i,
126
+ paranoid: secure,
127
+ keepalive: vars(:ssh_no_keepalive) ? false : true,
128
+ password: @node.auth[:password],
129
+ timeout: Oxidized.config.timeout,
130
+ number_of_password_prompts: 0
131
+ }
132
+
133
+ auth_methods = vars(:auth_methods) || %w(none publickey password)
134
+ ssh_opts[:auth_methods] = auth_methods
135
+ Oxidized.logger.debug "AUTH METHODS::#{auth_methods}"
136
+
137
+ if proxy_host = vars(:ssh_proxy)
138
+ proxy_command = "ssh "
139
+ proxy_command += "-o StrictHostKeyChecking=no " unless secure
140
+ if proxy_port = vars(:ssh_proxy_port)
141
+ proxy_command += "-p #{proxy_port} "
142
+ end
143
+ proxy_command += "#{proxy_host} -W %h:%p"
144
+ proxy = Net::SSH::Proxy::Command.new(proxy_command)
145
+ ssh_opts[:proxy] = proxy
146
+ end
147
+
148
+ ssh_opts[:keys] = [vars(:ssh_keys)].flatten if vars(:ssh_keys)
149
+ ssh_opts[:kex] = vars(:ssh_kex).split(/,\s*/) if vars(:ssh_kex)
150
+ ssh_opts[:encryption] = vars(:ssh_encryption).split(/,\s*/) if vars(:ssh_encryption)
151
+ ssh_opts[:host_key] = vars(:ssh_host_key).split(/,\s*/) if vars(:ssh_host_key)
152
+ ssh_opts[:hmac] = vars(:ssh_hmac).split(/,\s*/) if vars(:ssh_hmac)
153
+
154
+ if Oxidized.config.input.debug?
155
+ ssh_opts[:logger] = Oxidized.logger
156
+ ssh_opts[:verbose] = Logger::DEBUG
157
+ end
158
+
159
+ ssh_opts
160
+ end
145
161
  end
146
162
  end
@@ -34,6 +34,7 @@ module Oxidized
34
34
 
35
35
  def cmd cmd_str, expect = @node.prompt
36
36
  return send(cmd_str + "\n") unless expect
37
+
37
38
  Oxidized.logger.debug "Telnet: #{cmd_str} @#{@node.name}"
38
39
  args = { 'String' => cmd_str,
39
40
  'Match' => expect,
@@ -4,7 +4,7 @@ class ACOS < Oxidized::Model
4
4
  comment '! '
5
5
 
6
6
  # ACOS prompt changes depending on the state of the device
7
- prompt /^([-\w.\/:?\[\]\(\)]+[#>]\s?)$/
7
+ prompt /^([-\w.\/:?\[\]()]+[#>]\s?)$/
8
8
 
9
9
  cmd :secret do |cfg|
10
10
  cfg.gsub!(/community read encrypted (\S+)/, 'community read encrypted <hidden>') # snmp
@@ -60,7 +60,7 @@ class ACOS < Oxidized::Model
60
60
 
61
61
  cmd :all do |cfg, cmdstring|
62
62
  new_cfg = comment "COMMAND: #{cmdstring}\n"
63
- new_cfg << cfg.each_line.to_a[1..-2].join
63
+ new_cfg << cfg.cut_both
64
64
  end
65
65
 
66
66
  pre do
@@ -4,7 +4,7 @@ class ACSW < Oxidized::Model
4
4
 
5
5
  cmd :all do |cfg|
6
6
  cfg.gsub! /^% Invalid input detected at '\^' marker\.$|^\s+\^$/, ''
7
- cfg.each_line.to_a[1..-2].join
7
+ cfg.cut_both
8
8
  end
9
9
 
10
10
  cmd :secret do |cfg|
@@ -36,11 +36,11 @@ class ACSW < Oxidized::Model
36
36
  cfg = cfg.each_line.to_a[3..-1]
37
37
  cfg = cfg.reject { |line| line.match /^ntp clock-period / }.join
38
38
  cfg.gsub! /^Current configuration : [^\n]*\n/, ''
39
- cfg.gsub! /^\ tunnel\ mpls\ traffic-eng\ bandwidth[^\n]*\n*(
40
- (?:\ [^\n]*\n*)*
41
- tunnel\ mpls\ traffic-eng\ auto-bw)/mx, '\1'
42
- cfg.gsub! /^([\s\t\!]*Last configuration change ).*/, ''
43
- cfg.gsub! /^([\s\t\!]*NVRAM config last ).*/, ''
39
+ cfg.gsub! /^ tunnel mpls traffic-eng bandwidth[^\n]*\n*(
40
+ (?: [^\n]*\n*)*
41
+ tunnel mpls traffic-eng auto-bw)/mx, '\1'
42
+ cfg.gsub! /^([\s\t!]*Last configuration change ).*/, ''
43
+ cfg.gsub! /^([\s\t!]*NVRAM config last ).*/, ''
44
44
  cfg
45
45
  end
46
46