Splunk Search

Why am I getting an eval command error "The arguments to the match function are invalid"?

Taner
Engager

I would like to create a new panel in my Dashboard and I am using the following search string:

index=$index$ eventId=xy source="zz-json.log" (X-TRACE-ID="PV3*") OR (X-TRACE-ID="IPL*")| dedup X-TRACE-ID |
eval event=case(
match(X-TRACE-ID,"PV3"),"Option1",
match(X-TRACE-ID,"IPL"),"Option2") | chart count by event

Why do I get the error message: Error in "eval" command: The arguments to the „match“ function are invalid.

Could you please help me 😞 ?

Tags (1)
0 Karma
1 Solution

somesoni2
SplunkTrust
SplunkTrust

You should enclose field names with special characters within single quotes in eval and where clause. Like this

index=$index$ eventId=xy source="zz-json.log" (X-TRACE-ID="PV3*") OR (X-TRACE-ID="IPL*")| dedup X-TRACE-ID | 
eval event=case( 
match('X-TRACE-ID',"PV3"),"Option1", 
match('X-TRACE-ID',"IPL"),"Option2") | chart count by event

View solution in original post

somesoni2
SplunkTrust
SplunkTrust

You should enclose field names with special characters within single quotes in eval and where clause. Like this

index=$index$ eventId=xy source="zz-json.log" (X-TRACE-ID="PV3*") OR (X-TRACE-ID="IPL*")| dedup X-TRACE-ID | 
eval event=case( 
match('X-TRACE-ID',"PV3"),"Option1", 
match('X-TRACE-ID',"IPL"),"Option2") | chart count by event

Taner
Engager

It is working. Thank you very much 🙂

0 Karma

s2_splunk
Splunk Employee
Splunk Employee

The hyphens in your field names cause Splunk to evaluate the field as the expression X minus TRACE minus ID. Try adding | rename X-TRACE-ID as xtraceid after your dedup and use xtraceid in your match expressions and it should work as expected.

0 Karma

s2_splunk
Splunk Employee
Splunk Employee

response overlap with sbbadri, sorry for the dupe

0 Karma

sbbadri
Motivator

try below, i think - in XTRACEID created a issue.

index=$index$ eventId=xy source="zz-json.log" (X-TRACE-ID="PV3*") OR (X-TRACE-ID="IPL*")| dedup X-TRACE-ID | rename X-TRACE-ID as XTRACEID | eval event=case(
match(XTRACEID ,"PV3"),"Option1",
match(XTRACEID ,"IPL"),"Option2") | chart count by event

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

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

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...