Splunk Search

I have developed a good search, but need to notify a recovery or alert depending on the output of the search. The difference between the two outcomes is just a couple of lines that I have not been able to configure in a single search

rcole2
New Member

Snippet of search
SEARCH
| eval runmacro = if(deltadif="NO","TurnTimeRecovered","TurnTimeWarning")
runmacro

comment(" +++++++++TurnTimeWarning
| where alertnamecount>0
| where alertnamecount=(count+1)
+++++++++++++++ ")

comment(" +++++++++TurnTimeRecovered
| where alertnamecount=0
| head 1
| where count=1
| where deltadif = "NO"
++++++++++++ ")

The macros exist and the comments above are the exact macros. From the 'deltadif' value I need to perform one of the above macros. This runs successfully, but it appears the macro is not executing. When I run each one inline, they function as expected, but require a unique search for each.
Can a variable be set as a macro and be called; if so how? Or is there a better solution?

0 Karma
1 Solution

woodcock
Esteemed Legend

Yes, like this:

.... | eval runmacro = if(deltadif="NO","`TurnTimeRecovered`","`TurnTimeWarning`")
| map search="search Other Stuff Here | `$runmacro$`"

View solution in original post

woodcock
Esteemed Legend

Yes, like this:

.... | eval runmacro = if(deltadif="NO","`TurnTimeRecovered`","`TurnTimeWarning`")
| map search="search Other Stuff Here | `$runmacro$`"

woodcock
Esteemed Legend

You can turn this inside-out and do the same thing with a subsearch:
http://docs.splunk.com/Documentation/Splunk/6.5.3/SearchTutorial/Useasubsearch

The 2 templatizing approaches are map and subsearch.

0 Karma

rcole2
New Member

That's what I wasn't considering -- running separate search. Thanks for the guidance; it does appear to give me what I'm looking for.

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...