diff options
author | Neil Lathwood <neil@lathwood.co.uk> | 2018-04-27 11:38:06 +0100 |
---|---|---|
committer | Neil Lathwood <neil@lathwood.co.uk> | 2018-04-27 11:38:06 +0100 |
commit | b1194745929043b578c409f794ecb433aa515fa9 (patch) | |
tree | 133e7103073b707aaca855eb3df4d5025bebae06 /extra/syslog.rb | |
parent | 9156243b9debfc0bc2b05dfe98a910ce5153bf49 (diff) | |
parent | 34fd5369feee94ab45c5a81d7769b1df717e4c8c (diff) |
Rebased and fixed conflicts
Diffstat (limited to 'extra/syslog.rb')
-rwxr-xr-x | extra/syslog.rb | 32 |
1 files changed, 16 insertions, 16 deletions
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' |