Splunk Search

Run macro commands from lookup

apiprek2
Explorer

Hi

I'm wondering if it's possible to define and execute a macro from a lookup.  I have an index with several (about 50) user actions, which aren't named in a user friendly manner.  Additionally, each action has different fields, which I'd like to extract using inline rex queries.  In short, I'd like a table with the following:

TimeUserNameMessage
10:00 a.m.JohnDoeThis is action1.  Details for action1.
10:01 a.m.JohnDoeThis is action2.  Details for action2.
10:02 a.m. JohnDoeThis is action3.  Details for action3.

 

I know can define a friendly name for the action using a lookup.  I can also do the rex field extractions and compose a details field using a macro for each action.  However, is there a way to also rex the fields and define the details in a lookup?  

I was thinking of creating a lookup like this:

ActionFriendlyDescriptionMacroDefinition
action1"This is action1"| rex to extract fields for action1 | eval for Details for action1
action2"This is action2"| rex to extract fields for action2 | eval for Details for action2
action3"This is action3"| rex to extract fields for action3 | eval for Details for action3

 

I was thinking about something like this:

 

index=MyIndex source=MySource

| lookup MyLookup.csv ActionId OUTPUT FriendlyDescription, MacroDefinition

`code to execute MacroDefinition`

|table _time, UserName, FriendlyDescription, Details for action

 

I'm not sure if i'm barking up the wrong tree, but the reason I'd like to do this in one place (a lookup) instead of 50 different macro definitions.  It'd be neat to have all the code in one place.

Thanks!

 

 

 

 

 

 

Labels (1)
Tags (3)
0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Macros are expanded before the resultant SPL is parsed and executed which probably means that macros stored in a lookup are not expanded.

0 Karma

apiprek2
Explorer

That's what i'm finding as well.  I'm curious if there's a round-about way to do this.  Maybe using that string as a token in a dashboard?

0 Karma
Get Updates on the Splunk Community!

Observe and Secure All Apps with Splunk

  Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...

Splunk Decoded: Business Transactions vs Business IQ

It’s the morning of Black Friday, and your e-commerce site is handling 10x normal traffic. Orders are flowing, ...

Fastest way to demo Observability

I’ve been having a lot of fun learning about Kubernetes and Observability. I set myself an interesting ...