summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/oxidized/hook/ciscosparkdiff.rb49
-rw-r--r--lib/oxidized/input/ssh.rb5
-rw-r--r--lib/oxidized/model/xos.rb5
-rw-r--r--lib/oxidized/model/zynoscli.rb36
-rw-r--r--lib/oxidized/worker.rb6
5 files changed, 98 insertions, 3 deletions
diff --git a/lib/oxidized/hook/ciscosparkdiff.rb b/lib/oxidized/hook/ciscosparkdiff.rb
new file mode 100644
index 0000000..e45d7c6
--- /dev/null
+++ b/lib/oxidized/hook/ciscosparkdiff.rb
@@ -0,0 +1,49 @@
+require 'cisco_spark'
+
+# defaults to posting a diff, if messageformat is supplied them a message will be posted too
+# diffenable defaults to true
+# Modified from slackdiff
+
+class CiscoSparkDiff < Oxidized::Hook
+ def validate_cfg!
+ raise KeyError, 'hook.accesskey is required' unless cfg.has_key?('accesskey')
+ raise KeyError, 'hook.space is required' unless cfg.has_key?('space')
+ end
+
+ def run_hook(ctx)
+ return unless ctx.node
+ return unless ctx.event.to_s == "post_store"
+ log "Connecting to Cisco Spark"
+ CiscoSpark.configure do |config|
+ config.api_key = cfg.accesskey
+ config.proxy = cfg.proxy if cfg.has_key?('proxy')
+ end
+ space = cfg.space
+ client = CiscoSpark::Room.new(id: space)
+ client.fetch
+ log "Connected"
+ diffenable = true
+ if cfg.has_key?('diff') == true
+ if cfg.diff == false
+ diffenable = false
+ end
+ end
+ if diffenable == true
+ gitoutput = ctx.node.output.new
+ diff = gitoutput.get_diff ctx.node, ctx.node.group, ctx.commitref, nil
+ title = ctx.node.name.to_s
+ log "Posting diff as snippet to #{cfg.space}"
+ message = CiscoSpark::Message.new(text: 'Device ' + title + ' modified:' + "\n" + diff[:patch].lines.to_a[4..-1].join)
+ room = CiscoSpark::Room.new(id: space)
+ room.send_message(message)
+ end
+ if cfg.has_key?('message') == true
+ log cfg.message
+ 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 }
+ log msg
+ log "Posting message to #{cfg.space}"
+ client.chat_postMessage(channel: cfg.channel, text: msg, as_user: true)
+ end
+ log "Finished"
+ end
+end
diff --git a/lib/oxidized/input/ssh.rb b/lib/oxidized/input/ssh.rb
index dc1eb27..6e86d13 100644
--- a/lib/oxidized/input/ssh.rb
+++ b/lib/oxidized/input/ssh.rb
@@ -29,11 +29,14 @@ module Oxidized
port: port.to_i,
paranoid: secure,
keepalive: true,
- auth_methods: %w(none publickey password keyboard-interactive),
password: @node.auth[:password], :timeout => Oxidized.config.timeout,
number_of_password_prompts: 0,
}
+ auth_methods = vars(:auth_methods) || %w(none publickey password)
+ ssh_opts[:auth_methods] = auth_methods
+ Oxidized.logger.info "AUTH METHODS::#{auth_methods}"
+
if proxy_host = vars(:ssh_proxy)
proxy_command = "ssh "
proxy_command += "-o StrictHostKeyChecking=no " unless secure
diff --git a/lib/oxidized/model/xos.rb b/lib/oxidized/model/xos.rb
index e862596..5ce8017 100644
--- a/lib/oxidized/model/xos.rb
+++ b/lib/oxidized/model/xos.rb
@@ -26,7 +26,10 @@ class XOS < Oxidized::Model
comment cfg.each_line.reject { |line| line.match /Time:/ or line.match /boot/i }.join
end
- cmd 'show configuration'
+ cmd 'show configuration' do |cfg|
+ cfg = cfg.each_line.reject { |line| line.match /^#(\s[\w]+\s)(Configuration generated)/ }.join
+ cfg
+ end
cmd 'show policy detail' do |cfg|
comment cfg
diff --git a/lib/oxidized/model/zynoscli.rb b/lib/oxidized/model/zynoscli.rb
new file mode 100644
index 0000000..ae64b04
--- /dev/null
+++ b/lib/oxidized/model/zynoscli.rb
@@ -0,0 +1,36 @@
+class ZyNOSCLI < Oxidized::Model
+ # Used in Zyxel DSLAMs, such as SAM1316
+
+ # Typical prompt "XGS4600#"
+ prompt /^([\w.@()-]+[#>]\s\e7)$/
+ comment ';; '
+
+ cmd :all do |cfg|
+ cfg.gsub! /^.*\e7/, ''
+ end
+ cmd 'show stacking'
+
+ cmd 'show version'
+
+ cmd 'show running-config'
+
+ cfg :telnet do
+ username /^User name:/i
+ password /^Password:/i
+ end
+
+ cfg :telnet, :ssh do
+ if vars :enable
+ post_login do
+ send "enable\n"
+ # Interpret enable: true as meaning we won't be prompted for a password
+ unless vars(:enable).is_a? TrueClass
+ expect /[pP]assword:\s?$/
+ send vars(:enable) + "\n"
+ end
+ expect /^.+[#]$/
+ end
+ end
+ pre_logout 'exit'
+ end
+end
diff --git a/lib/oxidized/worker.rb b/lib/oxidized/worker.rb
index 7eaa888..692b060 100644
--- a/lib/oxidized/worker.rb
+++ b/lib/oxidized/worker.rb
@@ -80,7 +80,11 @@ module Oxidized
private
def is_cycle_finished?
- @jobs_done > 0 && @jobs_done % @nodes.count == 0
+ if @jobs_done > @nodes.count
+ true
+ else
+ @jobs_done > 0 && @jobs_done % @nodes.count == 0
+ end
end
def run_done_hook