Class: SyslogServer

Inherits:
Object
  • Object
show all
Defined in:
lib/monitor/server/syslog/syslog_server.rb

Instance Method Summary collapse

Constructor Details

#initialize(buff) ⇒ SyslogServer

Returns a new instance of SyslogServer.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/monitor/server/syslog/syslog_server.rb', line 3

def initialize(buff)
  require 'socket'
  @port = $config.syslog_port
  @buff=buff
  Socket.do_not_reverse_lookup = true
  @server = UDPSocket.open
  begin
    $log.info("Syslog Server: listening on udp port #{@port}")
    @server.bind("", @port)
  rescue Errno::EADDRINUSE => msg
    $log.fatal("Syslog Server: #{msg}, socket in use")
    raise Errno::EADDRINUSE
  rescue Errno::EACCES => msg
    $log.fatal("Syslog Server: #{msg}, need root perms")
    raise Errno::EACCES
  rescue Exception => msg
    raise msg
  end

  @listener = Thread.start do
    while $config.syslog_mon
      begin
        msg = @server.recvfrom(1024)
        #extract peer info: domain, port, name, and IP address
        @buff.put Time.new.to_s()+'|'+"#{msg[1][3]}#{msg[0]}"
        Thread.pass if @buff.full?
      rescue Exception => msg
        #catch when stream is closed by close() method
      end
    end
  end
end

Instance Method Details

#close_socketObject



36
37
38
# File 'lib/monitor/server/syslog/syslog_server.rb', line 36

def close_socket()
  @server.close unless @server == nil
end

#get_threadObject



40
41
42
# File 'lib/monitor/server/syslog/syslog_server.rb', line 40

def get_thread
  @listener
end