Splunk Search

Why is eval searchmatch giving me a "the expression is malformed" error?

TJemisonIpacc
Explorer

Hello,

I'm trying to use the searchmatch command to create a field that has two values, success and exceptions. I am also using the count command to count the number the successes and exceptions after the field has been created. This is my current search:

host="inf012prd*.ipacc.com" source="/logging/PaymentsServiceV3/inf012prd*.ipacc.com/ipacc.log" OR  source="/logging/PaymentsServiceV3/inf012prd*.ipacc.com/error.log" | eval Payments=if(searchmatch("source=/logging/PaymentsServiceV3/inf012prd*.ipacc.com/ipacc.log" "*Payment Request: *")"Success",STATE) | eval Errors=if(searchmatch("source=/logging/PaymentsServiceV3/inf012prd*.ipacc.com/error.log")"Exceptions",STATE)| timechart span=1d count(Success) as Success, count(Errors) as Errors

Yet, each time I run the search, I only get this:

Error in 'eval' command: The expression is malformed. Expected ).

What is wrong with my syntax? Any help is appreciated.

Tags (3)
0 Karma
1 Solution

woodcock
Esteemed Legend

You are missing some commas; try this:

host="inf012prd*.ipacc.com" source="/logging/PaymentsServiceV3/inf012prd*.ipacc.com/ipacc.log" OR source="/logging/PaymentsServiceV3/inf012prd*.ipacc.com/error.log" | eval Payments=if(searchmatch("source=/logging/PaymentsServiceV3/inf012prd*.ipacc.com/ipacc.log" "*Payment Request: *"),"Success",STATE) | eval Errors=if(searchmatch("source=/logging/PaymentsServiceV3/inf012prd*.ipacc.com/error.log"),"Exceptions",STATE)| timechart span=1d count(Success) as Success, count(Errors) as Errors

View solution in original post

woodcock
Esteemed Legend

You are missing some commas; try this:

host="inf012prd*.ipacc.com" source="/logging/PaymentsServiceV3/inf012prd*.ipacc.com/ipacc.log" OR source="/logging/PaymentsServiceV3/inf012prd*.ipacc.com/error.log" | eval Payments=if(searchmatch("source=/logging/PaymentsServiceV3/inf012prd*.ipacc.com/ipacc.log" "*Payment Request: *"),"Success",STATE) | eval Errors=if(searchmatch("source=/logging/PaymentsServiceV3/inf012prd*.ipacc.com/error.log"),"Exceptions",STATE)| timechart span=1d count(Success) as Success, count(Errors) as Errors

TJemisonIpacc
Explorer

Unfortunately, that didn't work. Maybe it's something else? The parentheses seem to match up fine...

0 Karma

woodcock
Esteemed Legend

You are correct, it also has a problem with double-quotes. Try this:

host="inf012prd*.ipacc.com" source="/logging/PaymentsServiceV3/inf012prd*.ipacc.com/ipacc.log" OR source="/logging/PaymentsServiceV3/inf012prd*.ipacc.com/error.log" | eval Payments=if(searchmatch("source=/logging/PaymentsServiceV3/inf012prd*.ipacc.com/ipacc.log *Payment Request: *"),"Success",STATE) | eval Errors=if(searchmatch("source=/logging/PaymentsServiceV3/inf012prd*.ipacc.com/error.log"),"Exceptions",STATE)| timechart span=1d count(Success) as Success, count(Errors) as Errors

TJemisonIpacc
Explorer

That did it. Thank you, woodcock.

0 Karma
Get Updates on the Splunk Community!

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...

Splunk APM: New Product Features + Community Office Hours Recap!

Howdy Splunk Community! Over the past few months, we’ve had a lot going on in the world of Splunk Application ...

Index This | Forward, I’m heavy; backward, I’m not. What am I?

April 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...