Splunk Search

Issue with using "search IN" command within map

Kristian_86
Explorer

Hello,
I have the following issue, do you know any solution or workaround?
(Or maybe I declared something wrongly...)
When using a comma separated field values in MAP within the IN command, it is not working from the outer search. But when I write out the value of that outside field, it is recognized.

 

| makeresults
| eval ips="a,c,x"
| map [
  | makeresults
  | append [ makeresults | eval ips="a", label="aaa" ]
  | append [ makeresults | eval ips="b", label="bbb" ]
  | append [ makeresults | eval ips="c", label="ccc" ]
  | append [ makeresults | eval ips="d", label="ddd" ]
  ```| search ips IN ($ips$)```           ```NOT WORKING```
  | search ips IN (a,c,x)           ```WORKING```
  | eval outer_ips=$ips$
] maxsearches=10

 

 

Labels (2)
0 Karma
1 Solution

bowesmana
SplunkTrust
SplunkTrust

Most likely because the substitution is passing $ips$ as the string "a,c,x" and if you search for 

| search ips IN ("a,c,x")

you also get no results

You could do it differently using where, for example this works

| eval outer_ips=split($ips$, ",")
| where ips=outer_ips

or this

| where match($ips$, ips)

assuming your use case is IP addresses, the where option also allows for cirdmatch if that is useful.

 

View solution in original post

bowesmana
SplunkTrust
SplunkTrust

Most likely because the substitution is passing $ips$ as the string "a,c,x" and if you search for 

| search ips IN ("a,c,x")

you also get no results

You could do it differently using where, for example this works

| eval outer_ips=split($ips$, ",")
| where ips=outer_ips

or this

| where match($ips$, ips)

assuming your use case is IP addresses, the where option also allows for cirdmatch if that is useful.

 

Kristian_86
Explorer

Thank you for your answer, it helped me out. 🙂
The final version was a bit more trickier as in the ips field can be an "*" instead of any listed values and in that case any of the found values should be considered.
So this was the final solution:

 

| makeresults
| eval ips="a,c,x"
```| eval ips="*"```
| eval ips=replace(ips, "\*", "%")
| map [
  | makeresults
  | append [ makeresults | eval ips="a", label="aaa" ]
  | append [ makeresults | eval ips="b", label="bbb" ]
  | append [ makeresults | eval ips="c", label="ccc" ]
  | append [ makeresults | eval ips="d", label="ddd" ]
  | eval outer_ips=split("$ips$", ",")
  | where (ips=outer_ips OR LIKE(ips, "$ips$"))
```with the above conditon when only a * (%) is there as a value it will catch it with the LIKE. when some other value then the first condition will catch the proper events)```
] maxsearches=10

 

0 Karma

bowesmana
SplunkTrust
SplunkTrust

Just as an aside on the use of map, note that it is not a practical command for use on large datasets, as each map result gets executed in its own serial search, so it can take time and depending on the search can cause a lot of overhead to iterate through large result sets. 

Often there is an alternative way to write the search (but not always). Depends on the use case.

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Take Action Automatically on Splunk Alerts with Red Hat Ansible Automation Platform

 Are you ready to revolutionize your IT operations? As digital transformation accelerates, the demand for ...

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...