summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md95
-rw-r--r--lib/oxidized/model/sgos.rb46
-rw-r--r--lib/oxidized/node.rb4
-rw-r--r--lib/oxidized/nodes.rb1
-rw-r--r--lib/oxidized/worker.rb2
5 files changed, 140 insertions, 8 deletions
diff --git a/README.md b/README.md
index ea75d07..3ddea35 100644
--- a/README.md
+++ b/README.md
@@ -181,6 +181,8 @@ Oxidized is a network device configuration backup tool. It's a RANCID replacemen
* [EtherHaul](lib/oxidized/model/siklu.rb)
* Supermicro
* [Supermicro](lib/oxidized/model/supermicro.rb)
+ * Symantec
+ * [Blue Coat ProxySG / Security Gateway OS (SGOS)](lib/oxidized/model/sgos.rb)
* Trango Systems
* [Trango](lib/oxidized/model/trango.rb)
* TPLink
@@ -1092,12 +1094,95 @@ The following objects exist in Oxidized.
* 'sql', 'csv' and 'http' (supports any format with single entry per line, like router.db)
## Model
- * lists commands to gather from given device model
- * can use 'cmd', 'prompt', 'comment', 'cfg'
- * cfg is executed in input/output/source context
- * cmd is executed in instance of model
- * 'junos', 'ios', 'ironware' and 'powerconnect' implemented
+### At the top level
+A model may use several methods at the top level in the class. `cfg` is
+executed in input/output/source context. `cmd` is executed within an instance
+of the model.
+#### `cfg`
+`cfg` may be called with a list of methods (`:ssh`, `:telnet`) and a block with
+zero parameters. Calling `cfg` registers the given access methods and calling
+it at least once is required for a model to work.
+
+The block may contain commands to change some behaviour for the given methods
+(e.g. calling `post_login` to disable the pager).
+
+#### `cmd`
+Is used to specify commands that should be executed on a model in order to
+gather its configuration. It can be called with:
+
+* Just a string
+* A string and a block
+* `:all` and a block
+* `:secret` and a block
+
+The block takes a single parameter `cfg` containing the output of the command
+being processed.
+
+Calling `cmd` with just a string will emit the output of the command given in
+that string as configuration.
+
+Calling `cmd` with a string and a block will pass the output of the given
+command to the block, then emit its return value (that must be a string) as
+configuration.
+
+Calling `cmd` with `:all` and a block will pass all command output through this
+block before emitting it. This is useful if some cleanup is required of the
+output of all commands.
+
+Calling `cmd` with `:secret` and a block will pass all configuration to the
+given block before emitting it to hide secrets if secret hiding is enabled. The
+block should replace any secrets with `'<hidden>'` and return the resulting
+string.
+
+Execution order is `:all`, `:secret`, and lastly the command specific block, if
+given.
+
+#### `comment`
+Called with a single string containing the string to prepend for comments in
+emitted configuration for this model.
+
+If not specified the default of `'# '` will be used (note the trailing space).
+
+#### `prompt`
+Is called with a regular expression that is used to detect when command output
+ends after a command has been executed.
+
+If not specified, a default of `/^([\w.@-]+[#>]\s?)$/` is used.
+
+#### `expect`
+Called with a regular expression and a block. The block takes two parameters:
+the regular expression, and the data containing the match.
+
+The passed data is replaced by the return value of the block.
+
+`expect` can be used to, for example, strip escape sequences from output before
+it's further processed.
+
+### At the second level
+The following methods are available:
+
+#### `comment`
+Used inside `cmd` invocations. Comments out every line in the passed string and
+returns the result.
+
+#### `password`
+Used inside `cfg` invocations to specify the regular expression used to detect
+the password prompt. If not specified, the default of `/^Password/` is used.
+
+#### `post_login`
+Used inside `cfg` invocations to specify commands to run once Oxidized has
+logged in to the switch. Takes one argument that is either a block (taking zero
+parameters) or a string containing a command to execute.
+
+#### `pre_logout`
+Used to specify commands to run before Oxidized closes the connection to the
+switch. Takes one argument that is either a block (taking zero parameters) or a
+string containing a command to execute.
+
+#### `send`
+Usually used inside `expect` or blocks passed to `post_login`/`pre_logout`.
+Takes a single parameter: a string to be sent to the switch.
# Help Needed
diff --git a/lib/oxidized/model/sgos.rb b/lib/oxidized/model/sgos.rb
new file mode 100644
index 0000000..3d42a53
--- /dev/null
+++ b/lib/oxidized/model/sgos.rb
@@ -0,0 +1,46 @@
+class SGOS < Oxidized::Model
+
+ comment '!- '
+ prompt /\w+>|#/
+
+ expect /--More--/ do |data, re|
+ send ' '
+ data.sub re, ''
+ end
+
+ cmd :all do |cfg|
+ cfg.each_line.to_a[1..-3].join
+ end
+
+ cmd 'show licenses' do |cfg|
+ comment cfg
+ end
+
+ cmd 'show general' do |cfg|
+ comment cfg
+ end
+
+ cmd :secret do |cfg|
+ cfg.gsub! /^(security hashed-enable-password).*/, '\\1 <secret hidden>'
+ cfg.gsub! /^(security hashed-password).*/, '\\1 <secret hidden>'
+ cfg
+ end
+
+ cmd 'show configuration expanded noprompts with-keyrings unencrypted' do |cfg|
+ cfg.gsub! /^(!- Local time).*/,""
+ cfg.gsub! /^(archive-configuration encrypted-password).*/, ""
+ cfg.gsub! /^(download encrypted-password).*/, ""
+ cfg
+ end
+
+ cfg :telnet, :ssh do
+ # preferred way to handle additional passwords
+ if vars :enable
+ post_login do
+ send "enable\n"
+ cmd vars(:enable)
+ end
+ end
+ pre_logout 'exit'
+ end
+end
diff --git a/lib/oxidized/node.rb b/lib/oxidized/node.rb
index 4f9ae54..2b15d4e 100644
--- a/lib/oxidized/node.rb
+++ b/lib/oxidized/node.rb
@@ -6,7 +6,7 @@ module Oxidized
class ModelNotFound < OxidizedError; end
class Node
attr_reader :name, :ip, :model, :input, :output, :group, :auth, :prompt, :vars, :last, :repo
- attr_accessor :running, :user, :msg, :from, :stats, :retry
+ attr_accessor :running, :user, :email, :msg, :from, :stats, :retry
alias :running? :running
def initialize opt
@@ -121,7 +121,7 @@ module Oxidized
end
def reset
- @user = @msg = @from = nil
+ @user = @email = @msg = @from = nil
@retry = 0
end
diff --git a/lib/oxidized/nodes.rb b/lib/oxidized/nodes.rb
index 6751c7a..3f84e15 100644
--- a/lib/oxidized/nodes.rb
+++ b/lib/oxidized/nodes.rb
@@ -68,6 +68,7 @@ module Oxidized
with_lock do
n = del node
n.user = opt['user']
+ n.email = opt['email']
n.msg = opt['msg']
n.from = opt['from']
# set last job to nil so that the node is picked for immediate update
diff --git a/lib/oxidized/worker.rb b/lib/oxidized/worker.rb
index dfe9803..4173680 100644
--- a/lib/oxidized/worker.rb
+++ b/lib/oxidized/worker.rb
@@ -52,7 +52,7 @@ module Oxidized
msg += " with message '#{node.msg}'" if node.msg
output = node.output.new
if output.store node.name, job.config,
- :msg => msg, :user => node.user, :group => node.group
+ :msg => msg, :email => node.email, :user => node.user, :group => node.group
Oxidized.logger.info "Configuration updated for #{node.group}/#{node.name}"
Oxidized.Hooks.handle :post_store, :node => node,
:job => job,