remote_syslog 1.2.1 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -41,14 +41,17 @@ specified as arguments to the remote_syslog daemon. More below.
41
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
+ -p, --dest-port PORT Destination syslog port (514)
44
45
  -D, --no-detach Don't daemonize and detach from the terminal
45
46
  -f, --facility FACILITY Facility (user)
46
- -p, --dest-port PORT Destination syslog port (514)
47
+ --hostname HOST Local hostname to send from
47
48
  -P, --pid-dir DIRECTORY Directory to write .pid file in (/var/run/)
49
+ --pid-file FILENAME PID filename (<program name>.pid)
50
+ --parse-syslog Parse file as syslog-formatted file
48
51
  -s, --severity SEVERITY Severity (notice)
52
+ --tls Connect via TCP with TLS
49
53
  --strip-color Strip color codes
50
54
  -h, --help Show this message
51
-
52
55
 
53
56
 
54
57
  ## Example
@@ -68,6 +71,13 @@ remote_syslog.init.d. You may be able to:
68
71
 
69
72
  $ cp examples/remote_syslog.init.d /etc/init.d/remote_syslog
70
73
 
74
+ ## Sending messages securely ##
75
+
76
+ If the receiving system supports sending syslog over TCP with TLS, you can
77
+ pass the `--tls` option when running `remote_syslog`:
78
+
79
+ $ remote_syslog --tls -p 1234 /var/log/mysqld.log
80
+
71
81
 
72
82
  ## Configuration
73
83
 
@@ -110,6 +120,10 @@ The `syslog` regex is `(\w+ \d+ \S+) (\S+) ([^:]+): (.*)`. It parses this:
110
120
 
111
121
  Jul 18 08:25:08 hostname programname[1234]: The log message
112
122
 
123
+ Or provide `parse_fields: rfc3339` to parse high-precision RFC 3339
124
+ timestamps like:
125
+ 2011-07-16T08:25:08.651413-07:00 hostname programname[1234]: The log message
126
+
113
127
  Or provide your own regex that includes these 4 backreferences, in order:
114
128
  timestamp, system name, program name, message. Match and return empty
115
129
  strings for any empty positions where the log value should be ignored.
data/lib/remote_syslog.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  module RemoteSyslog
2
- VERSION = "1.2.1"
2
+ VERSION = "1.3.0"
3
3
  end
4
4
 
5
5
  require 'remote_syslog/reader'
6
+ require 'remote_syslog/tls_endpoint'
7
+ require 'remote_syslog/udp_endpoint'
@@ -8,6 +8,7 @@ module RemoteSyslog
8
8
  class Cli
9
9
  FIELD_REGEXES = {
10
10
  'syslog' => /^(\w+ \d+ \S+) (\w+) ([^: ]+):? (.*)$/,
11
+ 'rfc3339' => /^(\S+) (\w+) ([^: ]+):? (.*)$/
11
12
  }
12
13
 
13
14
  def self.process!(argv)
@@ -81,6 +82,9 @@ module RemoteSyslog
81
82
  opts.on("-s", "--severity SEVERITY", "Severity (notice)") do |v|
82
83
  @severity = v
83
84
  end
85
+ opts.on("--tls", "Connect via TCP with TLS") do
86
+ @tls = true
87
+ end
84
88
  opts.on("--strip-color", "Strip color codes") do
85
89
  @strip_color = true
86
90
  end
@@ -149,16 +153,19 @@ module RemoteSyslog
149
153
 
150
154
  def start
151
155
  EventMachine.run do
152
- socket = EventMachine.open_datagram_socket('0.0.0.0', 0)
156
+ if @tls
157
+ connection = TlsEndpoint.new(@dest_host, @dest_port)
158
+ else
159
+ connection = UdpEndpoint.new(@dest_host, @dest_port)
160
+ end
153
161
 
154
162
  @files.each do |path|
155
163
  begin
156
164
  EventMachine::file_tail(path, RemoteSyslog::Reader,
157
165
  @dest_host, @dest_port,
158
- :socket => socket, :facility => @facility,
166
+ :socket => connection, :facility => @facility,
159
167
  :severity => @severity, :strip_color => @strip_color,
160
168
  :hostname => @hostname, :parse_fields => @parse_fields)
161
-
162
169
  rescue Errno::ENOENT => e
163
170
  puts "#{path} not found, continuing. (#{e.message})"
164
171
  end
@@ -11,13 +11,10 @@ module RemoteSyslog
11
11
  def initialize(path, destination_address, destination_port, options = {})
12
12
  super(path, -1)
13
13
 
14
- @destination_address = destination_address
15
- @destination_port = destination_port.to_i
16
-
17
14
  @parse_fields = options[:parse_fields]
18
15
  @strip_color = options[:strip_color]
19
16
 
20
- @socket = options[:socket] || EventMachine.open_datagram_socket('0.0.0.0', 0)
17
+ @socket = options[:socket] || UdpEndpoint.new(destination_address, destination_port)
21
18
 
22
19
  @buffer = BufferedTokenizer.new
23
20
 
@@ -37,21 +34,6 @@ module RemoteSyslog
37
34
  if @packet.tag.length > 32
38
35
  @packet.tag = @packet.tag[0..31]
39
36
  end
