From ac39723feda302465090bf4994ea8c05893fba6c Mon Sep 17 00:00:00 2001 From: MrRJ45 Date: Sat, 15 Aug 2015 08:58:44 +0100 Subject: 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 :) --- extra/syslog.rb | 48 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 10 deletions(-) (limited to 'extra') 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 -- cgit v1.2.1