fluent-plugin-journal-parser 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ba092ee44c8e2e040c85699cb4f81a21c1d443b6
4
+ data.tar.gz: 980551f8ae8333b7d177df9c42a2131a48e40dab
5
+ SHA512:
6
+ metadata.gz: 6180aaf1c780caa6c2e739ef4469906c17ea936a963eb84e66a27b6f4e2d0b6d838bc3342f1e71a683eb15e8f84be7be6fb411880fd8c42a1d5b338b9dc0e2ad
7
+ data.tar.gz: fb9ed299cf0d6ed9bc39caef5d3d5d7fff9b2c6a3e67a52bba3bf7c2606e32cfe369c3a5aefba9af19dbfab9d8db98847cfa1474d8d9b18abc4ea31715d621ac
@@ -0,0 +1,105 @@
1
+ # fluent-plugin-journal-parser
2
+ # Copyright 2016 One.com
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ begin # fluentd >= 0.14
17
+ require 'fluent/plugin/parser'
18
+
19
+ module Fluent
20
+ module Plugin
21
+ class JournalParser < Parser
22
+ Plugin.register_parser('journal', self)
23
+
24
+ def parse(text)
25
+ ret = []
26
+ length = text.length
27
+ n = 0
28
+ while n < length
29
+ record = {}
30
+ while (m = text.index(/[=\n]/, n)) != n
31
+ raise ParserError if m.nil?
32
+ key = text.slice(n, m-n)
33
+ n = m+1 # continue parsing after newline/equal sign
34
+ if text[m] == '=' # simple field
35
+ m = text.index("\n", n)
36
+ value = text.slice(n, m-n)
37
+ else # text[m] == "\n" # binary safe field
38
+ m = text.slice(n, 8).unpack('Q<')[0]
39
+ n += 8
40
+ value = text.slice(n, m)
41
+ m = n+m
42
+ end
43
+ record[key] = value
44
+ n = m+1 # continue parsing after ending newline
45
+ end
46
+ # set timestamp from __REALTIME_TIMESTAMP field
47
+ ns = record['__REALTIME_TIMESTAMP']
48
+ if ns
49
+ ns = ns.to_i
50
+ record['time'] = EventTime.new(ns / 1000000, ns % 1000000)
51
+ end
52
+ ret.push(record)
53
+ n = m+1 # continue parsing after empty line
54
+ end
55
+ yield nil, ret
56
+ end
57
+
58
+ end
59
+ end
60
+ end
61
+ rescue LoadError # fluentd < 0.14
62
+ require 'fluent/parser'
63
+
64
+ module Fluent
65
+ class JournalParser < Parser
66
+ Fluent::Plugin.register_parser('journal', self)
67
+
68
+ def parse(text)
69
+ ret = []
70
+ length = text.length
71
+ n = 0
72
+ while n < length
73
+ record = {}
74
+ while (m = text.index(/[=\n]/, n)) != n
75
+ raise ParserError if m.nil?
76
+ key = text.slice(n, m-n)
77
+ n = m+1 # continue parsing after newline/equal sign
78
+ if text[m] == '=' # simple field
79
+ m = text.index("\n", n)
80
+ value = text.slice(n, m-n)
81
+ else # text[m] == "\n" # binary safe field
82
+ m = text.slice(n, 8).unpack('Q<')[0]
83
+ n += 8
84
+ value = text.slice(n, m)
85
+ m = n+m
86
+ end
87
+ record[key] = value
88
+ n = m+1 # continue parsing after ending newline
89
+ end
90
+ # set timestamp from __REALTIME_TIMESTAMP field
91
+ ns = record['__REALTIME_TIMESTAMP']
92
+ if ns
93
+ record['time'] = ns.to_i / 1000000
94
+ end
95
+ ret.push(record)
96
+ n = m+1 # continue parsing after empty line
97
+ end
98
+ yield nil, ret
99
+ end
100
+
101
+ end
102
+ end
103
+ end
104
+
105
+ # vim: set ts=2 sw=2 et:
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-journal-parser
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Emil Renner Berthing
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fluentd
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.12'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.12'
27
+ description:
28
+ email:
29
+ - erb@one.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - lib/fluent/plugin/parser_journal.rb
35
+ homepage: https://github.com/One-com/fluent-plugin-journal-parser
36
+ licenses:
37
+ - Apache-2.0
38
+ metadata: {}
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubyforge_project:
55
+ rubygems_version: 2.5.1
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: Fluentd plugin to parse systemd journal export format.
59
+ test_files: []