diff options
author | ytti <saku@ytti.fi> | 2018-04-25 16:12:44 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-25 16:12:44 +0300 |
commit | 583bc422448a234a215113a15f8a6976c50b2296 (patch) | |
tree | b3f757e6f37aa058a0c80e4ded3ef82553bc98c1 /extra | |
parent | 9a7d16c00163c421d2c9f3cb2783c76633860336 (diff) | |
parent | dffae0f76656a57da8f5473ce21955638cbe1f7f (diff) |
Merge pull request #1296 from wk/the-great-makeover
the great makeover - standardize layout, alignment, indentation
Diffstat (limited to 'extra')
-rw-r--r-- | extra/rest_client.rb | 9 | ||||
-rwxr-xr-x | extra/syslog.rb | 32 |
2 files changed, 20 insertions, 21 deletions
diff --git a/extra/rest_client.rb b/extra/rest_client.rb index 35d93ae..dba89c3 100644 --- a/extra/rest_client.rb +++ b/extra/rest_client.rb @@ -6,10 +6,10 @@ module Oxidized require 'asetus' class Config - Root = Root = ENV['OXIDIZED_HOME'] || File.join(ENV['HOME'], '.config', 'oxidized') + Root = Root = ENV['OXIDIZED_HOME'] || File.join(ENV['HOME'], '.config', 'oxidized') end - CFGS = Asetus.new :name=>'oxidized', :load=>false, :key_to_s=>true + CFGS = Asetus.new :name => 'oxidized', :load => false, :key_to_s => true CFGS.default.rest = '127.0.0.1:8888' begin @@ -28,13 +28,13 @@ module Oxidized PATH = URI(restcfg).path class << self - def next opt={}, host=HOST, port=PORT + def next opt = {}, host = HOST, port = PORT web = new host, port web.next opt end end - def initialize host=HOST, port=PORT + def initialize host = HOST, port = PORT @web = Net::HTTP.new host, port end @@ -42,6 +42,5 @@ module Oxidized data = JSON.dump opt @web.put PATH + '/node/next/' + opt[:name].to_s, data end - end end diff --git a/extra/syslog.rb b/extra/syslog.rb index e364cf9..f7d271f 100755 --- a/extra/syslog.rb +++ b/extra/syslog.rb @@ -27,13 +27,12 @@ require 'resolv' require_relative 'rest_client' module Oxidized - require 'asetus' class Config - Root = File.join ENV['HOME'], '.config', 'oxidized' + Root = File.join ENV['HOME'], '.config', 'oxidized' end - CFGS = Asetus.new :name=>'oxidized', :load=>false, :key_to_s=>true + CFGS = Asetus.new :name => 'oxidized', :load => false, :key_to_s => true CFGS.default.syslogd.port = 514 CFGS.default.syslogd.file = 'messages' CFGS.default.syslogd.resolve = true @@ -43,7 +42,7 @@ module Oxidized rescue => error raise InvalidConfig, "Error loading config: #{error.message}" ensure - CFG = CFGS.cfg # convenienence, instead of Config.cfg.password, CFG.password + CFG = CFGS.cfg # convenienence, instead of Config.cfg.password, CFG.password end class SyslogMonitor @@ -59,12 +58,13 @@ module Oxidized } class << self - def udp port=Oxidized::CFG.syslogd.port, listen=0 + def udp port = Oxidized::CFG.syslogd.port, listen = 0 io = UDPSocket.new io.bind listen, port new io, :udp end - def file syslog_file=Oxidized::CFG.syslogd.file + + def file syslog_file = Oxidized::CFG.syslogd.file io = open syslog_file, 'r' io.seek 0, IO::SEEK_END new io, :file @@ -73,7 +73,7 @@ module Oxidized private - def initialize io, mode=:udp + def initialize io, mode = :udp @mode = mode run io end @@ -84,24 +84,24 @@ module Oxidized def ios ip, log, i # TODO: we need to fetch 'ip/name' in mode == :file here - user = log[i+5] + user = log[i + 5] from = log[-1][1..-2] - rest( :user => user, :from => from, :model => 'ios', :ip => ip, - :name => getname(ip) ) + rest(:user => user, :from => from, :model => 'ios', :ip => ip, + :name => getname(ip)) end def jnpr ip, log, i # TODO: we need to fetch 'ip/name' in mode == :file here - user = log[i+2][1..-2] - msg = log[(i+6)..-1].join(' ')[10..-2] + user = log[i + 2][1..-2] + msg = log[(i + 6)..-1].join(' ')[10..-2] msg = nil if msg == 'none' - rest( :user => user, :msg => msg, :model => 'jnpr', :ip => ip, - :name => getname(ip) ) + rest(:user => user, :msg => msg, :model => 'jnpr', :ip => ip, + :name => getname(ip)) end def handle_log log, ip log = log.to_s.split ' ' - if i = log.find_index { |e| e.match( MSG[:ios] ) } + if i = log.find_index { |e| e.match(MSG[:ios]) } ios ip, log, i elsif i = log.index(MSG[:junos]) jnpr ip, log, i @@ -140,4 +140,4 @@ module Oxidized end Oxidized::SyslogMonitor.udp -#Oxidized::SyslogMonitor.file '/var/log/poop' +# Oxidized::SyslogMonitor.file '/var/log/poop' |