Splunk Search

Extract string and separate results by different strings

EricLloyd79
Builder

I have been looking for days for an answer to this on Splunk answers and elsewhere.

I have a query like this:
sourcetype="*-xxx01" (XXX0014 OR XXX0019 OR XXX0018 OR XXX0015) | timechart span=30m COUNT

XXX014, XXX019, XXX018, XXX015 are all strings in each log entry (they are KPIs) (its either XXX014 or XXX019 or XXX018 or XXX015 obviously in each log entry). I am trying to get results returned that are in columns so I can separate the results based on these KPIs. This would be so easy if they were part of a field. I could use "by fieldname" but these aren't part of a field. I was hoping I could do "COUNT by sum(XXX0014) sum(XXX019) sum(XXX018) sum(XXX015)" but that doesn't work. Below is an example of a log entry. Any help would be greatly appreciated!! (ultimate goal is a timechart bar graph that separates by different string values in each span)

2014-04-15 15:00:48,056 [INFO] [UUID=XXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX subNo=XXXXXXXXXXX yhn=000000000] XXX0014: Ignored notification grant. cause=IgnoreNotificationException Ignore Grant Notification

Where it says XXX0014... that is the value I want to separate my results with.

0 Karma
1 Solution

martin_mueller
SplunkTrust
SplunkTrust

The easiest would be to get them extracted into a field, say KPI, and do a timechart count by KPI. For your sample event, you should be able to temporarily extract the field like this:

base search | rex "\]\s+(?<KPI>\w+):" | timechart count by KPI

If that works, move the extraction to the config (Settings -> Fields -> Field Extractions) so you can drop the rex call from the search. If your other KPIs are in differently looking events you can define multiple extractions that all yield the same field name.

View solution in original post

martin_mueller
SplunkTrust
SplunkTrust

The easiest would be to get them extracted into a field, say KPI, and do a timechart count by KPI. For your sample event, you should be able to temporarily extract the field like this:

base search | rex "\]\s+(?<KPI>\w+):" | timechart count by KPI

If that works, move the extraction to the config (Settings -> Fields -> Field Extractions) so you can drop the rex call from the search. If your other KPIs are in differently looking events you can define multiple extractions that all yield the same field name.

EricLloyd79
Builder

This worked beautifully... thank you!

0 Karma
Get Updates on the Splunk Community!

Introducing Splunk Enterprise 9.2

WATCH HERE! Watch this Tech Talk to learn about the latest features and enhancements shipped in the new Splunk ...

Adoption of RUM and APM at Splunk

    Unleash the power of Splunk Observability   Watch Now In this can't miss Tech Talk! The Splunk Growth ...

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...