Class: RemoteSyslog::Agent
- Inherits:
-
Servolux::Server
- Object
- Servolux::Server
- RemoteSyslog::Agent
- Defined in:
- lib/remote_syslog/agent.rb
Instance Attribute Summary collapse
-
#client_cert_chain ⇒ Object
TLS settings.
-
#client_private_key ⇒ Object
TLS settings.
-
#destination_host ⇒ Object
Who should we connect to?.
-
#destination_port ⇒ Object
Who should we connect to?.
-
#eventmachine_tail ⇒ Object
Should we use eventmachine to tail?.
-
#exclude_file_pattern ⇒ Object
Exclude files matching pattern.
-
#exclude_pattern ⇒ Object
Exclude messages matching pattern.
-
#facility ⇒ Object
syslog defaults.
-
#files ⇒ Object
Files (can be globs).
-
#glob_check_interval ⇒ Object
How often should we check for new files?.
-
#hostname ⇒ Object
syslog defaults.
-
#parse_fields ⇒ Object
Other settings.
-
#prepend ⇒ Object
Other settings.
-
#server_cert ⇒ Object
TLS settings.
-
#severity ⇒ Object
syslog defaults.
-
#strip_color ⇒ Object
Other settings.
-
#tcp ⇒ Object
Should use TCP?.
-
#tls ⇒ Object
Should use TLS?.
Instance Method Summary collapse
- #before_stopping ⇒ Object
- #endpoint_mode ⇒ Object
-
#initialize(options = {}) ⇒ Agent
constructor
A new instance of Agent.
- #log_file=(file) ⇒ Object
- #redirect_io! ⇒ Object
- #run ⇒ Object
- #watch_file(file) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Agent
Returns a new instance of Agent.
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/remote_syslog/agent.rb', line 47 def initialize( = {}) @files = [] @glob_check_interval = 10 @eventmachine_tail = .fetch(:eventmachine_tail, true) unless logger = [:logger] logger = Logger.new(STDERR) logger.level = Logger::ERROR end super('remote_syslog', :logger => logger, :pid_file => [:pid_file]) end |
Instance Attribute Details
#client_cert_chain ⇒ Object
TLS settings
24 25 26 |
# File 'lib/remote_syslog/agent.rb', line 24 def client_cert_chain @client_cert_chain end |
#client_private_key ⇒ Object
TLS settings
24 25 26 |
# File 'lib/remote_syslog/agent.rb', line 24 def client_private_key @client_private_key end |
#destination_host ⇒ Object
Who should we connect to?
15 16 17 |
# File 'lib/remote_syslog/agent.rb', line 15 def destination_host @destination_host end |
#destination_port ⇒ Object
Who should we connect to?
15 16 17 |
# File 'lib/remote_syslog/agent.rb', line 15 def destination_port @destination_port end |
#eventmachine_tail ⇒ Object
Should we use eventmachine to tail?
45 46 47 |
# File 'lib/remote_syslog/agent.rb', line 45 def eventmachine_tail @eventmachine_tail end |
#exclude_file_pattern ⇒ Object
Exclude files matching pattern
39 40 41 |
# File 'lib/remote_syslog/agent.rb', line 39 def exclude_file_pattern @exclude_file_pattern end |
#exclude_pattern ⇒ Object
Exclude messages matching pattern
33 34 35 |
# File 'lib/remote_syslog/agent.rb', line 33 def exclude_pattern @exclude_pattern end |
#facility ⇒ Object
syslog defaults
27 28 29 |
# File 'lib/remote_syslog/agent.rb', line 27 def facility @facility end |
#files ⇒ Object
Files (can be globs)
36 37 38 |
# File 'lib/remote_syslog/agent.rb', line 36 def files @files end |
#glob_check_interval ⇒ Object
How often should we check for new files?
42 43 44 |
# File 'lib/remote_syslog/agent.rb', line 42 def glob_check_interval @glob_check_interval end |
#hostname ⇒ Object
syslog defaults
27 28 29 |
# File 'lib/remote_syslog/agent.rb', line 27 def hostname @hostname end |
#parse_fields ⇒ Object
Other settings
30 31 32 |
# File 'lib/remote_syslog/agent.rb', line 30 def parse_fields @parse_fields end |
#prepend ⇒ Object
Other settings
30 31 32 |
# File 'lib/remote_syslog/agent.rb', line 30 def prepend @prepend end |
#server_cert ⇒ Object
TLS settings
24 25 26 |
# File 'lib/remote_syslog/agent.rb', line 24 def server_cert @server_cert end |
#severity ⇒ Object
syslog defaults
27 28 29 |
# File 'lib/remote_syslog/agent.rb', line 27 def severity @severity end |
#strip_color ⇒ Object
Other settings
30 31 32 |
# File 'lib/remote_syslog/agent.rb', line 30 def strip_color @strip_color end |
#tcp ⇒ Object
Should use TCP?
18 19 20 |
# File 'lib/remote_syslog/agent.rb', line 18 def tcp @tcp end |
#tls ⇒ Object
Should use TLS?
21 22 23 |
# File 'lib/remote_syslog/agent.rb', line 21 def tls @tls end |
Instance Method Details
#before_stopping ⇒ Object
140 141 142 |
# File 'lib/remote_syslog/agent.rb', line 140 def before_stopping EM.stop end |
#endpoint_mode ⇒ Object
130 131 132 133 134 135 136 137 138 |
# File 'lib/remote_syslog/agent.rb', line 130 def endpoint_mode @endpoint_mode ||= if @tls 'TCP/TLS' elsif @tcp 'TCP' else 'UDP' end end |
#log_file=(file) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/remote_syslog/agent.rb', line 60 def log_file=(file) @log_file = File.(file) level = self.logger.level self.logger = Logger.new(file) self.logger.level = level end |
#redirect_io! ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/remote_syslog/agent.rb', line 68 def redirect_io! if @log_file STDOUT.reopen(@log_file, 'a') STDERR.reopen(@log_file, 'a') STDERR.sync = STDOUT.sync = true end end |
#run ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/remote_syslog/agent.rb', line 92 def run EventMachine.run do EM.error_handler do |e| logger.error "Unhandled EventMachine Exception: #{e.class}: #{e.}:\n\t#{e.backtrace.join("\n\t")}" end if @tls = 10240 connection = TlsEndpoint.new(@destination_host, @destination_port, :client_cert_chain => @client_cert_chain, :client_private_key => @client_private_key, :server_cert => @server_cert, :logger => logger) elsif @tcp = 20480 connection = TcpEndpoint.new(@destination_host, @destination_port, :logger => logger) else = 1024 connection = UdpEndpoint.new(@destination_host, @destination_port, :logger => logger) end @message_generator = RemoteSyslog::MessageGenerator.new(connection, :facility => @facility, :severity => @severity, :strip_color => @strip_color, :hostname => @hostname, :parse_fields => @parse_fields, :exclude_pattern => @exclude_pattern, :prepend => @prepend, :max_message_size => ) files.each do |file| RemoteSyslog::GlobWatch.new(file, @glob_check_interval, @exclude_file_pattern, method(:watch_file)) end end end |
#watch_file(file) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/remote_syslog/agent.rb', line 80 def watch_file(file) if eventmachine_tail RemoteSyslog::EventMachineReader.new(file, :callback => @message_generator.method(:transmit), :logger => logger) else RemoteSyslog::FileTailReader.new(file, :callback => @message_generator.method(:transmit), :logger => logger) end end |