summaryrefslogtreecommitdiff
path: root/extra/syslog.rb
diff options
context:
space:
mode:
Diffstat (limited to 'extra/syslog.rb')
-rw-r--r--extra/syslog.rb50
1 files changed, 39 insertions, 11 deletions
diff --git a/extra/syslog.rb b/extra/syslog.rb
index 20e439e..e364cf9 100644
--- a/extra/syslog.rb
+++ b/extra/syslog.rb
@@ -8,10 +8,18 @@
# set system syslog host SERVER interactive-commands notice
# set system syslog host SERVER match "^mgd\[[0-9]+\]: UI_COMMIT: .*"
-# Ports < 1024 need extra privileges, use a port higher than this by passing the first argument a number
-# To use the default port for syslog (514) you shouldnt pass an argument, but you will need to allow this with:
+# Ports < 1024 need extra privileges, use a port higher than this by setting the port option in your oxidized config file.
+# To use the default port for syslog (514) you shouldn't pass an argument, but you will need to allow this with:
# sudo setcap 'cap_net_bind_service=+ep' /usr/bin/ruby
+# Config options are:
+# syslogd
+# port (Default = 514)
+# file (Default = messages)
+# resolve (Default = true)
+
+# To stop the resolution of IP's to PTR you can set resolve to false
+
# exit if fork ## TODO: proper daemonize
require 'socket'
@@ -19,13 +27,30 @@ require 'resolv'
require_relative 'rest_client'
module Oxidized
+
+ require 'asetus'
+ class Config
+ Root = File.join ENV['HOME'], '.config', 'oxidized'
+ end
+
+ 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
+
+ begin
+ CFGS.load
+ rescue => error
+ raise InvalidConfig, "Error loading config: #{error.message}"
+ ensure
+ CFG = CFGS.cfg # convenienence, instead of Config.cfg.password, CFG.password
+ end
+
class SyslogMonitor
NAME_MAP = {
/(.*)\.ip\.tdc\.net/ => '\1',
/(.*)\.ip\.fi/ => '\1',
}
- PORT = 514
- FILE = 'messages'
MSG = {
:ios => /%SYS-(SW[0-9]+-)?5-CONFIG_I:/,
:junos => 'UI_COMMIT:',
@@ -34,13 +59,12 @@ module Oxidized
}
class << self
- def udp port=PORT, listen=0
- port ||= PORT
+ def udp port=Oxidized::CFG.syslogd.port, listen=0
io = UDPSocket.new
io.bind listen, port
new io, :udp
end
- def file syslog_file=FILE
+ def file syslog_file=Oxidized::CFG.syslogd.file
io = open syslog_file, 'r'
io.seek 0, IO::SEEK_END
new io, :file
@@ -104,12 +128,16 @@ module Oxidized
end
def getname ip
- name = (Resolv.getname ip.to_s rescue ip)
- NAME_MAP.each { |re, sub| name.sub! re, sub }
- name
+ if Oxidized::CFG.syslogd.resolve == false
+ ip
+ else
+ name = (Resolv.getname ip.to_s rescue ip)
+ NAME_MAP.each { |re, sub| name.sub! re, sub }
+ name
+ end
end
end
end
-Oxidized::SyslogMonitor.udp ARGV[0]
+Oxidized::SyslogMonitor.udp
#Oxidized::SyslogMonitor.file '/var/log/poop'