Splunk Search

How to extract bunch of UUIDs from a string using regex?

Splunk_321
Path Finder

Hi,

I have a string in splunk logs something like below.

msg.message="Matches Logs :: Logger{clientId='hFKfFkF-K7jlp5epzCnZASazoYmXxgUzBLQ8cixb7f23afb8', apiName='Matches', apiStatus='Success', error='NA', locationIdMerchDetail=[6d65fcb6-8885-4f56-93c1-7050c8bef906 :: QUALITY COLLISION 1 LLC :: 1, e5ff5b47-839c-4ed0-86a3-87fc18f4bfda :: P A JOLLY'S LLC :: 2, 2053428f-f6ba-4038-a03e-4dbc8737c37d :: CREATIVE EXCELLENCE SALON LLC :: 3, c3e9e6fc-8388-49fd-ba7b-3b9d76f5f9ea :: QUALITY SERVICES AND APP :: 4, 75ca5712-f7a1-4a63-a69f-d73c8e7d187b :: FREEDOM COMICS LLC :: 5, e87a96e8-de73-47f8-bfbd-6099c83376f7 :: S AND G STORES LLC :: 6, 732f9d61-3916-4664-9601-dd0745b68837 :: QUALITY RESALE :: 7, d666bef7-e2fa-498f-a74f-e80f6d2701e7 :: CAKE ART SUPPLIES LLC :: 8, 23ca4856-5908-4bd6-b90d-cace07036b05 :: INTUIT PAYMENT SOLUTIONS, LLC :: 9, b583405f-bb3d-4dba-9bb3-ee9b3713b8f7 :: LA FIESTA TOLEDO LLC :: 10], numReturnedMatches='10'}"

My string contains locationIdMerchDetail as highlighted above. I need to extract locationId, rank into table first item being locationid and last item being rank in every comma separated item.

Ex: In 6d65fcb6-8885-4f56-93c1-7050c8bef906 :: QUALITY COLLISION 1 LLC :: 1

locationId : 6d65fcb6-8885-4f56-93c1-7050c8bef906

rank: 1

I am able to extract locationIds into table, using below query, but not sure how to include corresponding rank

######################################

index=app_pcf AND cf_app_name="credit-analytics-api" AND message_type=OUT AND msg.logger=c.m.c.d.MatchesApiDelegateImpl | rex field=msg.message "(?<LocationId>[0-9a-f]{8}-([0-9a-f]{4}\-){3}[0-9a-f]{12})" | table LocationId

######################################

I want a table something like below.

LocationId rank

6d65fcb6-8885-4f56-93c1-7050c8bef906 1

e5ff5b47-839c-4ed0-86a3-87fc18f4bfda 2

2053428f-f6ba-4038-a03e-4dbc8737c37d 3

..............................................................................................................

and so on

Any regex to filter these into table.

Please help.

Labels (2)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Assuming the "extra" comma after "PAYMENT SOLUTIONS" is just a typo, you could try this:

| rex max_match=0 "locationIdMerchDetail=\[(?<details>[^\]]+?)\]"
| eval locationIdRank=split(details,",")
| mvexpand locationIdRank
| rex field=locationIdRank "(?<locationId>\S+).*(?<rank>\d+)"
| table locationId rank

View solution in original post

yuanliu
SplunkTrust
SplunkTrust

As always, I advise not to use string manipulation to handle structured data like this. If you talk with your developer, they'll tell you that this is a clever way to embed a JSON object into the log. I'm sure you already have a field named msg.messages. If you unwrap the JSON object, you'll get all fields that your developers want you to use. Not only data set is richer, but you'll not worry about future changes that developers may make to their logs.

This is how you can do it.

