Splunk Search

How to use a value created with eval to search my events for a particular line of text?

Aaron_Fogarty
Path Finder

Hi,

I am trying to use a value from an eval as search data. I am searching my events for a particular line of text and not by a field or value.

This search will return any events with the text "DeployError" without using an eval

index="123" sourcetype="abc" host="xyz" source=$sourceType$  "DeployError" User | timechart count by User

Based on the $sourceType$ token, the eval will have a different value. I would like to make the same type of search as above with the eval value. This is what I have tried, but it does not work.

index="123" sourcetype="abc" host="xyz" source=$sourceType$ User | eval errorType=case(source=="/logs/proxy-service.log","\"DeployError\"", source=="/logs/service.log","\"BuildError\"")| search errorType | timechart count by User

Any help here would be much appreciated. Thanks

0 Karma

sundareshr
Legend

Its possibly a typo in here, but your search errorType will only return events with the text errorType. Should be search errorType=*

0 Karma

somesoni2
Revered Legend

You would need to use a subsearch, like this
Updated

 index="123" sourcetype="abc" host="xyz" source=$sourceType$ User [ | gentimes start=-1 | eval search=case(match("$sourceType$","/logs/proxy-service.log"),"\"DeployError\"", match("$sourceType$","/logs/service.log"),"\"BuildError\"",1=1," ") | table search ] | timechart count by User
0 Karma

Aaron_Fogarty
Path Finder

Hey somesoni2,

Thanks for your answer, I gave this a try but I am still getting no results found.

0 Karma

somesoni2
Revered Legend

Try the updated answer. Also, could you provide some sample value for the field source? Does it match exactly with "/logs/proxy-service.log"?

0 Karma

Aaron_Fogarty
Path Finder

Hey somesoni2,

Thanks again, but still no joy. Yes the source and value are the exact same, what I have provided here is made up values of what I cam doing, for confidentiality, but everything does match exactly in the real version.

index="123" sourcetype="abc" host="xyz" source=$sourceType$ User | eval errorType=case(source=="/logs/proxy-service.log","\"DeployError\"", source=="/logs/service.log","\"BuildError\"")| search errorType | timechart count by User
0 Karma
Get Updates on the Splunk Community!

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...