Splunk Search

How to transpose based on regex data to get the counts

kuul13
Engager

Hi,

I am new to Splunk. I am trying to figure out how to extract count of errors per api calls made for each client.

I have following query that i run :

`index=application_na sourcetype=my_logs:hec source=my_Logger_PROD  retrievePayments* ( returncode=Error OR returncode=Communication_Error) | rex field=message "Message=.* \((?<apiName>\w+?) -" |  lookup My_Client_Mapping client | table ClientName, apiName'

This query parses message to extract the apinames that starts with `retrievePayments`.  And shows this kind of results

ClientName  apiName

Client A          retrievePaymentsA

Client B          retrievePaymentsA

Client C         retrievePaymentsB

Client A         retrievePaymentsB

 

I want to see an output where my wildcard apiName are transposed and show error count for every client. 

Client      retrievePaymentsA    retrievePaymentsB     retrievePaymentsC    retrievePaymentsD

Client A  2                                     5                                             0                                         1

Client B  2                                     2                                             1                                         6

Client C  8                                     3                                             0                                         0

Client D  1                                     0                                            4                                         3

Any help would be appreciated.

Labels (3)
0 Karma
1 Solution

bowesmana
SplunkTrust
SplunkTrust

@kuul13 

This is a straightforward use of the chart command, see this run anywhere example

| makeresults count=20
| fields - _time
| eval ClientName=mvindex(split("ABC",""), random() % 3)
| mvexpand ClientName
| eval ClientName="Client ".ClientName
| eval apiName="retrievePayments".mvindex(split("ABCD",""), random() % 4)
| chart count over ClientName by apiName

This sets up some example data and then uses the chart command do to the tabling you need.

View solution in original post

0 Karma

bowesmana
SplunkTrust
SplunkTrust

@kuul13 

This is a straightforward use of the chart command, see this run anywhere example

| makeresults count=20
| fields - _time
| eval ClientName=mvindex(split("ABC",""), random() % 3)
| mvexpand ClientName
| eval ClientName="Client ".ClientName
| eval apiName="retrievePayments".mvindex(split("ABCD",""), random() % 4)
| chart count over ClientName by apiName

This sets up some example data and then uses the chart command do to the tabling you need.

0 Karma
Get Updates on the Splunk Community!

Index This | I’m short for "configuration file.” What am I?

May 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with a Special ...

New Articles from Academic Learning Partners, Help Expand Lantern’s Use Case Library, ...

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Your Guide to SPL2 at .conf24!

So, you’re headed to .conf24? You’re in for a good time. Las Vegas weather is just *chef’s kiss* beautiful in ...