15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/fluent/plugin/filter_nais_kubewatch.rb', line 15
def filter(tag, time, record)
if record['source'].is_a?(Hash)
if record['source'].has_key?('host')
record['host'] = record['source']['host']
end
if record['source'].has_key?('component')
record['source'] = record['source']['component']
end
end
record['event'] = record.delete('reason') if record.has_key?('reason')
type = record.delete(@type_field)
if type == 'Normal'
record['level'] = 'Info'
elsif !type.nil?
record['level'] = type
end
if record.has_key?('involvedObject')
if (record['involvedObject']['fieldPath'] =~ /^spec.containers\{([^\}]+)\}$/ ||
record['involvedObject']['name'] =~ /^(.+?)(?:-[0-9a-f]{8,})?(?:-[0-9a-z]{5})?$/ ||
(record['involvedObject']['kind'] == 'ReplicaSet' && record['involvedObject']['name'] =~ /^(.+?)(?:-[0-9a-f]{8,})?$/) ||
(record['involvedObject']['kind'] =~ /(?:Deployment|DaemonSet)/ && record['involvedObject']['name'] =~ /^(.+)$/))
record['application'] = $1
record['namespace'] = record['involvedObject']['namespace']
if record['involvedObject']['kind'] == 'Pod'
record['pod'] = record['involvedObject']['name']
else
record.delete('pod')
end
record.delete('involvedObject')
record.delete('container')
end
if record.has_key?('involvedObject')
record['involvedObject'].delete('uid')
record['involvedObject'].delete('resourceVersion')
record['involvedObject'].delete('apiVersion')
end
end
record.delete('count')
record.delete('firstTimestamp')
record.delete('metadata')
timestamp = record.delete('lastTimestamp')
unless timestamp.nil?
record['@timestamp'] = Time.parse(timestamp).iso8601
end
record
end
|