diff options
author | Wild Kat <wk@users.noreply.github.com> | 2018-09-12 11:23:45 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-12 11:23:45 +0200 |
commit | 7c02a230dc970c2946770f6893e35c627b6b1ec0 (patch) | |
tree | d77395371f89aa8efe01d7fa8a194fb3bf9ed58c /lib | |
parent | 58c5310ae1406f1b6d7f1794d8574597c8698138 (diff) |
add a new line after guard clauses for better visual flow (#1520)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/oxidized/cli.rb | 2 | ||||
-rw-r--r-- | lib/oxidized/core.rb | 1 | ||||
-rw-r--r-- | lib/oxidized/hook/ciscosparkdiff.rb | 1 | ||||
-rw-r--r-- | lib/oxidized/hook/slackdiff.rb | 1 | ||||
-rw-r--r-- | lib/oxidized/hook/xmppdiff.rb | 1 | ||||
-rw-r--r-- | lib/oxidized/input/ssh.rb | 2 | ||||
-rw-r--r-- | lib/oxidized/input/telnet.rb | 1 | ||||
-rw-r--r-- | lib/oxidized/model/aireos.rb | 1 | ||||
-rw-r--r-- | lib/oxidized/model/aosw.rb | 2 | ||||
-rw-r--r-- | lib/oxidized/model/gcombnps.rb | 2 | ||||
-rw-r--r-- | lib/oxidized/model/model.rb | 3 | ||||
-rw-r--r-- | lib/oxidized/model/openwrt.rb | 1 | ||||
-rw-r--r-- | lib/oxidized/model/xos.rb | 1 | ||||
-rw-r--r-- | lib/oxidized/node.rb | 2 | ||||
-rw-r--r-- | lib/oxidized/nodes.rb | 3 | ||||
-rw-r--r-- | lib/oxidized/output/gitcrypt.rb | 1 | ||||
-rw-r--r-- | lib/oxidized/source/csv.rb | 2 | ||||
-rw-r--r-- | lib/oxidized/source/http.rb | 1 | ||||
-rw-r--r-- | lib/oxidized/worker.rb | 1 |
19 files changed, 29 insertions, 0 deletions
diff --git a/lib/oxidized/cli.rb b/lib/oxidized/cli.rb index 23cc28c..9fdc9b2 100644 --- a/lib/oxidized/cli.rb +++ b/lib/oxidized/cli.rb @@ -85,8 +85,10 @@ module Oxidized def pid_status(pidfile) return :exited unless File.exists?(pidfile) + pid = ::File.read(pidfile).to_i return :dead if pid == 0 + Process.kill(0, pid) :running rescue Errno::ESRCH diff --git a/lib/oxidized/core.rb b/lib/oxidized/core.rb index 440d8e2..62999fe 100644 --- a/lib/oxidized/core.rb +++ b/lib/oxidized/core.rb @@ -13,6 +13,7 @@ module Oxidized Oxidized.Hooks = HookManager.from_config(Oxidized.config) nodes = Nodes.new raise NoNodesFound, 'source returns no usable nodes' if nodes.size == 0 + @worker = Worker.new nodes trap('HUP') { nodes.load } if Oxidized.config.rest? diff --git a/lib/oxidized/hook/ciscosparkdiff.rb b/lib/oxidized/hook/ciscosparkdiff.rb index e45d7c6..fae2716 100644 --- a/lib/oxidized/hook/ciscosparkdiff.rb +++ b/lib/oxidized/hook/ciscosparkdiff.rb @@ -13,6 +13,7 @@ class CiscoSparkDiff < Oxidized::Hook 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 diff --git a/lib/oxidized/hook/slackdiff.rb b/lib/oxidized/hook/slackdiff.rb index baaf291..94e624c 100644 --- a/lib/oxidized/hook/slackdiff.rb +++ b/lib/oxidized/hook/slackdiff.rb @@ -12,6 +12,7 @@ class SlackDiff < Oxidized::Hook def run_hook(ctx) return unless ctx.node return unless ctx.event.to_s == "post_store" + log "Connecting to slack" Slack.configure do |config| config.token = cfg.token diff --git a/lib/oxidized/hook/xmppdiff.rb b/lib/oxidized/hook/xmppdiff.rb index 6acb172..3440b36 100644 --- a/lib/oxidized/hook/xmppdiff.rb +++ b/lib/oxidized/hook/xmppdiff.rb @@ -12,6 +12,7 @@ class XMPPDiff < Oxidized::Hook def run_hook(ctx) return unless ctx.node return unless ctx.event.to_s == "post_store" + begin Timeout.timeout(15) do gitoutput = ctx.node.output.new diff --git a/lib/oxidized/input/ssh.rb b/lib/oxidized/input/ssh.rb index 11b0ae6..a2e049c 100644 --- a/lib/oxidized/input/ssh.rb +++ b/lib/oxidized/input/ssh.rb @@ -85,6 +85,7 @@ module Oxidized end ch.request_pty (@pty_options) do |_ch, success_pty| raise NoShell, "Can't get PTY" unless success_pty + ch.send_channel_request 'shell' do |_ch, success_shell| raise NoShell, "Can't get shell" unless success_shell end @@ -112,6 +113,7 @@ module Oxidized sleep 0.1 match = regexps.find { |regexp| @output.match regexp } return match if match + true end end diff --git a/lib/oxidized/input/telnet.rb b/lib/oxidized/input/telnet.rb index 63d811f..17fad53 100644 --- a/lib/oxidized/input/telnet.rb +++ b/lib/oxidized/input/telnet.rb @@ -34,6 +34,7 @@ module Oxidized def cmd cmd_str, expect = @node.prompt return send(cmd_str + "\n") unless expect + Oxidized.logger.debug "Telnet: #{cmd_str} @#{@node.name}" args = { 'String' => cmd_str, 'Match' => expect, diff --git a/lib/oxidized/model/aireos.rb b/lib/oxidized/model/aireos.rb index 84bbb3f..e8e1f30 100644 --- a/lib/oxidized/model/aireos.rb +++ b/lib/oxidized/model/aireos.rb @@ -44,6 +44,7 @@ class Aireos < Oxidized::Model cfg.each_line do |line| next if line.match /^\s*$/ next if line.match /rogue (adhoc|client) (alert|Unknown) [\da-f]{2}:/ + line = line[1..-1] if line[0] == "\r" out << line.strip end diff --git a/lib/oxidized/model/aosw.rb b/lib/oxidized/model/aosw.rb index fae0eff..65559b3 100644 --- a/lib/oxidized/model/aosw.rb +++ b/lib/oxidized/model/aosw.rb @@ -63,6 +63,7 @@ class AOSW < Oxidized::Model cfg.each_line do |line| next if line.match /^controller config \d+$/ next if line.match /^Building Configuration/ + out << line.strip end out = out.join "\n" @@ -106,6 +107,7 @@ class AOSW < Oxidized::Model next if line.match /(Tachometers|Temperatures|Voltages)/ next if line.match /((Card|CPU) Temperature|Chassis Fan|VMON1[0-9])/ next if line.match /[0-9]+\s+(RPMS?|m?V|C)/i + out << line.strip end out = comment out.join "\n" diff --git a/lib/oxidized/model/gcombnps.rb b/lib/oxidized/model/gcombnps.rb index 0aa4a11..21929e3 100644 --- a/lib/oxidized/model/gcombnps.rb +++ b/lib/oxidized/model/gcombnps.rb @@ -42,6 +42,7 @@ class GcomBNPS < Oxidized::Model next if line.match /^ Bias Current\(mA\)/ next if line.match /^ RX Power\(dBM\)/ next if line.match /^ TX Power\(dBM\)/ + out << line end @@ -57,6 +58,7 @@ class GcomBNPS < Oxidized::Model cfg.each_line do |line| next if line.match /^system run time :/ next if line.match /^switch temperature :/ + out << line end diff --git a/lib/oxidized/model/model.rb b/lib/oxidized/model/model.rb index 761e19e..8bded03 100644 --- a/lib/oxidized/model/model.rb +++ b/lib/oxidized/model/model.rb @@ -17,6 +17,7 @@ module Oxidized def comment _comment = '# ' return @comment if @comment + @comment = block_given? ? yield : _comment end @@ -102,6 +103,7 @@ module Oxidized Oxidized.logger.debug "lib/oxidized/model/model.rb Executing #{string}" out = @input.cmd(string) return false unless out + out = out.b unless Oxidized.config.input.utf8_encoded? self.class.cmds[:all].each do |all_block| out = instance_exec Oxidized::String.new(out), string, &all_block @@ -155,6 +157,7 @@ module Oxidized self.class.cmds[:cmd].each do |command, block| out = cmd command, &block return false unless out + outputs << out end procs[:pre].each do |pre_proc| diff --git a/lib/oxidized/model/openwrt.rb b/lib/oxidized/model/openwrt.rb index 7ba9e98..ce7cf76 100644 --- a/lib/oxidized/model/openwrt.rb +++ b/lib/oxidized/model/openwrt.rb @@ -62,6 +62,7 @@ class OpenWrt < Oxidized::Model end @mtdpartitions.scan(/(\w+):\s+\w+\s+\w+\s+"(.*)"/).each do |partition, name| next unless vars(:openwrt_backup_partitions) && partitions_to_backup.include?(name) + Oxidized.logger.debug "Exporting partition - #{name}(#{partition})" cfg << comment("#### Partition: #{name} /dev/#{partition} #####") cfg << comment("Decode using 'echo -en <data> | gzip -dc > #{name}'") diff --git a/lib/oxidized/model/xos.rb b/lib/oxidized/model/xos.rb index a589d0b..e1ae37b 100644 --- a/lib/oxidized/model/xos.rb +++ b/lib/oxidized/model/xos.rb @@ -45,6 +45,7 @@ class XOS < Oxidized::Model data = cmd 'disable clipaging session' match = data.match /^disable clipaging session\n\*?[\w .-]+(:\d+)? # $/m next if match + cmd 'disable clipaging' end diff --git a/lib/oxidized/node.rb b/lib/oxidized/node.rb index 3775fa9..1d119e4 100644 --- a/lib/oxidized/node.rb +++ b/lib/oxidized/node.rb @@ -39,6 +39,7 @@ module Oxidized # don't try input if model is missing config block, we may need strong config to class_name map cfg_name = input.to_s.split('::').last.downcase next unless @model.cfg[cfg_name] and not @model.cfg[cfg_name].empty? + @model.input = input = input.new if config = run_input(input) Oxidized.logger.debug "lib/oxidized/node.rb: #{input.class.name} ran for #{name} successfully" @@ -229,6 +230,7 @@ module Oxidized def git_type opt type = opt[:output] || Oxidized.config.output.default return nil unless type[0..2] == "git" + type end end diff --git a/lib/oxidized/nodes.rb b/lib/oxidized/nodes.rb index 3e0869a..c0ade54 100644 --- a/lib/oxidized/nodes.rb +++ b/lib/oxidized/nodes.rb @@ -16,6 +16,7 @@ module Oxidized nodes.each do |node| # we want to load specific node(s), not all of them next unless node_want? node_want, node + begin _node = Node.new node new.push _node @@ -32,6 +33,7 @@ module Oxidized def node_want? node_want, node return true unless node_want + node_want_ip = (IPAddr.new(node_want) rescue false) name_is_ip = (IPAddr.new(node[:name]) rescue false) if name_is_ip and node_want_ip == node[:name] @@ -173,6 +175,7 @@ module Oxidized node = find { |n| n.name == node_name } output = node.output.new raise Oxidized::NotSupported unless output.respond_to? :fetch + yield node, output end end diff --git a/lib/oxidized/output/gitcrypt.rb b/lib/oxidized/output/gitcrypt.rb index 2da0179..41d351f 100644 --- a/lib/oxidized/output/gitcrypt.rb +++ b/lib/oxidized/output/gitcrypt.rb @@ -99,6 +99,7 @@ module Oxidized else File.read path end + lock repo rescue 'node not found' diff --git a/lib/oxidized/source/csv.rb b/lib/oxidized/source/csv.rb index 5b43352..c8654b2 100644 --- a/lib/oxidized/source/csv.rb +++ b/lib/oxidized/source/csv.rb @@ -22,8 +22,10 @@ module Oxidized nodes = [] open_file.each_line do |line| next if line.match(/^\s*#/) + data = line.chomp.split(@cfg.delimiter, -1) next if data.empty? + # map node parameters keys = {} @cfg.map.each do |key, position| diff --git a/lib/oxidized/source/http.rb b/lib/oxidized/source/http.rb index 26c9e05..0c3c7fd 100644 --- a/lib/oxidized/source/http.rb +++ b/lib/oxidized/source/http.rb @@ -21,6 +21,7 @@ module Oxidized data = string_navigate(data, @cfg.hosts_location) if @cfg.hosts_location? data.each do |node| next if node.empty? + # map node parameters keys = {} @cfg.map.each do |key, want_position| diff --git a/lib/oxidized/worker.rb b/lib/oxidized/worker.rb index 3fc1cee..dd9a3bf 100644 --- a/lib/oxidized/worker.rb +++ b/lib/oxidized/worker.rb @@ -28,6 +28,7 @@ module Oxidized # shift nodes and get the next node node = @nodes.get node.running? ? next : node.running = true + @jobs.push Job.new node Oxidized.logger.debug "lib/oxidized/worker.rb: Added #{node.group}/#{node.name} to the job queue" end |