@@ -24,61 +24,104 @@ func TestResource_Processors(t *testing.T) {
24
24
content : []byte (`---
25
25
description: Made up pipeline
26
26
processors:
27
- # First processor.
28
- - grok:
29
- tag: Extract header
30
- field: message
31
- patterns:
32
- - \[%{APACHE_TIME:apache.error.timestamp}\] \[%{LOGLEVEL:log.level}\]( \[client
33
- %{IPORHOST:source.address}(:%{POSINT:source.port})?\])? %{GREEDYDATA:message}
34
- - \[%{APACHE_TIME:apache.error.timestamp}\] \[%{DATA:apache.error.module}:%{LOGLEVEL:log.level}\]
35
- \[pid %{NUMBER:process.pid:long}(:tid %{NUMBER:process.thread.id:long})?\](
36
- \[client %{IPORHOST:source.address}(:%{POSINT:source.port})?\])? %{GREEDYDATA:message}
37
- pattern_definitions:
38
- APACHE_TIME: '%{DAY} %{MONTH} %{MONTHDAY} %{TIME} %{YEAR}'
39
- ignore_missing: true
27
+ - grok:
28
+ tag: Extract header
29
+ field: message
30
+ patterns:
31
+ - \[%{APACHE_TIME:apache.error.timestamp}\] \[%{LOGLEVEL:log.level}\]( \[client%{IPORHOST:source.address}(:%{POSINT:source.port})?\])? %{GREEDYDATA:message}
32
+ - \[%{APACHE_TIME:apache.error.timestamp}\] \[%{DATA:apache.error.module}:%{LOGLEVEL:log.level}\]
33
+ ignore_missing: true
40
34
41
- - date:
42
- field: apache.error.timestamp
43
- target_field: '@timestamp'
44
- formats:
45
- - EEE MMM dd H:m:s yyyy
46
- - EEE MMM dd H:m:s.SSSSSS yyyy
47
- on_failure:
48
- - append:
35
+ - date:
36
+ field: apache.error.timestamp
37
+ target_field: '@timestamp'
38
+ formats:
39
+ - EEE MMM dd H:m:s yyyy
40
+ - EEE MMM dd H:m:s.SSSSSS yyyy
41
+ on_failure:
42
+ - append:
43
+ field: error.message
44
+ value: '{{ _ingest.on_failure_message }}'
45
+ - set:
46
+ description: Set event category
47
+ field: event.category
48
+ value: web
49
+ # Some script
50
+ - script:
51
+ lang: painless
52
+
53
+ - grok:
54
+ field: source.address
55
+ ignore_missing: true
56
+ patterns:
57
+ - ^(%{IP:source.ip}|%{HOSTNAME:source.domain})$
58
+ - rename:
59
+ field: source.as.organization_name
60
+ target_field: source.as.organization.name
61
+ ignore_missing: true
62
+ on_failure:
63
+ - set:
49
64
field: error.message
50
65
value: '{{ _ingest.on_failure_message }}'
51
- - set:
52
- description: Set event category
53
- field: event.category
54
- value: web
55
- # Some script
56
- - script:
57
- lang: painless
58
- source: >-
59
- [...]
66
+ ` ),
67
+ expected : []Processor {
68
+ {Type : "grok" , FirstLine : 4 , LastLine : 11 },
69
+ {Type : "date" , FirstLine : 12 , LastLine : 21 },
70
+ {Type : "set" , FirstLine : 22 , LastLine : 26 },
71
+ {Type : "script" , FirstLine : 27 , LastLine : 29 },
72
+ {Type : "grok" , FirstLine : 30 , LastLine : 34 },
73
+ {Type : "rename" , FirstLine : 35 , LastLine : 38 },
74
+ },
75
+ },
76
+ {
77
+ name : "Yaml pipeline" ,
78
+ format : "yml" ,
79
+ content : []byte (`---
80
+ description: Made up pipeline
81
+ processors:
82
+ - grok:
83
+ tag: Extract header
84
+ field: message
85
+ patterns:
86
+ - \[%{APACHE_TIME:apache.error.timestamp}\] \[%{LOGLEVEL:log.level}\]( \[client%{IPORHOST:source.address}(:%{POSINT:source.port})?\])? %{GREEDYDATA:message}
87
+ - \[%{APACHE_TIME:apache.error.timestamp}\] \[%{DATA:apache.error.module}:%{LOGLEVEL:log.level}\]
88
+ ignore_missing: true
60
89
61
- - grok:
62
- field: source.address
63
- ignore_missing: true
64
- patterns:
65
- - ^(%{IP:source.ip}|%{HOSTNAME:source.domain})$
66
- - rename:
67
- field: source.as.organization_name
68
- target_field: source.as.organization.name
69
- ignore_missing: true
70
- on_failure:
71
- - set:
72
- field: error.message
73
- value: '{{ _ingest.on_failure_message }}'
90
+ - date:
91
+ field: apache.error.timestamp
92
+ target_field: '@timestamp'
93
+ formats:
94
+ - EEE MMM dd H:m:s yyyy
95
+ - EEE MMM dd H:m:s.SSSSSS yyyy
96
+ on_failure:
97
+ - append:
98
+ field: error.message
99
+ value: '{{ _ingest.on_failure_message }}'
100
+ - set:
101
+ description: Set event category
102
+ field: event.category
103
+ value: web
104
+ # Some script
105
+ - script:
106
+ lang: painless
107
+
108
+ - grok:
109
+ field: source.address
110
+ ignore_missing: true
111
+ patterns:
112
+ - ^(%{IP:source.ip}|%{HOSTNAME:source.domain})$
113
+ - rename:
114
+ field: source.as.organization_name
115
+ target_field: source.as.organization.name
116
+ ignore_missing: true
74
117
` ),
75
118
expected : []Processor {
76
- {Type : "grok" , FirstLine : 5 , LastLine : 16 },
77
- {Type : "date" , FirstLine : 18 , LastLine : 27 },
78
- {Type : "set" , FirstLine : 28 , LastLine : 31 },
79
- {Type : "script" , FirstLine : 33 , LastLine : 35 },
80
- {Type : "grok" , FirstLine : 38 , LastLine : 42 },
81
- {Type : "rename" , FirstLine : 43 , LastLine : 46 },
119
+ {Type : "grok" , FirstLine : 4 , LastLine : 11 },
120
+ {Type : "date" , FirstLine : 12 , LastLine : 21 },
121
+ {Type : "set" , FirstLine : 22 , LastLine : 26 },
122
+ {Type : "script" , FirstLine : 27 , LastLine : 29 },
123
+ {Type : "grok" , FirstLine : 30 , LastLine : 34 },
124
+ {Type : "rename" , FirstLine : 35 , LastLine : 38 },
82
125
},
83
126
},
84
127
{
@@ -109,10 +152,10 @@ on_failure:
109
152
` ),
110
153
expected : []Processor {
111
154
{Type : "drop" , FirstLine : 3 , LastLine : 3 },
112
- {Type : "set" , FirstLine : 4 , LastLine : 7 },
155
+ {Type : "set" , FirstLine : 4 , LastLine : 8 },
113
156
{Type : "remove" , FirstLine : 9 , LastLine : 9 },
114
157
{Type : "set" , FirstLine : 9 , LastLine : 9 },
115
- {Type : "set" , FirstLine : 10 , LastLine : 13 },
158
+ {Type : "set" , FirstLine : 10 , LastLine : 15 },
116
159
},
117
160
},
118
161
{
@@ -155,7 +198,7 @@ on_failure:
155
198
"processors": [{"drop": {"if":"ctx.drop!=null"}}]
156
199
}` ),
157
200
expected : []Processor {
158
- {Type : "drop" , FirstLine : 3 , LastLine : 3 },
201
+ {Type : "drop" , FirstLine : 3 , LastLine : 4 },
159
202
},
160
203
},
161
204
{
@@ -173,7 +216,7 @@ on_failure:
173
216
]
174
217
}` ),
175
218
expected : []Processor {
176
- {Type : "script" , FirstLine : 3 , LastLine : 10 },
219
+ {Type : "script" , FirstLine : 3 , LastLine : 11 },
177
220
// Source will be processed as multiline:
178
221
// "source": """
179
222
// String[] envSplit = ctx['env'].splitOnToken(params['delimiter']);
@@ -222,6 +265,22 @@ processors:
222
265
{Type : "script" , FirstLine : 3 , LastLine : 6 },
223
266
},
224
267
},
268
+ {
269
+ name : "Yaml script with empty line characters" ,
270
+ format : "yml" ,
271
+ content : []byte (`---
272
+ processors:
273
+ - script:
274
+ description: Do something.
275
+ tag: script_drop_null_empty_values
276
+ lang: painless
277
+ source: "def a = b \n
278
+ ; def b = 2; \n"
279
+ ` ),
280
+ expected : []Processor {
281
+ {Type : "script" , FirstLine : 3 , LastLine : 8 },
282
+ },
283
+ },
225
284
{
226
285
name : "Yaml empty processor" ,
227
286
format : "yml" ,
@@ -249,7 +308,7 @@ processors:
249
308
def b = 2;
250
309
` ),
251
310
expected : []Processor {
252
- {Type : "set" , FirstLine : 4 , LastLine : 6 },
311
+ {Type : "set" , FirstLine : 4 , LastLine : 8 },
253
312
{Type : "script" , FirstLine : 9 , LastLine : 12 },
254
313
},
255
314
},
0 commit comments