Splunk Search

How to write base query to get all the fields from below three multiple logs

shruti14
Explorer

Hi , I have to get the below fields extracted from these three logs to create visulisation: Fields i am interested:

Event_log type,originator_username,object,username,destination,bucket_name,time,type

 

I have written this regex to create parser but i am not getting all the fields while writing base serach:

^(?:[^ \n]* ){2}(?P<event_log>\w+\s+[a-z_-]+)(?:[^ \n]* ){2}\{"originator_username"\:(?P<originator_username>.[a-z]+")\,"object"\:(?<object>.[a-z]+)[^,\n]*,"extra"\:\{(?P<extra>.[a-z]+)":[^,\n]*(?:[^,\n]*,){6}"time"\:(?P<time>\w+),(?:[^,\n]*,){2}"type"\:(?<type>.[a-z_]+[a-z])"}

 

2022-01-23 10:19:47,140 WARNING event_log EventLog: {"originator_username":"abc","object":"cluster","extra":{"username":"admin"},"object_type":"cluster","originator_uid":0,"time":164287087,"throttled_event_count":1,"obj_uid":null,"type":"failed_authentication_attempt"}

2022-01-23 07:24:05,479 INFO event_log EventLog: {"originator_username":"abcef","object":"bdb:1","extra":{"destination":{"bucket_name":"dbabucket","type":"s3","subdir":"radar2","filename":""}},"object_type":"bdb","originator_uid":0,"time":164767765,"throttled_event_count":1,"obj_uid":"1","type":"backup_succeeded"}

2022-01-23 07:15:00,294 INFO event_log EventLog: {"originator_username":"adminstrator","object":"bdb:1","object_type":"bdb","originator_uid":0,"time":1642788100,"throttled_event_count":1,"obj_uid":"1","type":"backup_started"}

 

Can anyone help me what neededd to be fix in regex so i can get all the needed field extracted for base search.

Labels (1)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

You could extract the JSON and use spath

| rex "(?<log>\{.*\})"
| spath input=log
0 Karma

shruti14
Explorer

Hi, 

But these logs are not in json format, i.e why i have to parse them manually by writing regex

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

The examples you gave have JSON strings at the end which I extracted with the rex before using spath. Are you trying to extract at indexing time or search time?

0 Karma

shruti14
Explorer

I want to extract them at indexing time. So I want to get these field extracted during the index so i get the fields created and then create base search to build dashboards for visualisation. 

The logs are not in regular json format .

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Does this help?

^(?:[^ \n]* ){2}(?P<event_log>\w+\s+[a-z_-]+)(?:[^ \n]* ){2}\{"originator_username"\:(?P<originator_username>"[^"]+")\,"object"\:(?<object>"[^"]+")[^,\n]*,("extra"\:\{(?P<extra>.[a-z]+)":[^,\n])*(?:[^,\n]*,)+"time"\:(?P<time>\w+),(?:[^,\n]*,){2}"type"\:(?<type>.[a-z_]+[a-z])"}
0 Karma

shruti14
Explorer

Yeah it is almost there is there way we can get username and destination also extracted as fields since they also have value i mean this regex gives extra field with value as username and destination but if you can see i have username :admin and destination as bucket name does that further breakage is possible ?

username: admin

"destination":{"bucket_name":"dbabucket","type":"s3","subdir":"radar2","filename":""}}

But yes the regex shared by you is really helpful and i understood what mistake i am doing  thanks ITWhisperer

 

Tags (1)
0 Karma
Get Updates on the Splunk Community!

Community Content Calendar, November Edition

Welcome to the November edition of our Community Spotlight! Each month, we dive into the Splunk Community to ...

October Community Champions: A Shoutout to Our Contributors!

As October comes to a close, we want to take a moment to celebrate the people who make the Splunk Community ...

Stay Connected: Your Guide to November Tech Talks, Office Hours, and Webinars!

What are Community Office Hours? Community Office Hours is an interactive 60-minute Zoom series where ...