40
-
41
- # Try to resolve the destination address
42
- resolve_destination_address
43
-
44
- # Every 60 seconds we'll see if the address has changed
45
- EventMachine.add_periodic_timer(60) do
46
- resolve_destination_address
47
- end
48
- end
49
-
50
- def resolve_destination_address
51
- request = EventMachine::DnsResolver.resolve(@destination_address)
52
- request.callback do |addrs|
53
- @cached_destination_ip = addrs.first
54
- end
55
37
  end
56
38
 
57
39
  def receive_data(data)
@@ -60,10 +42,6 @@ module RemoteSyslog
60
42
  end
61
43
  end
62
44
 
63
- def destination_address
64
- @cached_destination_ip || @destination_address
65
- end
66
-
67
45
  def transmit(message)
68
46
  message = message.gsub(COLORED_REGEXP, '') if @strip_color
69
47
 
@@ -78,7 +56,7 @@ module RemoteSyslog
78
56
  end
79
57
  end
80
58
 
81
- @socket.send_datagram(packet.assemble, destination_address, @destination_port)
59
+ @socket.write(packet.assemble)
82
60
  end
83
61
  end
84
62
  end
@@ -0,0 +1,68 @@
1
+ module RemoteSyslog
2
+ class TlsEndpoint
3
+ class Handler < EventMachine::Connection
4
+ def initialize(endpoint)
5
+ @endpoint = endpoint
6
+ @endpoint.connection = self
7
+ super()
8
+ end
9
+
10
+ def connection_completed
11
+ start_tls
12
+ end
13
+
14
+ def unbind
15
+ @endpoint.unbind
16
+ end
17
+ end
18
+
19
+ attr_accessor :connection
20
+
21
+ def initialize(address, port)
22
+ @address = address
23
+ @port = port.to_i
24
+
25
+ # Try to resolve the address
26
+ resolve_address
27
+
28
+ # Every 60 seconds we'll see if the address has changed
29
+ EventMachine.add_periodic_timer(60) do
30
+ resolve_address
31
+ end
32
+
33
+ connect
34
+ end
35
+
36
+ def resolve_address
37
+ request = EventMachine::DnsResolver.resolve(@address)
38
+ request.callback do |addrs|
39
+ @cached_ip = addrs.first
40
+ end
41
+ end
42
+
43
+ def address
44
+ @cached_ip || @address
45
+ end
46
+
47
+ def connect
48
+ EventMachine.connect(address, @port, TlsEndpoint::Handler, self)
49
+ end
50
+
51
+ def unbind
52
+ @connection = nil
53
+ connect
54
+ end
55
+
56
+ def write(value)
57
+ if @connection
58
+ if @queue
59
+ @connection.send_data(@queue.join("\n") + "\n")
60
+ @queue = nil
61
+ end
62
+ @connection.send_data(value + "\n")
63
+ else
64
+ (@queue ||= []) << value
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,32 @@
1
+ module RemoteSyslog
2
+ class UdpEndpoint
3
+ def initialize(address, port)
4
+ @address = address
5
+ @port = port.to_i
6
+ @socket = EventMachine.open_datagram_socket('0.0.0.0', 0)
7
+
8
+ # Try to resolve the address
9
+ resolve_address
10
+
11
+ # Every 60 seconds we'll see if the address has changed
12
+ EventMachine.add_periodic_timer(60) do
13
+ resolve_address
14
+ end
15
+ end
16
+
17
+ def resolve_address
18
+ request = EventMachine::DnsResolver.resolve(@address)
19
+ request.callback do |addrs|
20
+ @cached_ip = addrs.first
21
+ end
22
+ end
23
+
24
+ def address
25
+ @cached_ip || @address
26
+ end
27
+
28
+ def write(value)
29
+ @socket.send_datagram(value, address, @port)
30
+ end
31
+ end
32
+ end
@@ -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.2.1'
12
- s.date = '2011-07-25'
11
+ s.version = '1.3.0'
12
+ s.date = '2011-07-29'
13
13
  s.rubyforge_project = 'remote_syslog'
14
14
 
15
15
  ## Make sure your summary is short. The description may be as long
@@ -67,6 +67,8 @@ Gem::Specification.new do |s|
67
67
  lib/remote_syslog.rb
68
68
  lib/remote_syslog/cli.rb
69
69
  lib/remote_syslog/reader.rb
70
+ lib/remote_syslog/tls_endpoint.rb
71
+ lib/remote_syslog/udp_endpoint.rb
70
72
  remote_syslog.gemspec
71
73
  ]
72
74
  # = MANIFEST =
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
- - 2
8
- - 1
9
- version: 1.2.1
7
+ - 3
8
+ - 0
9
+ version: 1.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Troy Davis
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-25 00:00:00 -07:00
18
+ date: 2011-07-29 00:00:00 -07:00
19
19
  default_executable: remote_syslog
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -104,6 +104,8 @@ files:
104
104
  - lib/remote_syslog.rb
105
105
  - lib/remote_syslog/cli.rb
106
106
  - lib/remote_syslog/reader.rb
107
+ - lib/remote_syslog/tls_endpoint.rb
108
+ - lib/remote_syslog/udp_endpoint.rb
107
109
  - remote_syslog.gemspec
108
110
  has_rdoc: true
109
111
  homepage: http://github.com/papertrail/remote_syslog