remote_syslog 1.4.2 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,22 +1,22 @@
1
1
  # remote_syslog Ruby daemon & sender
2
2
 
3
- Lightweight Ruby daemon to tail one or more log files and transmit UDP syslog
3
+ Lightweight Ruby daemon to tail one or more log files and transmit UDP syslog
4
4
  messages to a remote syslog host (centralized log aggregation).
5
5
 
6
- remote_syslog generates UDP packets itself instead of depending on a system
7
- syslog daemon, so its configuration doesn't affect system-wide
6
+ remote_syslog generates UDP packets itself instead of depending on a system
7
+ syslog daemon, so its configuration doesn't affect system-wide
8
8
  logging - syslog is just the transport.
9
9
 
10
10
  Uses:
11
11
 
12
12
  * collecting logs from servers & daemons which don't natively support syslog
13
- * when reconfiguring the system logger is less convenient than a
13
+ * when reconfiguring the system logger is less convenient than a
14
14
  purpose-built daemon (e.g., automated app deployments)
15
15
  * aggregating files not generated by daemons (e.g., package manager logs)
16
16
 
17
17
  The library can also be used to generate one-off log messages from Ruby code.
18
18
 
19
- Tested with the hosted log management service [Papertrail] and should work for
19
+ Tested with the hosted log management service [Papertrail] and should work for
20
20
  transmitting to any syslog server.
21
21
 
22
22
 
@@ -26,19 +26,19 @@ Install the gem, which includes a binary called "remote_syslog":
26
26
 
27
27
  $ [sudo] gem install remote_syslog
28
28
 
29
- Optionally, create a log_files.yml with the log file paths to read and the
30
- host/port to log to (see examples/[log_files.yml.example][sample config]). These can also be
29
+ Optionally, create a log_files.yml with the log file paths to read and the
30
+ host/port to log to (see examples/[log_files.yml.example][sample config]). These can also be
31
31
  specified as command-line arguments (below).
32
32
 
33
33
 
34
34
  ## Usage
35
35
 
36
36
  $ remote_syslog -h
37
- Usage: remote_syslog [options] <path to add'l log 1> .. <path to add'l log n>
37
+ Usage: remote_syslog [options] [<logfile>...]
38
38
 
39
39
  Example: remote_syslog -c configs/logs.yml -p 12345 /var/log/mysqld.log
40
40
 
41
- Options (default):
41
+ Options:
42
42
  -c, --configfile PATH Path to config (/etc/log_files.yml)
43
43
  -d, --dest-host HOSTNAME Destination syslog hostname or IP (logs.papertrailapp.com)
44
44
  -p, --dest-port PORT Destination syslog port (514)
@@ -52,7 +52,7 @@ specified as command-line arguments (below).
52
52
  --strip-color Strip color codes
53
53
  --tls Connect via TCP with TLS
54
54
  -h, --help Show this message
55
-
55
+
56
56
 
57
57
  ## Example
58
58
 
@@ -60,7 +60,7 @@ Typical:
60
60
 
61
61
  $ remote_syslog
62
62
 
63
- Daemonize and collect messages from files listed in `./config/logs.yml` as
63
+ Daemonize and collect messages from files listed in `./config/logs.yml` as
64
64
  well as the file `/var/log/mysqld.log`. Send to port `logs.papertrailapp.com:12345`:
65
65
 
66
66
  $ remote_syslog -c configs/logs.yml -p 12345 /var/log/mysqld.log
@@ -71,7 +71,7 @@ to `a.server.com:514`:
71
71
 
72
72
  $ remote_syslog -D -d a.server.com -f local0 -P /tmp /var/log/mysqld.log
73
73
 
74
- remote_syslog will daemonize by default. A sample init file is in the gem as
74
+ remote_syslog will daemonize by default. A sample init file is in the gem as
75
75
  [remote_syslog.init.d]. You may be able to:
76
76
 
77
77
  $ cp examples/remote_syslog.init.d /etc/init.d/remote_syslog
@@ -90,21 +90,25 @@ By default, the gem looks for a configuration in /etc/log_files.yml.
90
90
  The gem comes with a [sample config]. Optionally:
91
91
 
92
92
  $ cp examples/log_files.yml.example /etc/log_files.yml
