Splunk Search

How to search for a specific field

balash1979
Path Finder

Here is the output of my log message:

{"line":"2019-11-21T22:09:29.982Z LCS   LCE [abc-75] INFO  i.r.queue.poller.SqsMessagePoller - Tags: {accountId=111222333, jobId=1002207394, cloudAccount=ABC-Cloud, jobAttributes={\"serviceIds\":[\"ABC\"]}, jobType=awsAccountService, custName=ABC}

How can I extract the cloudAccount and CustName from the above log so I can search like this:

index="*" | search cloudAccount=ABC-Cloud | search CustName=ABC ?

0 Karma
1 Solution

woodcock
Esteemed Legend

Like this:

| makeresults | eval _raw="{\"line\":\"2019-11-21T22:09:29.982Z LCS   LCE [abc-75] INFO  i.r.queue.poller.SqsMessagePoller - Tags: {accountId=111222333, jobId=1002207394, cloudAccount=ABC-Cloud, jobAttributes={\\\"serviceIds\\\":[\\\"ABC\\\"]}, jobType=awsAccountService, custName=ABC}"
| rex mode=sed "s/.*Tags:\s+//"
| kv
| search cloudAccount="ABC-Cloud" AND CustName="ABC"

View solution in original post

0 Karma

nikita_p
Contributor

Hi balash1979,
You can also directly extract fields from your search via Splunk UI using "Extract Fields". You can also check if your extractions are matching every field in the events.
You can refer the Splunk doc for the same:
https://docs.splunk.com/Documentation/Splunk/8.0.0/Knowledge/FXSelectSamplestep

0 Karma

woodcock
Esteemed Legend

Like this:

| makeresults | eval _raw="{\"line\":\"2019-11-21T22:09:29.982Z LCS   LCE [abc-75] INFO  i.r.queue.poller.SqsMessagePoller - Tags: {accountId=111222333, jobId=1002207394, cloudAccount=ABC-Cloud, jobAttributes={\\\"serviceIds\\\":[\\\"ABC\\\"]}, jobType=awsAccountService, custName=ABC}"
| rex mode=sed "s/.*Tags:\s+//"
| kv
| search cloudAccount="ABC-Cloud" AND CustName="ABC"
0 Karma

balash1979
Path Finder

I gave the log line as an example so using the makeresults wont work for me. Lets say I have different log lines with different custName and different cloudAccount, how can i do a generic search that will show me only the lines associated with cloudAccount="ABC-Cloud" ?

0 Karma

woodcock
Esteemed Legend

Sorry, the makeresults part is for demonstration/testing purposes. Your solution is lines 2-4. Just tack those onto your existing search.

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...