forked from elastic/integrations
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipeline_dns.yml
254 lines (249 loc) · 10.5 KB
/
pipeline_dns.yml
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
---
description: Pipeline for parsing Infoblox NIOS DNS logs.
processors:
- grok:
field: message
patterns:
- "^zone %{DATA:dns.question.name}/%{DATA:dns.question.class}: notify from %{IP:client.ip}#%{NUMBER:client.port:long}:? %{GREEDYDATA:infoblox_nios.log.dns.message}$"
- "^transfer of '%{DATA:dns.question.name}/%{DATA:dns.question.class}' from %{IP:client.ip}#%{NUMBER:client.port:long}:? %{GREEDYDATA:infoblox_nios.log.dns.message}$"
- "^validating %{DATA:dns.question.name}/%{WORD:dns.question.type}: %{GREEDYDATA:infoblox_nios.log.dns.message}$"
- "^(%{NOTSPACE:infoblox_nios.log.dns.category}:)?\\s*client %{DATA} %{IP:client.ip}#%{NUMBER:client.port:long}:? updating zone '%{DATA:dns.question.name}/%{DATA:dns.question.class}': %{GREEDYDATA:infoblox_nios.log.dns.message}$"
- "^(%{NOTSPACE:infoblox_nios.log.dns.category}:)?\\s*client %{DATA} %{IP:client.ip}#%{NUMBER:client.port:long}:? \\(%{DATA:client.domain}\\): query failed %{GREEDYDATA:infoblox_nios.log.dns.message}$"
- "^(%{NOTSPACE:infoblox_nios.log.dns.category}:)?\\s*client %{DATA} %{IP:client.ip}#%{NUMBER:client.port:long}:? \\(%{DATA:infoblox_nios.log.dns.before_query}\\): rewriting query name %{DATA} to '%{DATA:infoblox_nios.log.dns.after_query}', type %{DATA:dns.question.type}$"
- "^(%{NOTSPACE:infoblox_nios.log.dns.category}:)?\\s*client %{DATA} %{IP:client.ip}#%{NUMBER:client.port:long}:? \\(%{DATA:client.domain}\\): query: %{DATA:dns.question.name} %{DATA:dns.question.class} %{WORD:dns.question.type} %{DATA:infoblox_nios.log.dns.header_flags} \\(%{IP:server.ip}\\)$"
- "^(%{NOTSPACE:infoblox_nios.log.dns.category}:)?\\s*client %{IP:client.ip}#%{NUMBER:client.port:long}:? %{DATA:network.transport}: query: %{DATA:dns.question.name} %{DATA:dns.question.class} %{WORD:dns.question.type} response: %{DATA:dns.response_code} %{DATA:infoblox_nios.log.dns.header_flags}$"
- "^(%{NOTSPACE:infoblox_nios.log.dns.category}:)?\\s*client %{DATA} %{IP:client.ip}#%{NUMBER:client.port:long}:? \\(%{DATA:client.domain}\\): transfer of '%{DATA:dns.question.name}/%{DATA:dns.question.class}': %{GREEDYDATA:infoblox_nios.log.dns.message}$"
- "^(%{NOTSPACE:infoblox_nios.log.dns.category}:)?\\s*CEF:0\\|Infoblox\\|NIOS\\|%{GREEDYDATA:infoblox_nios.log.dns.version}\\|RPZ-%{DATA:dns.answers.type}\\|%{DATA:infoblox_nios.log.dns.answers_policy}\\|\\d+\\|app=DNS dst=%{IP:server.ip} src=%{IP:client.ip} spt=%{NUMBER:client.port:long} view=%{DATA:infoblox_nios.log.dns.view_name} qtype=%{WORD:dns.question.type} msg=%{GREEDYDATA:infoblox_nios.log.dns.message}$"
- "^(%{NOTSPACE:infoblox_nios.log.dns.category}:)?\\s*%{GREEDYDATA:timestamp} client %{IP:client.ip}#%{NUMBER:client.port:long}:? %{DATA:network.transport}: query: %{DATA:dns.question.name} %{DATA:dns.question.class} %{WORD:dns.question.type} response: %{DATA:dns.response_code} %{DATA:infoblox_nios.log.dns.header_flags} %{GREEDYDATA:repeat_message}$"
- "^(%{NOTSPACE:infoblox_nios.log.dns.category}:)?\\s*%{GREEDYDATA:timestamp} client %{IP:client.ip}#%{NUMBER:client.port:long}:? %{DATA:network.transport}: query: %{DATA:dns.question.name} %{DATA:dns.question.class} %{WORD:dns.question.type} response: %{DATA:dns.response_code} %{DATA:infoblox_nios.log.dns.header_flags}$"
- "^(%{NOTSPACE:infoblox_nios.log.dns.category}:)?\\s*client %{DATA} %{IP:client.ip}#%{NUMBER:client.port:long}:? %{GREEDYDATA:infoblox_nios.log.dns.message}$"
- "^%{GREEDYDATA:infoblox_nios.log.dns.message}$"
- date:
field: timestamp
if: ctx.timestamp != null && ctx.event?.timezone != null
timezone: '{{{event.timezone}}}'
formats:
- dd-MMM-yyyy HH:mm:ss.SSS
- yyyy-MM-dd HH:mm:ss.SSS'Z'
on_failure:
- remove:
field: timestamp
ignore_missing: true
- append:
field: error.message
value: '{{{_ingest.on_failure_message}}}'
- date:
field: timestamp
if: ctx.timestamp != null && ctx.event?.timezone == null
formats:
- dd-MMM-yyyy HH:mm:ss.SSS
- yyyy-MM-dd HH:mm:ss.SSS'Z'
on_failure:
- remove:
field: timestamp
ignore_missing: true
- append:
field: error.message
value: '{{{_ingest.on_failure_message}}}'
- script:
lang: painless
if: ctx.repeat_message != null
description: |
Process dns.answers data by splitting repeat_message by ';'
and then each of the elements by space. It takes into account
quoted strings.
source: |
def splitUnquoted(String input, String sep) {
def tokens = [];
def startPosition = 0;
def isInQuotes = false;
char quote = (char)"\"";
for (def currentPosition = 0; currentPosition < input.length(); currentPosition++) {
if (input.charAt(currentPosition) == quote) {
isInQuotes = !isInQuotes;
}
else if (input.charAt(currentPosition) == (char)sep && !isInQuotes) {
def token = input.substring(startPosition, currentPosition).trim();
if (!token.equals("")) {
tokens.add(token);
}
startPosition = currentPosition + 1;
}
}
def lastToken = input.substring(startPosition);
if (!lastToken.equals(sep) && !lastToken.equals("")) {
tokens.add(lastToken.trim());
}
return tokens;
}
def arr = splitUnquoted(ctx.repeat_message, ";");
ctx.repeat_message = arr;
Map map = new HashMap();
map.put('name', new ArrayList());
map.put('ttl', new ArrayList());
map.put('class', new ArrayList());
map.put('type', new ArrayList());
map.put('data', new ArrayList());
for (def i = 0; i < arr?.length; i++) {
def response = splitUnquoted(arr[i], " ");
map['name'].add(response[0]);
map['ttl'].add(response[1]);
map['class'].add(response[2]);
map['type'].add(response[3]);
map['data'].addAll(response.subList(4, response.length));
}
ctx.dns.answers = map;
- convert:
field: dns.answers.ttl
type: long
ignore_missing: true
ignore_failure: true
- lowercase:
field: network.transport
ignore_missing: true
ignore_failure: true
- script:
description: Remove last Full Stop('.') from `dns.answers.data` field.
lang: painless
if: ctx.dns?.answers?.data instanceof List
source: |
def hash = new ArrayList();
for(data in ctx.dns?.answers?.data){
def n = data.length();
if(data.charAt(n-1).toString() == '.'){
def data_substring = data.substring(0,n-1) + data.substring(n);
hash.add(data_substring);
}
else{
hash.add(data);
}
}
ctx.dns.answers.data = hash;
- script:
description: Remove last Full Stop('.') from `dns.answers.name` field.
lang: painless
if: ctx.dns?.answers?.name instanceof List
source: |
def hash = new ArrayList();
for(name in ctx.dns?.answers?.name){
def n = name.length();
if(name.charAt(n-1).toString() == '.'){
def name_substring = name.substring(0,n-1) + name.substring(n);
hash.add(name_substring);
}
else{
hash.add(name);
}
}
ctx.dns.answers.name = hash;
- foreach:
field: dns.answers.data
if: ctx.dns?.answers?.data != null
processor:
grok:
field: '_ingest._value'
patterns:
- "^%{IP:related.ip}$"
- "^%{HOSTNAME:related.hosts}$"
ignore_failure: true
- convert:
field: client.ip
if: ctx.client?.ip != null && ctx.client.ip != ''
type: ip
ignore_missing: true
on_failure:
- remove:
field: client.ip
ignore_missing: true
- append:
field: error.message
value: '{{{_ingest.on_failure_message}}}'
- append:
field: related.ip
value: '{{{client.ip}}}'
if: ctx.client?.ip != null
allow_duplicates: false
ignore_failure: true
- convert:
field: server.ip
if: ctx.server?.ip != null && ctx.server.ip != ''
type: ip
ignore_missing: true
on_failure:
- remove:
field: server.ip
ignore_missing: true
- append:
field: error.message
value: '{{{_ingest.on_failure_message}}}'
- append:
field: related.ip
value: '{{{server.ip}}}'
if: ctx.server?.ip != null
allow_duplicates: false
ignore_failure: true
- append:
field: related.hosts
value: '{{{client.domain}}}'
if: ctx.client?.domain != null
allow_duplicates: false
ignore_failure: true
- foreach:
field: dns.answers.name
if: ctx.dns?.answers?.name != null
processor:
append:
field: related.hosts
value: '{{_ingest._value}}'
allow_duplicates: false
ignore_failure: true
- append:
field: related.hosts
value: '{{{dns.question.name}}}'
if: ctx.dns?.question?.name != null
allow_duplicates: false
ignore_failure: true
- script:
lang: painless
if: ctx.infoblox_nios?.log?.dns?.header_flags != null && ctx.infoblox_nios.log.dns.header_flags != ''
params:
'A': 'AA'
't': 'TC'
'C': 'CD'
'D': 'DO'
source: |
ArrayList hf = new ArrayList();
for (entry in params.entrySet()) {
if (ctx.infoblox_nios.log.dns.header_flags.contains(entry.getKey())) {
hf.add(entry.getValue());
}
}
if (ctx.dns?.response_code != null && ctx.dns.response_code != '') {
if (ctx.infoblox_nios.log.dns.header_flags.contains('+')) {
hf.add('RA')
}
} else {
if (ctx.infoblox_nios.log.dns.header_flags.contains('+')) {
hf.add('RD')
}
}
if (hf.length == 0) {
return;
}
if (ctx.dns == null) {
HashMap hm = new HashMap();
ctx.put('dns', hm);
}
ctx.dns.put('header_flags', hf);
- remove:
field:
- timestamp
- repeat_message
ignore_missing: true
on_failure:
- set:
field: event.kind
value: pipeline_error
- append:
field: error.message
value: '{{{ _ingest.on_failure_message }}}'