Splunk Search

Help with field extraction

griffinpair
Path Finder

I have the following event being returned (any event that includes "Streaming"):

Streaming 29 items to https://test.url.com/api/reginvolved/System/Legacy

I need the number after Streaming, in this case 29 (it can potentially be any number), extracted so I can add it up across all "Streaming" events.

It would also be helpful if the url could be extracted as well and I could potentially add up the "Streaming" number based on the urls

Thanks in advance!

0 Karma
1 Solution

tiagofbmm
Influencer

Hey

You can do a rex command on this:

| rex field=YOURFIELD "Streaming\s(?<ExtractedNumber>\d+).*(?=https)(?<URL>.*)"

Let me know if it works for you

View solution in original post

0 Karma

cpetterborg
SplunkTrust
SplunkTrust

If you have similar syntax for all the events, then you can get the count from the line with a regex like the following:

... | rex "Streaming\s+(?P<cnt>\d+)\sitems" | stats sum(cnt)

If your data varies by much, you should be able to make appropriate modifications to the rex. To get the URL as well, you can do it like the following:

... | rex "Streaming\s+(?P<cnt>\d+)\s+items\s+to\s+(?P<url>http\S+)" | stats sum(cnt) by url

or something similar.

0 Karma

richgalloway
SplunkTrust
SplunkTrust

The rex command makes this easy at search time. Assuming there is nothing after the URL, this should get you started.

index=foo | rex "Streaming\s(?<Streaming>\d+)\sitems\sto\s(?<URL>.*)" | ...
---
If this reply helps you, Karma would be appreciated.
0 Karma

tiagofbmm
Influencer

Hey

You can do a rex command on this:

| rex field=YOURFIELD "Streaming\s(?<ExtractedNumber>\d+).*(?=https)(?<URL>.*)"

Let me know if it works for you

0 Karma

tiagofbmm
Influencer

Please let me know if the answer was useful for you. If it was, accept it and upvote. If not, give us more input so we can help you with that

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...