Knowledge Management

how to make a reusable macro which replaces field text

SimonKof
New Member

I have a splunk dashboard which shows metrices for an API.

The dashboard have a graph showing response times and a table showing min, max, average of response times. They both include the following eval in the search to group endpoints with ids in the url.

eval endpoint = replace(endpoint,"user\/\d+\/address","user/{id}/address")

This way the calls to /user/12345/address and /user/98765/address will be grouped as /user/{id}/address.

How do I create a macro that I can use to extract this functionality so it can be used in several dashboard panel searches? For example:

index=api
| eval endpoint = replace(endpoint,"user\/\d+\/address","user/{id}/address") 
| timechart span=1h count by endpoint

and

index=api 
| eval endpoint = replace(endpoint,"user\/\d+\/address","user/{id}/address")  
| stats Count, min(executiontime), max(executiontime), avg(executiontime), stdev(executiontime) by endpoint 
| sort - count 
| head 20

I would like it to have a macro called group_endpoints so I can simplify the above to something similar to:

index=api
| group_endpoints(endpoints)
| timechart span=1h count by endpoint
0 Karma

niketn
Legend

@SimonKof, is this question different from https://answers.splunk.com/answers/626482/extracting-eval-for-reuse-in-other-searches.html?

If you can use Calculated Fields to make the above eval reusable, will you still need a macro to do something similar?

If Calculated Fields solves your need let us know and this question can be closed as duplicate.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma
Get Updates on the Splunk Community!

Detecting Remote Code Executions With the Splunk Threat Research Team

REGISTER NOWRemote code execution (RCE) vulnerabilities pose a significant risk to organizations. If ...

Observability | Use Synthetic Monitoring for Website Metadata Verification

If you are on Splunk Observability Cloud, you may already have Synthetic Monitoringin your observability ...

More Ways To Control Your Costs With Archived Metrics | Register for Tech Talk

Tuesday, May 14, 2024  |  11AM PT / 2PM ET Register to Attend Join us for this Tech Talk and learn how to ...