fluent-plugin-gelf-best 1.1.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
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,91 +1,88 @@
|
|
1
|
-
|
1
|
+
require 'oj'
|
2
|
+
require 'date'
|
3
|
+
require 'gelf'
|
4
|
+
|
2
5
|
module Fluent
|
3
6
|
module GelfPluginUtil
|
4
7
|
|
5
|
-
|
8
|
+
LEVEL_MAP = {
|
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
|
6
18
|
|
7
|
-
def
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
29
|
+
|
30
|
+
def make_gelfentry(tag, time, record, conf = {})
|
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)}
|
34
|
+
|
35
|
+
record.each do |k, v|
|
36
|
+
process_record_entry(k, v, conf, gelfentry)
|
13
37
|
end
|
14
38
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
gelfentry['level'] = GELF::ERROR
|
34
|
-
when "4", "w" then
|
35
|
-
gelfentry['level'] = GELF::WARN
|
36
|
-
# gelf-rb also skips notice
|
37
|
-
when "5", "n" then
|
38
|
-
gelfentry['level'] = GELF::INFO
|
39
|
-
when "6", "i" then
|
40
|
-
gelfentry['level'] = GELF::INFO
|
41
|
-
when "7", "d" then
|
42
|
-
gelfentry['level'] = GELF::DEBUG
|
43
|
-
when "e" then
|
44
|
-
if v.to_s.length >= 2 and v.to_s.downcase[1] != "r" then
|
45
|
-
gelfentry['level'] = GELF::UNKNOWN
|
46
|
-
else
|
47
|
-
gelfentry['level'] = GELF::ERROR
|
48
|
-
end
|
49
|
-
else
|
50
|
-
gelfentry['_level'] = v
|
51
|
-
end
|
52
|
-
when 'msec' then
|
53
|
-
# msec must be three digits (leading/trailing zeroes)
|
54
|
-
if conf[:add_msec_time] then
|
55
|
-
gelfentry['timestamp'] = "#{time.to_s}.#{v}".to_f
|
56
|
-
else
|
57
|
-
gelfentry['_msec'] = v
|
58
|
-
end
|
59
|
-
when 'short_message', 'full_message', 'facility', 'line', 'file' then
|
60
|
-
gelfentry[k] = v
|
61
|
-
else
|
62
|
-
if !k.start_with?('_')
|
63
|
-
gelfentry['_'+k] = v
|
64
|
-
else
|
65
|
-
gelfentry[k] = v
|
66
|
-
end
|
67
|
-
end
|
39
|
+
ensure_short_message(gelfentry)
|
40
|
+
gelfentry.compact
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
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
|
+
|
52
|
+
def calculate_timestamp(time)
|
53
|
+
if defined?(Fluent::EventTime) && time.is_a?(Fluent::EventTime)
|
54
|
+
time.sec + (time.nsec.to_f / 1_000_000_000).round(3)
|
55
|
+
else
|
56
|
+
time
|
68
57
|
end
|
58
|
+
end
|
69
59
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
60
|
+
def process_record_entry(k, v, conf, gelfentry)
|
61
|
+
case k
|
62
|
+
when 'host', 'hostname'
|
63
|
+
gelfentry['host'] = conf[:use_record_host] ? v : (gelfentry['_host'] = v)
|
64
|
+
when 'timestamp', 'time'
|
65
|
+
gelfentry['timestamp'] = parse_timestamp(v)
|
66
|
+
when 'level'
|
67
|
+
gelfentry['level'] = LEVEL_MAP[v.to_s.downcase[0]] || GELF::UNKNOWN
|
68
|
+
when 'msec'
|
69
|
+
gelfentry['timestamp'] = conf[:add_msec_time] ? "#{time.to_s}.#{v}".to_f : (gelfentry['_msec'] = v)
|
70
|
+
when 'short_message', 'version', 'full_message', 'facility', 'file', 'line'
|
71
|
+
gelfentry[k] = v
|
72
|
+
else
|
73
|
+
gelfentry[k.start_with?('_') ? k : "_#{k}"] = v
|
84
74
|
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def parse_timestamp(v)
|
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
|
81
|
+
end
|
85
82
|
|
86
|
-
|
87
|
-
|
88
|
-
|
83
|
+
def ensure_short_message(gelfentry)
|
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)'
|
89
86
|
end
|
90
87
|
end
|
91
88
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-gelf-best
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Yamauchi
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2024-04-
|
13
|
+
date: 2024-04-18 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: fluentd
|