93
-
94
- log_files.yml has filenames to log from (as an array) and hostname and port
95
- to log to (as a hash). Wildcards are supported using * and standard shell
96
- globbing. Filenames given on the command line are additive to those in
93
+
94
+ log_files.yml has filenames to log from (as an array) and hostname and port
95
+ to log to (as a hash). Wildcards are supported using * and standard shell
96
+ globbing. Filenames given on the command line are additive to those in
97
97
  the config file.
98
98
 
99
- Only 1 destination server is supported; the command-line argument wins.
99
+ Only 1 destination server is supported; the command-line argument wins.
100
100
 
101
- files: [/var/log/httpd/access_log, /var/log/httpd/error_log, /var/log/mysqld.log, /var/run/mysqld/mysqld-slow.log]
101
+ files:
102
+ - /var/log/httpd/access_log
103
+ - /var/log/httpd/error_log
104
+ - /var/log/mysqld.log
105
+ - /var/run/mysqld/mysqld-slow.log
102
106
  destination:
103
107
  host: logs.papertrailapp.com
104
108
  port: 12345
105
109
 
106
- remote_syslog sends the name of the file without a path ("mysqld.log") as
107
- the syslog tag (program name). RFCs 3164 and 5424 limit the tag to 32
110
+ remote_syslog sends the name of the file without a path ("mysqld.log") as
111
+ the syslog tag (program name). RFCs 3164 and 5424 limit the tag to 32
108
112
  characters. Longer filenames are truncated to 32 characters.
109
113
 
110
114
  ## Advanced Configuration (Optional)
@@ -117,9 +121,24 @@ Provide `--hostname somehostname` or use the `hostname` configuration option:
117
121
 
118
122
  hostname: somehostname
119
123
 
124
+ ### Verify server certificate
125
+
126
+ Provide the public key for the remote host when using TLS:
127
+
128
+ ssl_server_cert: syslog.crt
129
+
130
+
131
+ ### Use a client certificate
132
+
133
+ Provide a client certificate when connecting via TLS:
134
+
135
+ ssl_client_cert_chain: syslog_client.crt
136
+ ssl_client_private_key: syslog_client.key
137
+
138
+
120
139
  ### Multiple instances
121
140
 
122
- Run multiple instances to support more than one message-specific file format
141
+ Run multiple instances to support more than one message-specific file format
123
142
  or to specify unique syslog hostnames.
124
143
 
125
144
  To do that, provide an alternate PID filename as a command-line option
@@ -127,49 +146,50 @@ to the additional instance(s). For example:
127
146
 
128
147
  --pid-file remote_syslog_2.pid
129
148
 
149
+
130
150
  ### Parse fields from log messages
131
151
 
132
- Rarely needed. Usually only used when remote_syslog is watching files
152
+ Rarely needed. Usually only used when remote_syslog is watching files
133
153
  generated by syslogd (rather than by apps), like ``/var/log/messages``.
134
154
 
135
- remote_syslog can parse the program and hostname from the log line. When one
136
- file contains logs from multiple programs (like with syslog), the log line
137
- may include text that is not part of the log message, like a timestamp,
138
- hostname, or program name. remote_syslog will extract those and use them in
155
+ remote_syslog can parse the program and hostname from the log line. When one
156
+ file contains logs from multiple programs (like with syslog), the log line
157
+ may include text that is not part of the log message, like a timestamp,
158
+ hostname, or program name. remote_syslog will extract those and use them in
139
159
  the corresponding syslog packet fields.
140
160
 
141
- To do that, use the config file option `parse_fields` with the name of a
161
+ To do that, use the config file option `parse_fields` with the name of a
142
162
  format supported by remote_syslog, or your own regex. Included format names
143
163
  are `syslog` and `rfc3339`. For example:
144
164
 
145
165
  parse_fields: syslog
146
166
 
147
- The included `syslog` format uses the regex `(\w+ \d+ \S+) (\S+) ([^:]+): (.*)`
167
+ The included `syslog` format uses the regex `(\w+ \d+ \S+) (\S+) ([^:]+): (.*)`
148
168
  to parse standard syslog lines like this:
149
169
 
150
170
  Jul 18 08:25:08 hostname programname[1234]: The log message
151
171
 
152
- The included `rfc3339` format uses the regex `(\S+) (\S+) ([^: ]+):? (.*)` to
172
+ The included `rfc3339` format uses the regex `(\S+) (\S+) ([^: ]+):? (.*)` to
153
173
  parse syslog lines with high-precision RFC 3339 timestamps, like this:
