All of these answers are excellent, but just to add a little more colour to subsearches ...
Any time you use a subsearch, think of it like backticks in the unix shell. (If you don't get that reference then look at https://unix.stackexchange.com/questions/27428/what-does-backquote-backtick-mean-in-commands ) So the thing inside the subsearch runs, and then its output textually replaces the subsearch itself. (Commands like foreach , apppend , join , etc that use subsearch syntax don't necessarily apply here. This is the context of using a subsearch as part of search criteria)
Subsearches normally return field-value pairs. You can cheat to see what a subsearch is going to return by running it in conjunction with the format command.
Like suppose I had a lookup file like your example:
src_ip,servername
1.2.3.4,server1
5.6.7.8,server2
9.10.11.12,server3
If I do a | inputlookup serverlist.csv then I see the CSV file itself as a search result. But if I do a | inputlookup serverlist.csv | format then I get something different / more interesting ...
( ( servername="server1" AND src_ip="1.2.3.4" ) OR ( servername="server2" AND src_ip="5.6.7.8" ) OR ( servername="server3" AND src_ip="9.10.11.12" ) )
This gives me a picture of what a search like:
sourcetype=pan:traffic index=firewalls [ | inputlookup serverlist.csv ]
Will look more like this after the subsearch has returned:
sourcetype=pan:traffic index=firewalls ( ( servername="server1" AND src_ip="1.2.3.4" ) OR ( servername="server2" AND src_ip="5.6.7.8" ) OR ( servername="server3" AND src_ip="9.10.11.12" ) )
Ultimately, this probably won't return ANYTHING because pan:traffic likely does not have a field named servername . What if I instead ran:
sourcetype=pan:traffic index=firewalls [ | inputlookup serverlist.csv | fields src_ip ]
The return command works similarly to format and outside of a subsearch will give you an idea of what it is up to as well. Compare:
| inputlookup serverlist.csv | return src_ip
to
| inputlookup serverlist.csv | return 1000 src_ip
One other thing that is interesting about subsearches is that return is not required! If you don't call return then as I demonstrated above, some default functionality happens. Another piece of default functionality includes specially named fields. If your subsearch outputs a field named query then the field name disappears from the subsearch output., like so:
| inputlookup serverlist.csv | fields src_ip | rename src_ip as query | format
will return
( ( "1.2.3.4" ) OR ( "5.6.7.8" ) OR ( "9.10.11.12" ) )
"Look ma, no field names!"
Hopefully this helps you peer a little more into how your subsearches are working....
... View more