paano
February 18, 2019, 9:13pm
1
I have the following the json message.
{
"eventData" : {
"commandContext" : {
"eventUserId" : "system",
"eventOrigin" : "java",
"eventQueueMgr" : "TEST1",
"eventAccountingToken" : 0000000000000000000000000000000000000000000000000000000000000000,
"eventApplIdentity" : "",
"eventApplType" : "Unix",
"eventApplName" : "aixutil",
"eventApplOrigin" : "",
"command" : "Inquire"
}
}
}
Trying to remove the leading zero as logstash is throwing error. Cannot adjust the source.
I am trying to achieve this by adding a ruby filter to replace the 0
to ' '
.
Need some assistance on how to write the script.
logstash conf is -
filter {
ruby {
code => "str.sub!([eventData][commandContext][eventAccountingToken], "")"
}
json {
source => "message"
}
}
Badger
February 18, 2019, 9:48pm
2
The JSON has not been parsed when the ruby filter executes, so that field does not exist at that point. You can remove leading zeroes from fields using
mutate { gsub => [ "message", " 0*([0-9]+),", " \1," ] }
paano
February 18, 2019, 10:10pm
3
@Badger it works.
IF i would use ruby filter, how would i implement. I am trying to learn using rubyfilter. ANy suggestion
Badger
February 18, 2019, 10:23pm
4
ruby { code => ' event.set("message", event.get("message").gsub(/ 0*([0-9]+),/, " \\1,")) ' }
paano
February 19, 2019, 5:11pm
5
@Badger if i had to remove the field completely before the json parse. is there a way in logstash. And also convert field to string
in gsub
.
Badger
February 19, 2019, 5:36pm
6
You could use mutate+gsub to remove eventAccountingToken from the message before parsing.
If you want to convert the field to a string use mutate+convert.
system
(system)
Closed
March 19, 2019, 5:36pm
7
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.