Splunk Search

How can I escape dollar-signs to use "map" or "sendemail" inside of a macro or workflow?

woodcock
Esteemed Legend

All 4 things use the $argument$ syntax. I am trying to use sendemail inside of a macro and have tried \$search\$, $$search$$, and $$$search$$$ but none works. Is it even possible?

My macro is this:

sendemail
sendresults=true
inline=true
graceful=true
to=whatever@gmail.com
subject="subject"
message="This report alert was generated by search $name$ in $app$ Splunk with this search string: $search$"

And the $name$, $app$, and $search$ are being eaten.

See dox here:
https://docs.splunk.com/Documentation/Splunk/latest/Alert/EmailNotificationTokens

ejwade
Contributor

I'm having the same issue, @woodcock. Let me know if you figured it out (you usually do). 🙂

0 Karma

SanjayReddy
SplunkTrust
SplunkTrust

Hi @ejwade 

I’m a Community Moderator in the Splunk Community.

you are replying to question was posted couple of  years ago, so it might not get the attention you need for your question to be answered. We recommend that you post a new question with errors so that your issue can get the  visibility it deserves. To increase your chances of getting help from the community, follow these guidelines in the Splunk Answers User Manual when creating your post.

Thank you! 

0 Karma

PickleRick
SplunkTrust
SplunkTrust

And back to the original question - I suspect it's just how it works. Macro expansion is after all just a simple string substitution, there is no complicated magic behind it. If it's something that could be useful, you might consider posting an idea on https://ideas.splunk.com

woodcock
Esteemed Legend

Let me restate my problem. There are multiple things in Splunk that use the $argument$ syntax. The question is: how do I get 2 of those things to work together when they both think that $argument$ is for him. In this case, the 2 things are macro and sendemail. How do I get macro not to mess up the arguments that are intended for sendemail.

0 Karma

efavreau
Motivator

@woodcock It's difficult for me to test. It's sparked a lot of conversation over here. I see someone else can't test it. Do you think you could work this into a run anywhere example of where you are so far? Then people could test in parallel. At a minimum, we could comment on what we tried and what didn't work. At the most, we'd find the solution. Thoughts?

###

If this reply helps you, an upvote would be appreciated.
0 Karma

efavreau
Motivator

@woodcock I'm not clear on what you mean. I have a simple search:

index=_internal sourcetype=splunkd_access user=efavreau |  stats count

Created a macro:
name: testsendemail(3)
definition: sendemail sendresults=true inline=true graceful=true to=me@me.com subject="subject" message="This report alert was generated by search $name$ in $app$ Splunk with this search string: $search$ "
args: name, app, search

Put it all together:

index=_internal sourcetype=splunkd_access user=efavreau 
|  stats count
| `testsendemail(mytest,FOOAPP,"index=_internal sourcetype=splunkd_access user=efavreau |  stats count")`

Ran it in the GUI and that worked for me in v6.6.6. So then I scheduled the report on a cron * * * * * , and that worked too.
Am I missing something?

###

If this reply helps you, an upvote would be appreciated.
0 Karma

woodcock
Esteemed Legend

Let me clarify. I get the email, but the 3 variables do not get dereferenced; they get dropped altogether. so the message should be This report alert was generated by search This Is The Search Name in AppName Splunk with this search string: index=foo sourcetype=bar ... but instead I get This report alert was generated by search in Splunk with this search string:.

0 Karma

woodcock
Esteemed Legend

Wait a minute. I think I have the answer. As long as the variables for the "other" thing do not match the names of the arguments of my macro, my macro should ignore them (I think)! Testing now...

0 Karma

woodcock
Esteemed Legend

Did not work.

0 Karma

skalliger
Motivator

Isn't the "!" the correct escape character here? Got nothing to test right now..
I think it's $!variable$

0 Karma

woodcock
Esteemed Legend

This is also a problem for ldapsearch command as documented (and solved!) here: https://answers.splunk.com/answers/223246/workflow-action-contains-other-variables-how-do-i.html
Unfortunately, the solution was to use a macro!

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

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...

Unlock What’s Next: The Splunk Cloud Platform at .conf25

In just a few days, Boston will be buzzing as the Splunk team and thousands of community members come together ...