Splunk Search

State with custom source in by clause

rainerst
Engager

Hello,

I am currently faced with the problem while creating stats for a specific event, where the event itself contains a custom source field. With my current search it will use the default source field rather than the custom source field of the event. How can I use this custom source field in the by clause of the stats command?

Here an event sample:

name=testEvent source=application1 eventType=type1

Here the search:

eventType=type1 | stats count as occurrences by source, eventType

Thanks in advance,
Rainer

Tags (1)
0 Karma
1 Solution

lguinn2
Legend

This is a little clunky but it will work

eventType=type1 | rex "source=(?<Source>\S+)"  | stats count as occurrences by Source, eventType

Notice that your custom source is now named "Source". Since field names are case-sensitive, this avoids the conflict.
You could put this regular expression into the appropriate props.conf file and then your "Source" would always be accessible, without the need for the rex command...

View solution in original post

lguinn2
Legend

This is a little clunky but it will work

eventType=type1 | rex "source=(?<Source>\S+)"  | stats count as occurrences by Source, eventType

Notice that your custom source is now named "Source". Since field names are case-sensitive, this avoids the conflict.
You could put this regular expression into the appropriate props.conf file and then your "Source" would always be accessible, without the need for the rex command...

rainerst
Engager

thank you!

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!

[Puzzles] Solve, Learn, Repeat: Character substitutions with Regular Expressions

This challenge was first posted on Slack #puzzles channelFor BORE at .conf23, we had a puzzle question which ...

Splunk Community Badges!

  Hey everyone! Ready to earn some serious bragging rights in the community? Along with our existing badges ...

[Puzzles] Solve, Learn, Repeat: Matching cron expressions

This puzzle (first published here) is based on matching timestamps to cron expressions.All the timestamps ...