summaryrefslogtreecommitdiff
path: root/extra
diff options
context:
space:
mode:
authorWild Kat <wk@users.noreply.github.com>2018-05-26 23:49:29 +0200
committerGitHub <noreply@github.com>2018-05-26 23:49:29 +0200
commit39dbb74c527c054007e26ad34c8921d4be6cb638 (patch)
treed55745153153450fb40e1f591eb861495a6068d9 /extra
parentdefdc69f92b3bcf62b1fd3b5ceac63a7a4e637ae (diff)
parent42bf10b7bce34ff577c469f6c2f659f3913cbf4a (diff)
Merge branch 'master' into FortiOS-Push
Diffstat (limited to 'extra')
-rw-r--r--extra/rest_client.rb9
-rwxr-xr-xextra/syslog.rb32
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'