Splunk Search

Splunk query

Awanish1212
Explorer

Suppose there are 5 events in raw text in Splunk as below:

"host":"111.123.23.34","level":1,"msg":"cricket score : 10","time":"2023-07-11T17:28:33.265Z"

"host":"111.123.23.34","level":2,"msg":"cricket score : 20","time":"2023-07-11T17:28:33.265Z"

"host":"111.123.23.34","level":3,"msg":"cricket score : 30","time":"2023-07-11T17:28:33.265Z"

"host":"111.123.23.34","level":4,"msg":"cricket score : 40","time":"2023-07-11T17:28:33.265Z"

"host":"111.123.23.34","level"5,"msg":"cricket score : 50","time":"2023-07-11T17:28:33.265Z"

So I need to create a Splunk query to get output as below.

Total Number of events (sum of all events)
5

Total Score (sum of all cricket score)
150

Request your help for the same.

Labels (1)
0 Karma

yuanliu
SplunkTrust
SplunkTrust

Alternatively, is the illustrated raw text the full _raw events?  They look too much like part of valid JSON objects.  If raw events are in JSON, you should have fields host, msg, and so on.  If so, using fields instead of _raw would be more efficient, like

| eval cricket_score = mvindex(split(msg, ": "), 1)
| stats count sum(cricket_score) as total_score

If msg field is not available, using extract (aka kv) might also be more efficient than rex, like

| kv pairdelim="," kvdelim=":"
| eval cricket_score = mvindex(split(msg, ": "), 1)
| stats count sum(cricket_score) as total_score

 

 

Awanish1212
Explorer

thanks

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
| rex "cricket\sscore\s*:\s*(?<score>\d+)"
| stats count sum(score) as cricketscore

Awanish1212
Explorer

Thanks 

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Mile High Learning with Splunk University, Denver, Colorado

If Denver is known for its mile-high elevation, Splunk University is about to raise the bar on technical ...

IT Service Intelligence 5.0 Series: Your Guide to the June Launch

We are excited to announce the June release of Splunk IT Service Intelligence (ITSI) 5.0. This update ...

Agent Mode Engaged! Enchaining Agentic Operations with Splunk AI Assistant 2.0

    Are you ready to transform how your team handles complex data requests? We invite you to our upcoming ...