Splunk Enterprise Security

pass field value in search as an argument to be used in a macro

hexerino
Explorer

Hi,

I am trying to figure out how to pass a field value in the search to a macro which interprets it and does further processing through a lookup table.

I have consulted multiple threads but due to karma cannot link to them. Currently my approach is as follows:

Search

index=my_index my_custom_field="the_value_to_filter_for" | map search="|`my_processing_macro($my_custom_field_)`"

Macro: my_processing_macro(1) (argument defined as name)

lookup my_lookup_table_def $name$ as lookup_table_column1

Lookup table (CSV-format): linked to lookup table definition

lookup_table_column1,lookup_table_column2
value_i_pass_in_macro, value_i_want_returned

So in short, the value I pass in my_custom_field corresponds to a column1 row in the lookup table. Basically column 2 contains the regex or other macro's to expand during processing.

0 Karma

lakshman239
Influencer

The below search should work .. are you seeing any errors? You need $$ and test your macros by using both |yourmacro(1)` pipe and without pipe and adjust

index=my_index my_custom_field="the_value_to_filter_for" | map search=" search `my_processing_macro($my_custom_field$)`"
0 Karma

hexerino
Explorer

After long deliberation we decided to adopt a different filtering strategy. This method worked after some alteration. Thank you for your suggestion !

0 Karma

lakshman239
Influencer

Glad it helped. Pls vote to accept the comment/answers and also post your answers for future readers.

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


Introducing Unified TDIR with the New Enterprise Security 8.2

Read the blog
Get Updates on the Splunk Community!

Thanks for the Memories! Splunk University, .conf25, and our Community

Thank you to everyone in the Splunk Community who joined us for .conf25, which kicked off with our iconic ...

Data Persistence in the OpenTelemetry Collector

This blog post is part of an ongoing series on OpenTelemetry. What happens if the OpenTelemetry collector ...

Introducing Splunk 10.0: Smarter, Faster, and More Powerful Than Ever

Now On Demand Whether you're managing complex deployments or looking to future-proof your data ...