summaryrefslogtreecommitdiff
path: root/extra
diff options
context:
space:
mode:
authorMrRJ45 <couton@gmail.com>2015-08-15 08:58:44 +0100
committerMrRJ45 <couton@gmail.com>2015-08-15 08:58:44 +0100
commitac39723feda302465090bf4994ea8c05893fba6c (patch)
treef2df371279baad442824c03539471aa6810f0d89 /extra
parent5f892762c05e425f8d4d0d8b36371ed0e9114ca2 (diff)
Update syslog.rb
Change syslog.rb to use oxidized config file for options. I have to make these changes with every update to meet our needs (and perhaps others). Not a big change, but it all appears to work fine for me :)
Diffstat (limited to 'extra')
-rw-r--r--extra/syslog.rb48
1 files changed, 38 insertions, 10 deletions
diff --git a/extra/syslog.rb b/extra/syslog.rb
index 2af83a0..f042744 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,26 +27,42 @@ 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:',
}
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
@@ -102,9 +126,13 @@ 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