forked from rancher/rancher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
templatematch.go
225 lines (215 loc) · 5.86 KB
/
templatematch.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
package generator
var MatchTemplate = `
{{define "match"}}
<match {{ .ContainerLogSourceTag}}.** {{ .CustomLogSourceTag}}.** {{ if .IncludeRke }}{{ .RkeLogTag }}.**{{end}}>
@type copy
{{- template "store-target" . -}}
{{- template "store-prometheus" . -}}
</match>
{{end}}
{{define "store-target"}}
<store>
{{- template "elasticsearch" . -}}
{{- template "splunk" . -}}
{{- template "kafka" . -}}
{{- template "syslog" . -}}
{{- template "fluentforwarder" . -}}
{{- template "custom" . -}}
{{- template "buffer" . -}}
</store>
{{end}}
{{define "store-prometheus"}}
<store>
@type prometheus
<metric>
name fluentd_output_status_num_records_total
type counter
desc The total number of outgoing records
<labels>
tag ${tag}
hostname ${hostname}
</labels>
</metric>
</store>
{{end}}
{{define "elasticsearch"}}
{{ if eq .CurrentTarget "elasticsearch" }}
@type elasticsearch
include_tag_key true
{{- if and .ElasticsearchConfig.AuthUserName .ElasticsearchConfig.AuthPassword}}
user {{.ElasticsearchConfig.AuthUserName}}
password {{.ElasticsearchConfig.AuthPassword}}
{{- end }}
hosts {{.ElasticsearchConfig.Endpoint}}
logstash_prefix "{{.ElasticsearchConfig.IndexPrefix}}"
logstash_format true
logstash_dateformat {{.ElasticsearchTemplateWrap.DateFormat}}
type_name "container_log"
{{- if eq .ElasticsearchTemplateWrap.Scheme "https"}}
ssl_verify {{.ElasticsearchConfig.SSLVerify}}
ssl_version {{ .ElasticsearchConfig.SSLVersion }}
{{- if .ElasticsearchConfig.Certificate }}
ca_file {{.CertFilePrefix}}_ca.pem
{{end}}
{{- if and .ElasticsearchConfig.ClientCert .ElasticsearchConfig.ClientKey}}
client_cert {{.CertFilePrefix}}_client-cert.pem
client_key {{.CertFilePrefix}}_client-key.pem
{{end}}
{{- if .ElasticsearchConfig.ClientKeyPass}}
client_key_pass {{.ElasticsearchConfig.ClientKeyPass}}
{{end}}
{{end}}
{{end}}
{{end}}
{{define "splunk"}}
{{- if eq .CurrentTarget "splunk"}}
@type splunk_hec
host {{.SplunkTemplateWrap.Host}}
port {{.SplunkTemplateWrap.Port}}
token {{.SplunkConfig.Token}}
{{- if .SplunkConfig.Source}}
sourcetype {{.SplunkConfig.Source}}
{{end}}
{{- if .SplunkConfig.Index}}
default_index {{ .SplunkConfig.Index }}
{{end}}
{{- if eq .SplunkTemplateWrap.Scheme "https"}}
use_ssl true
ssl_verify {{.SplunkConfig.SSLVerify}}
{{- if .SplunkConfig.Certificate }}
ca_file {{.CertFilePrefix}}_ca.pem
{{end}}
{{- if and .SplunkConfig.ClientCert .SplunkConfig.ClientKey}}
client_cert {{.CertFilePrefix}}_client-cert.pem
client_key {{.CertFilePrefix}}_client-key.pem
{{end}}
{{- if .SplunkConfig.ClientKeyPass}}
client_key_pass {{ .SplunkConfig.ClientKeyPass }}
{{end}}
{{end}}
{{end}}
{{end}}
{{define "kafka"}}
{{- if eq .CurrentTarget "kafka"}}
@type kafka_buffered
{{- if .KafkaConfig.ZookeeperEndpoint }}
zookeeper {{.KafkaTemplateWrap.Zookeeper}}
{{else}}
brokers {{.KafkaTemplateWrap.Brokers}}
{{end}}
default_topic {{.KafkaConfig.Topic}}
output_data_type "json"
output_include_tag true
output_include_time true
max_send_retries 3
{{- if .KafkaConfig.Certificate }}
ssl_ca_cert {{.CertFilePrefix}}_ca.pem
{{end}}
{{- if and .KafkaConfig.ClientCert .KafkaConfig.ClientKey}}
ssl_client_cert {{.CertFilePrefix}}_client-cert.pem
ssl_client_cert_key {{.CertFilePrefix}}_client-key.pem
{{end}}
{{- if and .KafkaConfig.SaslUsername .KafkaConfig.SaslPassword}}
username {{.KafkaConfig.SaslUsername}}
password {{.KafkaConfig.SaslPassword}}
{{end}}
{{- if and (eq .KafkaConfig.SaslType "scram") .KafkaConfig.SaslScramMechanism}}
scram_mechanism {{.KafkaConfig.SaslScramMechanism}}
{{- if eq .KafkaTemplateWrap.IsSSL false}}
sasl_over_ssl false
{{end}}
{{end}}
{{end}}
{{end}}
{{define "syslog"}}
{{- if eq .CurrentTarget "syslog"}}
@type remote_syslog
host {{.SyslogTemplateWrap.Host}}
port {{.SyslogTemplateWrap.Port}}
severity {{.SyslogTemplateWrap.WrapSeverity}}
protocol {{.SyslogConfig.Protocol}}
packet_size 65535
{{- if .SyslogConfig.Program }}
program {{.SyslogConfig.Program}}
{{end}}
{{- if eq .SyslogConfig.SSLVerify true}}
verify_mode 1
{{else }}
verify_mode 0
{{end}}
{{- if .SyslogConfig.EnableTLS }}
tls true
{{- if .SyslogConfig.Certificate }}
ca_file {{.CertFilePrefix}}_ca.pem
{{end}}
{{end}}
{{- if and .SyslogConfig.ClientCert .SyslogConfig.ClientKey}}
client_cert {{.CertFilePrefix}}_client-cert.pem
client_cert_key {{.CertFilePrefix}}_client-key.pem
{{end}}
{{end}}
{{end}}
{{define "fluentforwarder"}}
{{- if eq .CurrentTarget "fluentforwarder"}}
@type forward
{{- if .FluentForwarderConfig.EnableTLS }}
transport tls
tls_allow_self_signed_cert true
tls_verify_hostname true
{{end}}
{{- if .FluentForwarderConfig.Certificate }}
tls_cert_path {{.CertFilePrefix}}_ca.pem
{{end}}
{{- if .FluentForwarderConfig.Compress }}
compress gzip
{{end}}
{{- if .FluentForwarderTemplateWrap.EnableShareKey }}
<security>
self_hostname "#{Socket.gethostname}"
shared_key true
</security>
{{end}}
{{- range $k, $val := .FluentForwarderTemplateWrap.FluentServers }}
<server>
{{if $val.Hostname}}
name {{$val.Hostname}}
{{end}}
host {{$val.Host}}
port {{$val.Port}}
{{ if $val.SharedKey}}
shared_key {{$val.SharedKey}}
{{end}}
{{ if $val.Username}}
username {{$val.Username}}
{{end}}
{{ if $val.Password}}
password {{$val.Password}}
{{end}}
weight {{$val.Weight}}
{{if $val.Standby}}
standby
{{end}}
</server>
{{end}}
{{end}}
{{end}}
{{define "custom"}}
{{- if eq .CurrentTarget "customtarget"}}
{{.CustomTargetWrap.Content}}
{{end}}
{{end}}
{{define "buffer"}}
<buffer>
@type file
path /fluentd/log/buffer/{{.BufferFile}}
flush_mode interval
flush_interval {{.OutputFlushInterval}}s
flush_thread_count 8
{{- if eq .CurrentTarget "splunk"}}
chunk_limit_size 8m
{{end}}
queued_chunks_limit_size 200
</buffer>
slow_flush_log_threshold 40.0
{{end}}
`