Skip to content

Commit 4177ac8

Browse files
author
Amin Jamali
committed
Add a parsable logstash filter
- Convert the inner JSON encoded messages into useful/indexed entries - Ensure the timestamp is human readable - Remove unneeded fields and allow easier filtering
1 parent 1ad4494 commit 4177ac8

File tree

1 file changed

+45
-13
lines changed

1 file changed

+45
-13
lines changed

examples/logstash-filters.conf

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,51 @@
1-
# standard rfc5424 parsing
2-
grok {
3-
match => [ "message", "%{SYSLOG5424LINE}" ]
4-
}
1+
filter {
2+
# standard rfc5424 parsing
3+
grok {
4+
match => [ "message", "%{SYSLOG5424LINE}" ]
5+
}
56

6-
syslog_pri {}
7+
syslog_pri {}
78

8-
# extract BOSH instance metadata from structured data
9-
if [syslog5424_sd] =~ "\[instance@47450" {
10-
grok {
11-
match => [ "syslog5424_sd", "\[instance@47450 %{DATA:instance_raw}\]" ]
9+
mutate {
10+
rename => ["syslog5424_app", "job"]
11+
}
12+
mutate {
13+
rename => ["syslog5424_host", "host_address"]
14+
}
15+
date {
16+
match => [ "syslog5424_ts", "ISO8601" ]
17+
target => "@timestamp"
18+
remove_field => "syslog5424_ts"
1219
}
1320

14-
kv {
15-
source => "instance_raw"
16-
target => "syslog5424_sd_instance"
17-
remove_field => "instance_raw"
21+
# extract BOSH instance metadata from structured data
22+
if [syslog5424_sd] =~ "\[instance@47450" {
23+
grok {
24+
match => [ "syslog5424_sd", "\[instance@47450 %{DATA:source_raw}\]" ]
25+
}
26+
27+
kv {
28+
source => "source_raw"
29+
target => "source"
30+
remove_field => "source_raw"
31+
}
32+
33+
mutate {
34+
remove_field => "syslog5424_sd"
35+
}
36+
}
37+
38+
if [syslog5424_msg] =~ /^{.*}/ {
39+
json {
40+
source => "syslog5424_msg"
41+
target => "parsed_json"
42+
remove_field => "syslog5424_msg"
43+
add_tag => [ "json" ]
44+
}
45+
46+
date {
47+
match => ["[parsed_json][timestamp]", "ISO8601", "UNIX"]
48+
target => ["[parsed_json][timestamp]"]
49+
}
1850
}
1951
}

0 commit comments

Comments
 (0)