diff options
Diffstat (limited to 'extra')
-rw-r--r-- | extra/oxidized.supervisord | 10 | ||||
-rw-r--r-- | extra/oxidized.upstart | 18 | ||||
-rw-r--r-- | extra/syslog.rb | 17 |
3 files changed, 38 insertions, 7 deletions
diff --git a/extra/oxidized.supervisord b/extra/oxidized.supervisord new file mode 100644 index 0000000..3bef7fa --- /dev/null +++ b/extra/oxidized.supervisord @@ -0,0 +1,10 @@ +# by @MrRJ45 at issues #45 + +[program:oxidized] +command=/usr/local/bin/oxidized +autostart=true +autorestart=true +user=oxidized +stderr_logfile=/var/log/oxidized.err.log +stdout_logfile=/var/log/oxidized.out.log +environment=HOME='/home/oxidized/' diff --git a/extra/oxidized.upstart b/extra/oxidized.upstart new file mode 100644 index 0000000..26a0f83 --- /dev/null +++ b/extra/oxidized.upstart @@ -0,0 +1,18 @@ +# by @andrewpwade in issue #45 + +start on started networking + +respawn + +setuid oxidized +setgid oxidized + +chdir /home/oxidized + +env HOME=/home/oxidized + +pre-start script + test -x /usr/local/bin/oxidized || { stop; exit 0; } +end script + +exec /usr/local/bin/oxidized 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' |