| eval logs = replace('msg.message', "^[^{]+", "") ``` retain embedded JSON only ```
``` unwrap several levels of escapements below ```
| eval logs = replace(logs, " *([^{=,]+)=", "\"\1\":")
| eval logs = replace(logs, ":'([^']+)'([,}])", ":\"\1\"\2")
| eval logs = replace(logs, " *([^\[:]+::[^:]+::[^,\]]+)([,\]])", "\"\1\"\2")
``` | eval valid = if(json_valid(logs), "yes", "not") ```
| spath input=logs
| mvexpand locationIdMerchDetail{}
| eval locationIdMerchDetail = split('locationIdMerchDetail{}', " :: ")
| eval locationId = mvindex(locationIdMerchDetail, 0)
| eval MerchDetail = mvindex(locationIdMerchDetail, 1)
| eval rank = mvindex(locationIdMerchDetail, 2)

Splunk_321
Path Finder

Great approach to filter the required data. Appreciate your help. Btw, I was the developer who is new to splunk😄

0 Karma

yuanliu
SplunkTrust
SplunkTrust

With that, your sample data gives

MerchDetailapiNameapiStatusclientIderrorlocationIdnumReturnedMatchesrank
QUALITY COLLISION 1 LLCMatchesSuccesshFKfFkF-K7jlp5epzCnZASazoYmXxgUzBLQ8cixb7f23afb8NA6d65fcb6-8885-4f56-93c1-7050c8bef906101
P A JOLLY'S LLCMatchesSuccesshFKfFkF-K7jlp5epzCnZASazoYmXxgUzBLQ8cixb7f23afb8NAe5ff5b47-839c-4ed0-86a3-87fc18f4bfda102
CREATIVE EXCELLENCE SALON LLCMatchesSuccesshFKfFkF-K7jlp5epzCnZASazoYmXxgUzBLQ8cixb7f23afb8NA2053428f-f6ba-4038-a03e-4dbc8737c37d103
QUALITY SERVICES AND APPMatchesSuccesshFKfFkF-K7jlp5epzCnZASazoYmXxgUzBLQ8cixb7f23afb8NAc3e9e6fc-8388-49fd-ba7b-3b9d76f5f9ea104
FREEDOM COMICS LLCMatchesSuccesshFKfFkF-K7jlp5epzCnZASazoYmXxgUzBLQ8cixb7f23afb8NA75ca5712-f7a1-4a63-a69f-d73c8e7d187b105
S AND G STORES LLCMatchesSuccesshFKfFkF-K7jlp5epzCnZASazoYmXxgUzBLQ8cixb7f23afb8NAe87a96e8-de73-47f8-bfbd-6099c83376f7106
QUALITY RESALEMatchesSuccesshFKfFkF-K7jlp5epzCnZASazoYmXxgUzBLQ8cixb7f23afb8NA732f9d61-3916-4664-9601-dd0745b68837107
CAKE ART SUPPLIES LLCMatchesSuccesshFKfFkF-K7jlp5epzCnZASazoYmXxgUzBLQ8cixb7f23afb8NAd666bef7-e2fa-498f-a74f-e80f6d2701e7108
INTUIT PAYMENT SOLUTIONS, LLCMatchesSuccesshFKfFkF-K7jlp5epzCnZASazoYmXxgUzBLQ8cixb7f23afb8NA23ca4856-5908-4bd6-b90d-cace07036b05109
LA FIESTA TOLEDO LLCMatchesSuccesshFKfFkF-K7jlp5epzCnZASazoYmXxgUzBLQ8cixb7f23afb8NAb583405f-bb3d-4dba-9bb3-ee9b3713b8f71010
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Assuming the "extra" comma after "PAYMENT SOLUTIONS" is just a typo, you could try this:

| rex max_match=0 "locationIdMerchDetail=\[(?<details>[^\]]+?)\]"
| eval locationIdRank=split(details,",")
| mvexpand locationIdRank
| rex field=locationIdRank "(?<locationId>\S+).*(?<rank>\d+)"
| table locationId rank
Get Updates on the Splunk Community!

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 ...

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...