syslog-stream 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.ruby-version +1 -0
- data/.travis.yml +3 -0
- data/Gemfile +3 -0
- data/LICENSE +21 -0
- data/README.md +93 -0
- data/Rakefile +9 -0
- data/lib/syslog/stream.rb +19 -0
- data/lib/syslog/stream/octet_counting_framing.rb +26 -0
- data/lib/syslog/stream/version.rb +5 -0
- data/syslog-stream.gemspec +23 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 298186ea7270b64c496829f2ef4e28b49d40c9d1
|
4
|
+
data.tar.gz: c14d98d672f753afdef07dafa7258e863ee15666
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d9166c06f4b08ac73c277bc18d42ed72dc9e7d5f928a2d880dbb2b98f3ce58d80168d4232cb6f247ad3941b3e0dde41f67eab692993ccb20398f16bbaec64dce
|
7
|
+
data.tar.gz: 8a3cdf252b19a799b49405567ae00e40f098d72088e4e638ee89f4142b77f419bd08032c993a355dea8fb857c2214c3e10cd3702f7db632ee1897ea2e2c60358
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.2
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Calle Erlandsson
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
# Syslog::Stream
|
2
|
+
|
3
|
+
Parse streams of RFC5424 Syslog messages
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem "syslog-stream"
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
```sh
|
16
|
+
bundle
|
17
|
+
```
|
18
|
+
|
19
|
+
Or install it using gem(1):
|
20
|
+
|
21
|
+
```sh
|
22
|
+
gem install syslog-stream
|
23
|
+
```
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
`Syslog::Stream::OctetCountingFraming.new` should be able to accept any IO
|
28
|
+
object.
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
require "stringio"
|
32
|
+
require "syslog/stream"
|
33
|
+
|
34
|
+
io = StringIO.new(
|
35
|
+
'176 <165>1 2003-10-11T22:14:15.003Z mymachine.example.com evntslog - ID47 '\
|
36
|
+
'[exampleSDID@32473 iut="3" eventSource="Application" eventID="1011"] An '\
|
37
|
+
'application event log entry...181 <165>1 2003-10-11T22:14:16.003Z '\
|
38
|
+
'mymachine.example.com evntslog - ID48 [exampleSDID@32473 iut="3" '\
|
39
|
+
'eventSource="Application" eventID="1012"] Another application event log '\
|
40
|
+
'entry...',
|
41
|
+
)
|
42
|
+
|
43
|
+
stream = Syslog::Stream.new(Syslog::Stream::OctetCountingFraming.new(io))
|
44
|
+
|
45
|
+
stream.messages do |message|
|
46
|
+
# The values below are for the first yield to this block. This block will be
|
47
|
+
# yielded to, two times in total: Once for each messsage.
|
48
|
+
message.prival #=> 165
|
49
|
+
message.facility #=> 20
|
50
|
+
message.severity #=> 5
|
51
|
+
message.version #=> 1
|
52
|
+
message.timestamp #=> 2003-10-11 22:14:15 UTC
|
53
|
+
message.timestamp.class #=> Time
|
54
|
+
message.hostname #=> "mymachine.example.com"
|
55
|
+
message.app_name #=> "evntslog"
|
56
|
+
message.procid #=> nil
|
57
|
+
message.structured_data #=> [#<struct StructuredDataElement
|
58
|
+
# id="exampleSDID@32473"@71, params={"iut"=>"3", "eventSource"=>"Application",
|
59
|
+
# "eventID"=>"1011"}>]
|
60
|
+
message.msg #=> "An application event log entry..."
|
61
|
+
end
|
62
|
+
```
|
63
|
+
|
64
|
+
### Parsing streams received via Heroku HTTPS log drains
|
65
|
+
|
66
|
+
The cloud application platform [Heroku][heroku] allows it's users to register
|
67
|
+
log drains that receive Syslog formatted application log messages over HTTPS. As
|
68
|
+
outlined in [Heroku's documentation on HTTPS Log Drains][drains], these messages
|
69
|
+
do not fully conform to RFC5424:
|
70
|
+
|
71
|
+
> “application/logplex-1” does not conform to RFC5424. It leaves out
|
72
|
+
> STRUCTURED-DATA but does not replace it with a NILVALUE.
|
73
|
+
|
74
|
+
RFC5424 requires STRUCTURED-DATA to consist of either one NILVALUE or one or
|
75
|
+
more SD-ELEMENTs.
|
76
|
+
|
77
|
+
[heroku]: https://heroku.com
|
78
|
+
[drains]: https://devcenter.heroku.com/articles/log-drains#https-drains
|
79
|
+
|
80
|
+
In order to parse Syslog streams received via Heroku HTTPS log drains,
|
81
|
+
`Syslog::Stream` needs to be instantiated with a parser that allows missing
|
82
|
+
STRUCTURE-DATA:
|
83
|
+
|
84
|
+
```ruby
|
85
|
+
parser = Syslog::Parser.new(allow_missing_structured_data: true)
|
86
|
+
|
87
|
+
io = StringIO.new
|
88
|
+
|
89
|
+
stream = Syslog::Stream.new(
|
90
|
+
Syslog::Stream::OctetCountingFraming.new(io),
|
91
|
+
parser: parser,
|
92
|
+
)
|
93
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require "syslog/parser"
|
2
|
+
require "syslog/stream/octet_counting_framing"
|
3
|
+
|
4
|
+
module Syslog
|
5
|
+
class Stream
|
6
|
+
def initialize(framing, options={})
|
7
|
+
@framing = framing
|
8
|
+
@parser = options.fetch(:parser) { Syslog::Parser.new }
|
9
|
+
end
|
10
|
+
|
11
|
+
def messages
|
12
|
+
return to_enum(__callee__) unless block_given?
|
13
|
+
|
14
|
+
@framing.messages do |message|
|
15
|
+
yield @parser.parse(message)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Syslog
|
2
|
+
class Stream
|
3
|
+
class OctetCountingFraming
|
4
|
+
def initialize(io)
|
5
|
+
@io = io
|
6
|
+
end
|
7
|
+
|
8
|
+
def messages
|
9
|
+
loop do
|
10
|
+
length = ""
|
11
|
+
octet = ""
|
12
|
+
|
13
|
+
until octet == " " do
|
14
|
+
if @io.read(1, octet) == nil
|
15
|
+
return
|
16
|
+
end
|
17
|
+
|
18
|
+
length << octet
|
19
|
+
end
|
20
|
+
|
21
|
+
yield @io.read(Integer(length)).force_encoding("UTF-8")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "syslog/stream/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "syslog-stream"
|
7
|
+
spec.version = Syslog::Stream::VERSION
|
8
|
+
spec.authors = ["Calle Erlandsson"]
|
9
|
+
spec.email = ["calle@calleerlandsson.com"]
|
10
|
+
|
11
|
+
spec.summary = "Parse streams of RFC5424 Syslog messages"
|
12
|
+
spec.homepage = "https://github.com/calleerlandsson/syslog-stream/"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^test/}) }
|
16
|
+
spec.require_paths = ["lib"]
|
17
|
+
|
18
|
+
spec.add_dependency "syslog-parser"
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
spec.add_development_dependency "minitest"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: syslog-stream
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Calle Erlandsson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: syslog-parser
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.9'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.9'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- calle@calleerlandsson.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".ruby-version"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- lib/syslog/stream.rb
|
84
|
+
- lib/syslog/stream/octet_counting_framing.rb
|
85
|
+
- lib/syslog/stream/version.rb
|
86
|
+
- syslog-stream.gemspec
|
87
|
+
homepage: https://github.com/calleerlandsson/syslog-stream/
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.4.5
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: Parse streams of RFC5424 Syslog messages
|
111
|
+
test_files: []
|