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!

Developer Spotlight with Denis Gladkikh

From Splunk Engineer to Kubernetes App Builder Denis GladkikhWhat happens when a lifelong developer turns a ...

Governing Enterprise AI, Bringing Cisco Telemetry Home, and More from Splunk Lantern

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...

Agentic SOC Triage: Investigating Splunk ES Notables with MCP Server and a Local LLM

The Problem: Too Many Alerts, Too Little Context Security operations teams running Splunk Enterprise Security ...