diff options
Diffstat (limited to 'extra/syslog.rb')
-rw-r--r-- | extra/syslog.rb | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/extra/syslog.rb b/extra/syslog.rb index 7671d22..2af83a0 100644 --- a/extra/syslog.rb +++ b/extra/syslog.rb @@ -1,20 +1,22 @@ #!/usr/bin/env ruby # IOS: -# logging discriminator CFG mnemonics includes CONFIG_I +# logging discriminator CFG mnemonics includes CONFIG_I # logging host SERVER discriminator CFG # JunOS: # 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: # sudo setcap 'cap_net_bind_service=+ep' /usr/bin/ruby # exit if fork ## TODO: proper daemonize require 'socket' require 'resolv' -require './rest_client' +require_relative 'rest_client' module Oxidized class SyslogMonitor @@ -25,12 +27,13 @@ module Oxidized PORT = 514 FILE = 'messages' MSG = { - :ios => '%SYS-5-CONFIG_I:', + :ios => /%SYS-(SW[0-9]+-)?5-CONFIG_I:/, :junos => 'UI_COMMIT:', } class << self def udp port=PORT, listen=0 + port ||= PORT io = UDPSocket.new io.bind listen, port new io, :udp @@ -42,7 +45,7 @@ module Oxidized end end - private + private def initialize io, mode=:udp @mode = mode @@ -72,7 +75,7 @@ module Oxidized def handle_log log, ip log = log.to_s.split ' ' - if i = log.index(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 @@ -86,7 +89,7 @@ module Oxidized if @mode == :udp log, ip = log.recvfrom_nonblock 2000 ip = ip.last - else + else begin log = log.read_nonblock 2000 rescue EOFError @@ -106,5 +109,5 @@ module Oxidized end end -Oxidized::SyslogMonitor.udp +Oxidized::SyslogMonitor.udp ARGV[0] #Oxidized::SyslogMonitor.file '/var/log/poop' |