Splunk Search

How do I search for events that match a regex OR have Key?

splunkqy
Explorer

Say I have an event in the form:

{
    "a": {"b": "c"},
    "d": "e"
 }

I want to include the event if "c" matches a regex or if the value "e" is not null or empty.

How do I write a query for this? As far as I know, you can only find events matching a regex by using | regex <regular expression>. Is there a way to do this like (d != "" AND d != null) OR ( a.b AND | regex <regular expression>)?

0 Karma
1 Solution

chrisyounger
SplunkTrust
SplunkTrust

I would recommend you use the rex command : |rex field=WHATEVER "(?<my_new_field>MATCH_TO_CHECK)"

This will simplify your conditional logic becuase you can just do:

eval includeRecord = if((d != "" AND d != null) OR ( a.b AND isnotnull(my_new_field)), "true", "false") | search includeRecord=true

Hope you can understand my untested code 🙂

View solution in original post

0 Karma

chrisyounger
SplunkTrust
SplunkTrust

I would recommend you use the rex command : |rex field=WHATEVER "(?<my_new_field>MATCH_TO_CHECK)"

This will simplify your conditional logic becuase you can just do:

eval includeRecord = if((d != "" AND d != null) OR ( a.b AND isnotnull(my_new_field)), "true", "false") | search includeRecord=true

Hope you can understand my untested code 🙂

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 ...