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!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...