fluent-plugin-gelf-best 1.3.0 → 1.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fluent/plugin/gelf_plugin_util.rb +38 -46
- 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: dc3a134e34dfdc0c22a93f90ca53b655bbb9133f787726adb478ffdb6b74bba3
|
4
|
+
data.tar.gz: f65ca691ac9b2e7046878b1b8b6315a21c6a3d575408ece21aff885c0f3c3add
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2adf1721b08d85f7a191d7121eb0a0190aee674f70159c828a475a4f717a90594307e116b1a88212d0095c9b546d48134c596e7fb186f6dba9cc0476905e616
|
7
|
+
data.tar.gz: 7bca600938707cda06ce79d798d11dd3dd3756ee7a0a3016b2770aa9a63d1133f0a7bcb745d8e14699d6503099cced2d6ff2a63b008731e8aa8a4fc3b6a652a4
|
@@ -1,39 +1,24 @@
|
|
1
|
-
require 'oj'
|
2
|
-
require 'date'
|
3
|
-
require 'gelf'
|
4
|
-
|
5
1
|
module Fluent
|
6
2
|
module GelfPluginUtil
|
3
|
+
require "gelf"
|
4
|
+
require "date"
|
7
5
|
|
8
6
|
LEVEL_MAP = {
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
7
|
+
"0" => GELF::UNKNOWN, "1" => GELF::UNKNOWN, "a" => GELF::UNKNOWN,
|
8
|
+
"2" => GELF::FATAL, "c" => GELF::FATAL,
|
9
|
+
"3" => GELF::ERROR,
|
10
|
+
"4" => GELF::WARN, "w" => GELF::WARN,
|
11
|
+
"5" => GELF::INFO, "n" => GELF::INFO,
|
12
|
+
"6" => GELF::INFO, "i" => GELF::INFO,
|
13
|
+
"7" => GELF::DEBUG, "d" => GELF::DEBUG,
|
14
|
+
"e" => GELF::ERROR # assuming 'e' stands typically for 'error'
|
17
15
|
}.freeze
|
18
16
|
|
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
17
|
def make_gelfentry(tag, time, record, conf = {})
|
31
|
-
|
32
|
-
record = get_internal_json_out(record, "log")
|
33
|
-
gelfentry = {"_fluentd_tag" => tag, "timestamp" => calculate_timestamp(time)}
|
18
|
+
gelfentry = {'_fluentd_tag' => tag, 'timestamp' => calculate_timestamp(time)}
|
34
19
|
|
35
|
-
record.
|
36
|
-
process_record_entry(k, v, conf, gelfentry)
|
20
|
+
record.each_pair do |k, v|
|
21
|
+
gelfentry.merge!(process_record_entry(k, v, conf, gelfentry))
|
37
22
|
end
|
38
23
|
|
39
24
|
ensure_short_message(gelfentry)
|
@@ -42,13 +27,6 @@ module Fluent
|
|
42
27
|
|
43
28
|
private
|
44
29
|
|
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
30
|
def calculate_timestamp(time)
|
53
31
|
if defined?(Fluent::EventTime) && time.is_a?(Fluent::EventTime)
|
54
32
|
time.sec + (time.nsec.to_f / 1_000_000_000).round(3)
|
@@ -60,29 +38,43 @@ module Fluent
|
|
60
38
|
def process_record_entry(k, v, conf, gelfentry)
|
61
39
|
case k
|
62
40
|
when 'host', 'hostname'
|
63
|
-
|
41
|
+
return {'host' => (conf[:use_record_host] ? v : gelfentry['_host'] = v)}
|
64
42
|
when 'timestamp', 'time'
|
65
|
-
|
43
|
+
{ 'timestamp' => parse_timestamp(v) }
|
66
44
|
when 'level'
|
67
|
-
|
45
|
+
{'level' => LEVEL_MAP[v.to_s.downcase[0]] || (v.to_s.length >= 2 && v.to_s.downcase[1] != "r" ? GELF::UNKNOWN : v)}
|
68
46
|
when 'msec'
|
69
|
-
|
47
|
+
conf[:add_msec_time] ? {'timestamp' => "#{time.to_s}.#{v}".to_f} : {'_msec' => v}
|
70
48
|
when 'short_message', 'version', 'full_message', 'facility', 'file', 'line'
|
71
|
-
|
49
|
+
{k => v}
|
72
50
|
else
|
73
|
-
|
51
|
+
{k.start_with?('_') ? k : "_#{k}" => v}
|
74
52
|
end
|
75
53
|
end
|
76
54
|
|
77
55
|
def parse_timestamp(v)
|
78
|
-
|
79
|
-
|
80
|
-
|
56
|
+
if v.is_a?(Integer) || v.is_a?(Float)
|
57
|
+
v
|
58
|
+
else
|
59
|
+
begin
|
60
|
+
(DateTime.parse(v).strftime("%Q").to_f / 1_000).round(3)
|
61
|
+
rescue ArgumentError
|
62
|
+
v
|
63
|
+
end
|
64
|
+
end
|
81
65
|
end
|
82
66
|
|
83
67
|
def ensure_short_message(gelfentry)
|
84
|
-
|
85
|
-
|
68
|
+
return if gelfentry['short_message'] && !gelfentry['short_message'].to_s.strip.empty?
|
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']
|
86
78
|
end
|
87
79
|
end
|
88
80
|
end
|