Splunk Search

Extract data in log event as key value pair

galbrilovich
Explorer

Hi, I am trying to extract data from my logs to display it by time.

My logs look in this form:

2020-09-09 14:45:46.321 finished processing data- sold 5 products: 2(<product1>) 1(<product2>) 2(<product3>).
i want to show it as a timechart when 3 of the products are shown with each of their values:
2 sales for <product1>, 1 for <product2> and 2 for <product3>, how can i do it for each log?
Note: in a log there can be shown n different products.

Labels (2)
0 Karma
1 Solution

richgalloway
SplunkTrust
SplunkTrust

Try this query.

| makeresults | eval _raw="2020-09-09 14:45:46.321 finished processing data- sold 5 products: 2(<product1>) 1(<product2>) 2(<product3>)."
```Above just defines test data```
| rex max_match=0 "(?<quantity>\d+)\((?<product>[^\)]+)\)[\.\s+]"
| eval combo = mvzip(product, quantity)
| mvexpand combo
| eval combo = split(combo, ",")
| eval product=mvindex(combo, 0), quantity=mvindex(combo,1)
| timechart sum(quantity) as Sales by product

 

---
If this reply helps you, Karma would be appreciated.

View solution in original post

richgalloway
SplunkTrust
SplunkTrust

Try this query.

| makeresults | eval _raw="2020-09-09 14:45:46.321 finished processing data- sold 5 products: 2(<product1>) 1(<product2>) 2(<product3>)."
```Above just defines test data```
| rex max_match=0 "(?<quantity>\d+)\((?<product>[^\)]+)\)[\.\s+]"
| eval combo = mvzip(product, quantity)
| mvexpand combo
| eval combo = split(combo, ",")
| eval product=mvindex(combo, 0), quantity=mvindex(combo,1)
| timechart sum(quantity) as Sales by product

 

---
If this reply helps you, Karma would be appreciated.

galbrilovich
Explorer

thank you very mush, it works! 🎉

0 Karma
Get Updates on the Splunk Community!

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...

Splunk APM: New Product Features + Community Office Hours Recap!

Howdy Splunk Community! Over the past few months, we’ve had a lot going on in the world of Splunk Application ...

Index This | Forward, I’m heavy; backward, I’m not. What am I?

April 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...