154
174
 
155
175
  2011-07-16T08:25:08.651413-07:00 hostname programname[1234]: The log message
156
176
 
157
- To parse a format other than those, provide your own regex. It should include
158
- 4 backreferences to parse, in order: timestamp, system name, program name,
177
+ To parse a format other than those, provide your own regex. It should include
178
+ 4 backreferences to parse, in order: timestamp, system name, program name,
159
179
  message.
160
180
 
161
- Match and return empty strings for any empty positions where the log line
181
+ Match and return empty strings for any empty positions where the log line
162
182
  doesn't provide a value. For example, given the log message:
163
183
 
164
184
  something-meaningless The log message
165
185
 
166
186
  One could use a regex to ignore "something-meaningless" (and not to extract
167
- a program or hostname). To ignore that prefix and return 3 empty values
187
+ a program or hostname). To ignore that prefix and return 3 empty values
168
188
  then the log message, use parse_fields with this regex:
169
189
 
170
190
  parse_fields: "something-meaningless ()()()(.*)"
171
191
 
172
- Per-file regexes are not supported. Run multiple instances with different
192
+ Per-file regexes are not supported. Run multiple instances with different
173
193
  config files.
174
194
 
175
195
 
@@ -1,4 +1,9 @@
1
- files: [/var/log/httpd/access_log, /var/log/httpd/error_log, /opt/misc/*, /var/log/mysqld.log, /var/run/mysqld/mysqld-slow.log]
1
+ files:
2
+ - /var/log/httpd/access_log
3
+ - /var/log/httpd/error_log
4
+ - /opt/misc/*.log
5
+ - /var/log/mysqld.log
6
+ - /var/run/mysqld/mysqld-slow.log
2
7
  destination:
3
8
  host: logs.papertrailapp.com
4
9
  port: 12345 # optional, defaults to 514
data/lib/remote_syslog.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module RemoteSyslog
2
- VERSION = "1.4.2"
2
+ VERSION = "1.5.0"
3
3
  end
4
4
 
5
5
  require 'remote_syslog/reader'
@@ -45,11 +45,11 @@ module RemoteSyslog
45
45
 
46
46
  def parse
47
47
  op = OptionParser.new do |opts|
48
- opts.banner = "Usage: remote_syslog [options] <path to add'l log 1> .. <path to add'l log n>"
48
+ opts.banner = "Usage: remote_syslog [options] [<logfile>...]"
49
49
  opts.separator ''
50
50
  opts.separator "Example: remote_syslog -c configs/logs.yml -p 12345 /var/log/mysqld.log"
51
51
  opts.separator ''
52
- opts.separator "Options (default):"
52
+ opts.separator "Options:"
53
53
 
54
54
  opts.on("-c", "--configfile PATH", "Path to config (/etc/log_files.yml)") do |v|
55
55
  @configfile = File.expand_path(v)
@@ -117,9 +117,7 @@ module RemoteSyslog
117
117
 
118
118
  def parse_config
119
119
  if File.exist?(@configfile)
120
- config = open(@configfile) do |f|
121
- YAML.load(f)
122
- end
120
+ config = YAML.load_file(@configfile)
123
121
 
124
122
  @files += Array(config['files'])
125
123
 
@@ -135,6 +133,10 @@ module RemoteSyslog
135
133
  @hostname = config['hostname']
136
134
  end
137
135
 
136
+ @server_cert = config['ssl_server_cert']
137
+ @client_cert_chain = config['ssl_client_cert_chain']
138
+ @client_private_key = config['ssl_client_private_key']
139
+
138
140
  if config['parse_fields']
139
141
  @parse_fields = FIELD_REGEXES[config['parse_fields']] || Regexp.new(config['parse_fields'])
140
142
  end
@@ -142,6 +144,8 @@ module RemoteSyslog
142
144
  end
143
145
 
144
146
  def run
147
+ puts "Watching #{@files.length} files/paths. Sending to #{@dest_host}:#{@dest_port} (#{@tls ? 'TCP/TLS' : 'UDP'})."
148
+
145
149
  if @no_detach
146
150
  start
147
151
  else
@@ -152,10 +156,12 @@ module RemoteSyslog
152
156
  end
153
157
 
154
158
  def start
155
- puts "Watching #{@files.length} files/paths. Sending to #{@dest_host}:#{@dest_port} (#{@tls ? 'TCP/TLS' : 'UDP'})."
156
159
  EventMachine.run do
157
160
  if @tls
158
- connection = TlsEndpoint.new(@dest_host, @dest_port)
161
+ connection = TlsEndpoint.new(@dest_host, @dest_port,
162
+ :client_cert_chain => @client_cert_chain,
163
+ :client_private_key => @client_private_key,
164
+ :server_cert => @server_cert)
159
165
  else
160
166
  connection = UdpEndpoint.new(@dest_host, @dest_port)
161
167
  end
@@ -3,12 +3,22 @@ module RemoteSyslog
3
3
  class Handler < EventMachine::Connection
4
4
  def initialize(endpoint)
5
5
  @endpoint = endpoint
6
- @endpoint.connection = self
7
6
  super()
8
7
  end
9
8
 
10
9
  def connection_completed
11
- start_tls
10
+ start_tls(:verify_peer => @endpoint.server_cert != nil,
11
+ :cert_chain_file => @endpoint.client_cert_chain,
12
+ :private_key_file => @endpoint.client_private_key)
13
+ end
14
+
15
+ def ssl_verify_peer(peer_cert)
16
+ peer_cert = OpenSSL::X509::Certificate.new(peer_cert)
17
+ peer_cert.verify(@endpoint.server_cert.public_key)
18
+ end
19
+
20
+ def ssl_handshake_completed
21
+ @endpoint.connection = self
12
22
  end
13
23
 
14
24
  def unbind
@@ -17,10 +27,17 @@ module RemoteSyslog
17
27
  end
18
28
 
19
29
  attr_accessor :connection
30
+ attr_reader :server_cert, :client_cert_chain, :client_private_key
20
31
 
21
- def initialize(address, port)
22
- @address = address
23
- @port = port.to_i
32
+ def initialize(address, port, options = {})
33
+ @address = address
34
+ @port = port.to_i
35
+ @client_cert_chain = options[:client_cert_chain]
36
+ @client_private_key = options[:client_private_key]
37
+
38
+ if options[:server_cert]
39
+ @server_cert = OpenSSL::X509::Certificate.new(File.read(options[:server_cert]))
40
+ end
24
41
 
25
42
  # Try to resolve the address
26
43
  resolve_address
@@ -8,8 +8,8 @@ Gem::Specification.new do |s|
8
8
  ## If your rubyforge_project name is different, then edit it and comment out
9
9
  ## the sub! line in the Rakefile
10
10
  s.name = 'remote_syslog'
11
- s.version = '1.4.2'
12
- s.date = '2011-12-07'
11
+ s.version = '1.5.0'
12
+ s.date = '2011-12-30'
13
13
  s.rubyforge_project = 'remote_syslog'
14
14
 
15
15
  ## Make sure your summary is short. The description may be as long
metadata CHANGED
@@ -1,86 +1,99 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: remote_syslog
3
- version: !ruby/object:Gem::Version
4
- version: 1.4.2
5
- prerelease:
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 5
8
+ - 0
9
+ version: 1.5.0
6
10
  platform: ruby
7
- authors:
11
+ authors:
8
12
  - Troy Davis
9
13
  - Eric Lindvall
10
14
  autorequire:
11
15
  bindir: bin
12
16
  cert_chain: []
13
- date: 2011-12-07 00:00:00.000000000Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
17
+
18
+ date: 2011-12-30 00:00:00 -08:00
19
+ default_executable: remote_syslog
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
16
22
  name: daemons
17
- requirement: &70345349040060 !ruby/object:Gem::Requirement
18
- none: false
19
- requirements:
20
- - - ! '>='
21
- - !ruby/object:Gem::Version
22
- version: '0'
23
- type: :runtime
24
23
  prerelease: false
25
- version_requirements: *70345349040060
26
- - !ruby/object:Gem::Dependency
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
27
34
  name: eventmachine
28
- requirement: &70345349039500 !ruby/object:Gem::Requirement
29
- none: false
30
- requirements:
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ requirements:
31
38
  - - ~>
32
- - !ruby/object:Gem::Version
39
+ - !ruby/object:Gem::Version
40
+ segments:
41
+ - 0
42
+ - 12
43
+ - 10
33
44
  version: 0.12.10
34
45
  type: :runtime
35
- prerelease: false
36
- version_requirements: *70345349039500
37
- - !ruby/object:Gem::Dependency
46
+ version_requirements: *id002
47
+ - !ruby/object:Gem::Dependency
38
48
  name: eventmachine-tail
39
- requirement: &70345349055440 !ruby/object:Gem::Requirement
40
- none: false
41
- requirements:
42
- - - ! '>='
43
- - !ruby/object:Gem::Version
44
- version: '0'
45
- type: :runtime
46
49
  prerelease: false
47
- version_requirements: *70345349055440
48
- - !ruby/object:Gem::Dependency
50
+ requirement: &id003 !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ type: :runtime
58
+ version_requirements: *id003
59
+ - !ruby/object:Gem::Dependency
49
60
  name: syslog_protocol
50
- requirement: &70345349054880 !ruby/object:Gem::Requirement
51
- none: false
52
- requirements:
61
+ prerelease: false
62
+ requirement: &id004 !ruby/object:Gem::Requirement
63
+ requirements:
53
64
  - - ~>
54
- - !ruby/object:Gem::Version
65
+ - !ruby/object:Gem::Version
66
+ segments:
67
+ - 0
68
+ - 9
69
+ - 1
55
70
  version: 0.9.1
56
71
  type: :runtime
57
- prerelease: false
58
- version_requirements: *70345349054880
59
- - !ruby/object:Gem::Dependency
72
+ version_requirements: *id004
73
+ - !ruby/object:Gem::Dependency
60
74
  name: em-resolv-replace
61
- requirement: &70345349054460 !ruby/object:Gem::Requirement
62
- none: false
63
- requirements:
64
- - - ! '>='
65
- - !ruby/object:Gem::Version
66
- version: '0'
67
- type: :runtime
68
75
  prerelease: false
69
- version_requirements: *70345349054460
70
- description: Lightweight daemon to tail one or more log files and transmit UDP syslog
71
- messages to a remote syslog host (centralized log aggregation). Generates UDP packets
72
- itself instead of depending on a system syslog daemon, so it doesn't affect system-wide
73
- logging configuration.
74
- email:
76
+ requirement: &id005 !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ segments:
81
+ - 0
82
+ version: "0"
83
+ type: :runtime
84
+ version_requirements: *id005
85
+ description: Lightweight daemon to tail one or more log files and transmit UDP syslog messages to a remote syslog host (centralized log aggregation). Generates UDP packets itself instead of depending on a system syslog daemon, so it doesn't affect system-wide logging configuration.
86
+ email:
75
87
  - troy@sevenscale.com
76
88
  - eric@sevenscale.com
77
- executables:
89
+ executables:
78
90
  - remote_syslog
79
91
  extensions: []
80
- extra_rdoc_files:
92
+
93
+ extra_rdoc_files:
81
94
  - README.md
82
95
  - LICENSE
83
- files:
96
+ files:
84
97
  - Gemfile
85
98
  - LICENSE
86
99
  - README.md
@@ -96,30 +109,35 @@ files:
96
109
  - lib/remote_syslog/tls_endpoint.rb
97
110
  - lib/remote_syslog/udp_endpoint.rb
98
111
  - remote_syslog.gemspec
112
+ has_rdoc: true
99
113
  homepage: http://github.com/papertrail/remote_syslog
100
114
  licenses: []
115
+
101
116
  post_install_message:
102
- rdoc_options:
117
+ rdoc_options:
103
118
  - --charset=UTF-8
104
- require_paths:
119
+ require_paths:
105
120
  - lib
106
- required_ruby_version: !ruby/object:Gem::Requirement
107
- none: false
108
- requirements:
109
- - - ! '>='
110
- - !ruby/object:Gem::Version
111
- version: '0'
112
- required_rubygems_version: !ruby/object:Gem::Requirement
113
- none: false
114
- requirements:
115
- - - ! '>='
116
- - !ruby/object:Gem::Version
117
- version: '0'
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ segments:
126
+ - 0
127
+ version: "0"
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ segments:
133
+ - 0
134
+ version: "0"
118
135
  requirements: []
136
+
119
137
  rubyforge_project: remote_syslog
120
- rubygems_version: 1.8.7
138
+ rubygems_version: 1.3.6
121
139
  signing_key:
122
140
  specification_version: 2
123
- summary: Monitor plain text log file(s) for new entries and send to remote syslog
124
- collector
141
+ summary: Monitor plain text log file(s) for new entries and send to remote syslog collector
125
142
  test_files: []
143
+