Getting Data In

Is there an SPL command using REST to list the macros contained within a macro?

kdwsplunk
Explorer

Hello, I see that we can use SPL to get a list of arguments, "args", of a macro using the "rest" command.

| rest /services/configs/conf-macros

It would be great to be able to list all the dependencies of a macro.


In particular, is there a way to use the "rest" command to get a list of macros depended upon by another macro?


For instance, is it possible to get the following output? (See the third column "macros_called_by_macro".)

|---- args ----|---- title ----|---- macros_called_by_macro ---| --- author --- | --- definition --- |
|              |     macro_01  |    macro_02, macro_03         |
|              |     macro_02  |    macro_04                   |
|              |     macro_03  |                               |

Thanks so much!!!

somesoni2
Revered Legend

AFAIK, there are no such rest end point, not event for other knowledge objects (e.g. saved searches, dashboards etc) which will list dependencies. The rest queries just give details about current object. You probably have to parse it's definition to find any other macro invocation and then run some stats to get the table you expect.

DalJeanis
Legend

Try this...

| rest /services/configs/conf-macros 
| rex field=definition max_match=0 "\`(?<themacros>[^\`\(]*)[\`\(]" 
| rex field=id "(?<title>[^\/]*)$"
| table args title them* author definition

Then, depending on what you want to do next, you could put commas between the multiple values...

| eval themacros=mvjoin(themacros,", ")

kdwsplunk
Explorer

Thank you for your suggestion. ...Great approach!

I tried it and found that the REGEX on line #2 above just needs an adjustment because sometimes it grabs more than just the macro name. I'm currently getting up-to-speed on REGEX so that I can post an adjustment. I only have a partial suggestion at the moment. This suggestion grabs the macro name as well as the macro argument:

2. | rex field=definition max_match=0 "\`(?<themacros>[^`]*)\`"

I would like to figure out how to get rid of the argument (that is, the parentheses that follow the macro name, as well as the contents of the parentheses.

For example, the current result is:

macro_name(macro_argument)

But I would like to get the following result:

macro_name

Thank you again for your approach! Very nice!!!

0 Karma

landen99
Motivator
`(?<!\)`)(?<macros>[a-zA-Z][^`\(]*)[\(`]
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Laser Bananas and Edge Hubs: Exploring Operational Technology (OT) Data Through a ...

  OT is a different environment to traditional IT and can have interesting challenges when interfacing the ...

Event Series: Mastering AI Tokenomics and Splunk Agent Observability

Beyond the Black Box: Correlating AI Performance and Tokenomics with Splunk Agent Observability   As ...

span_metrics: The OpenTelemetry-Idiomatic Way to See Inside Your Services

You open a trace in Splunk Observability Cloud and everything looks fine. One root span, order-pipeline, with ...