Dashboards & Visualizations

How to extract Date and Time from the raw logs

aditsss
Motivator

Hi Everyone,

Below is my data( raw logs)

pod_name=node-fdzz message=2020-09-25 21:09:33.969 ERROR [node,00e,4deca,false]67 --- [r-84-548] c.r.Resolver 

How do I extract Date and time 2020-09-25 21:09:33.969 from the above log data?

Can anyone guide me on this.

Labels (2)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust
index=abc ns=sigh nodeException node="*" Id=* |rex "message=(?P<datetime>\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d+)\s"|fields datetime

You don't need field= as the default field is _raw - if you want to specify it explicitly then use

index=abc ns=sigh nodeException node="*" Id=* |rex field=_raw "message=(?P<datetime>\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d+)\s"|fields datetime

View solution in original post

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

This regex will extract the datetime

"message=(?P<datetime>\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d+)\s"
0 Karma

aditsss
Motivator

@ITWhisperer 

 

I tried like below . Not able to get any result

Where I am going wrong!

index=abc ns=sigh nodeException node="*" Id=* |rex field="message=(?P<datetime>\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d+)\s"|fields datetime

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Ideally, this extract should be done at indexing time

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
index=abc ns=sigh nodeException node="*" Id=* |rex "message=(?P<datetime>\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d+)\s"|fields datetime

You don't need field= as the default field is _raw - if you want to specify it explicitly then use

index=abc ns=sigh nodeException node="*" Id=* |rex field=_raw "message=(?P<datetime>\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}\.\d+)\s"|fields datetime
0 Karma

aditsss
Motivator

@ITWhisperer 

 

Thank you once again . It works exactly the way I want.

0 Karma
Get Updates on the Splunk Community!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...