fluent-plugin-gelf-best 1.2.0 → 1.3.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.
- checksums.yaml +4 -4
- data/lib/fluent/plugin/gelf_plugin_util.rb +47 -39
- data/lib/fluent-plugin-gelf-best/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3d0be1e13c195cc69d517d9678fd9ed15128700a203f6fcded95a8acf26ffa5
|
4
|
+
data.tar.gz: b5f48294ede888f480c827fcfeb635ae0769631c8e77b0329773927ca64a0aef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d0a6549e8a686fca58906ca27fd153e7e6d84cac711c59a7e0312f039ad591815567d08d55724d1a88c1d7ef3ae3acef214a652fae50aac09a3fc6145aae24d
|
7
|
+
data.tar.gz: 60bebae56b82025efa2f141be0842d1fe966d47d0d633fbe2e18bce7dbb7718635425150ae4bce2c69713b6a6b814efd6a63af508599ea16b293c2086d74c7dc
|
@@ -1,24 +1,39 @@
|
|
1
|
+
require 'oj'
|
2
|
+
require 'date'
|
3
|
+
require 'gelf'
|
4
|
+
|
1
5
|
module Fluent
|
2
6
|
module GelfPluginUtil
|
3
|
-
require 'gelf'
|
4
7
|
|
5
8
|
LEVEL_MAP = {
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
}
|
9
|
+
'0' => GELF::UNKNOWN, '1' => GELF::UNKNOWN, 'a' => GELF::UNKNOWN,
|
10
|
+
'2' => GELF::FATAL, 'c' => GELF::FATAL,
|
11
|
+
'3' => GELF::ERROR,
|
12
|
+
'4' => GELF::WARN, 'w' => GELF::WARN,
|
13
|
+
'5' => GELF::INFO, 'n' => GELF::INFO,
|
14
|
+
'6' => GELF::INFO, 'i' => GELF::INFO,
|
15
|
+
'7' => GELF::DEBUG, 'd' => GELF::DEBUG,
|
16
|
+
'e' => GELF::ERROR
|
17
|
+
}.freeze
|
18
|
+
|
19
|
+
def get_internal_json_out(record, key)
|
20
|
+
json_data = parse_json_field(record[key])
|
21
|
+
return record unless json_data
|
22
|
+
|
23
|
+
record.delete(key)
|
24
|
+
merge_record_with_json(record, json_data)
|
25
|
+
rescue Oj::ParseError, EncodingError
|
26
|
+
# Return original record if JSON parsing fails
|
27
|
+
record
|
28
|
+
end
|
15
29
|
|
16
30
|
def make_gelfentry(tag, time, record, conf = {})
|
17
|
-
|
18
|
-
|
31
|
+
record = get_internal_json_out(record, "message")
|
32
|
+
record = get_internal_json_out(record, "log")
|
33
|
+
gelfentry = {"_fluentd_tag" => tag, "timestamp" => calculate_timestamp(time)}
|
19
34
|
|
20
|
-
record.
|
21
|
-
|
35
|
+
record.each do |k, v|
|
36
|
+
process_record_entry(k, v, conf, gelfentry)
|
22
37
|
end
|
23
38
|
|
24
39
|
ensure_short_message(gelfentry)
|
@@ -27,6 +42,13 @@ module Fluent
|
|
27
42
|
|
28
43
|
private
|
29
44
|
|
45
|
+
def parse_json_field(json_field)
|
46
|
+
return nil unless json_field
|
47
|
+
json = Oj.load(json_field.strip)
|
48
|
+
return nil unless json.is_a?(Hash)
|
49
|
+
json
|
50
|
+
end
|
51
|
+
|
30
52
|
def calculate_timestamp(time)
|
31
53
|
if defined?(Fluent::EventTime) && time.is_a?(Fluent::EventTime)
|
32
54
|
time.sec + (time.nsec.to_f / 1_000_000_000).round(3)
|
@@ -38,43 +60,29 @@ module Fluent
|
|
38
60
|
def process_record_entry(k, v, conf, gelfentry)
|
39
61
|
case k
|
40
62
|
when 'host', 'hostname'
|
41
|
-
|
63
|
+
gelfentry['host'] = conf[:use_record_host] ? v : (gelfentry['_host'] = v)
|
42
64
|
when 'timestamp', 'time'
|
43
|
-
|
65
|
+
gelfentry['timestamp'] = parse_timestamp(v)
|
44
66
|
when 'level'
|
45
|
-
|
67
|
+
gelfentry['level'] = LEVEL_MAP[v.to_s.downcase[0]] || GELF::UNKNOWN
|
46
68
|
when 'msec'
|
47
|
-
conf[:add_msec_time] ?
|
69
|
+
gelfentry['timestamp'] = conf[:add_msec_time] ? "#{time.to_s}.#{v}".to_f : (gelfentry['_msec'] = v)
|
48
70
|
when 'short_message', 'version', 'full_message', 'facility', 'file', 'line'
|
49
|
-
|
71
|
+
gelfentry[k] = v
|
50
72
|
else
|
51
|
-
|
73
|
+
gelfentry[k.start_with?('_') ? k : "_#{k}"] = v
|
52
74
|
end
|
53
75
|
end
|
54
76
|
|
55
77
|
def parse_timestamp(v)
|
56
|
-
if v.is_a?(Integer) || v.is_a?(Float)
|
57
|
-
|
58
|
-
|
59
|
-
begin
|
60
|
-
(DateTime.parse(v).strftime("%Q").to_f / 1_000).round(3)
|
61
|
-
rescue ArgumentError
|
62
|
-
v
|
63
|
-
end
|
64
|
-
end
|
78
|
+
return v if v.is_a?(Integer) || v.is_a?(Float)
|
79
|
+
|
80
|
+
DateTime.parse(v).strftime("%Q").to_f / 1_000 rescue v
|
65
81
|
end
|
66
82
|
|
67
83
|
def ensure_short_message(gelfentry)
|
68
|
-
|
69
|
-
|
70
|
-
['_message', '_msg', '_log', '_record'].each do |key|
|
71
|
-
if gelfentry[key] && !gelfentry[key].to_s.strip.empty?
|
72
|
-
gelfentry['short_message'] = gelfentry.delete(key)
|
73
|
-
return
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
gelfentry['short_message'] = '(no message)' unless gelfentry['short_message']
|
84
|
+
default_key = ['_message', '_msg', '_log', '_record'].find { |key| gelfentry[key]&.strip&.empty? == false }
|
85
|
+
gelfentry['short_message'] = default_key ? gelfentry.delete(default_key) : '(no message)'
|
78
86
|
end
|
79
87
|
end
|
80
88
|
end
|