Splunk Search

How can I group multiple values from repeated fields in the same log?

grevortex
Engager

Hi all,

I would like to know if there is a way to group multiple values from repeated fields that are coming in the same log, for example, taking into account the following log event containing the following data:

Log1: moduleName="Module A" moduleType="TypeA" moduleName="Module B" moduleType="TypeB"

Log2: moduleName="Module C" moduleType="TypeC" moduleName="Module A" moduleType="TypeA"

I tried something like:

app_search_criteria | stats count by moduleName | sort -count

But this way it's only bringing data for the first moduleName field it finds in one log and not for all of them, for example, I'm getting the following table:

moduleName         count

ModuleA                     1

ModuleC                     1

The ideal approach would be:

moduleName         moduleType       count

ModuleA                      TypeA                   2

ModuleB                      TypeB                   1

ModuleC                      TypeC                   1

Thanks in advance!

Labels (5)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust
app_search_criteria 
| rex max_match=0  "(?<nametype>moduleName=\"[^\"]+\" moduleType=\"[^\"]+\")"
| mvexpand nametype
| rex field=nametype "moduleName=\"(?<moduleName>[^\"]+)\" moduleType=\"(?<moduleType>[^\"]+)\""
| stats count by moduleName moduleType 
| sort -count

View solution in original post

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
app_search_criteria 
| rex max_match=0  "(?<nametype>moduleName=\"[^\"]+\" moduleType=\"[^\"]+\")"
| mvexpand nametype
| rex field=nametype "moduleName=\"(?<moduleName>[^\"]+)\" moduleType=\"(?<moduleType>[^\"]+)\""
| stats count by moduleName moduleType 
| sort -count
0 Karma

grevortex
Engager

Hi @ITWhisperer , thanks very much that did the trick!

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!

Quick connection discovery mode for forwarders

When a Splunk forwarder loses connectivity to its indexers, it does not always reconnect immediately. In many ...

Build and Launch AI Agents from Your Splunk Workflows

  Register We’ve all been there: juggling alerts, runbooks, and endless manual searches. What if you could ...

Splunk Cloud Application Management in Terraform

Register   On Tuesday, August 4 at 11AM PDT / 2PM EDT, we’re diving into how you can bring Infrastructure as ...