Splunk Search

How to include arguments in search macros with non-alphanumeric values

cherrypick
Path Finder

I have arguments for my macro that contain other values e.g. $env:user$ and $timepicker.earliest$/$timepicker.latest$. How do I include these in my macro definition as it doesn't allow me since macro arguments must only contain alphanumeric, '_' and '-' characters?

 

 

Labels (1)
0 Karma
1 Solution

yuanliu
SplunkTrust
SplunkTrust

Use macro params to pass these tokens.  Here is an example:

NameDefinitionArguments
non-alphabetic-token(2)index=_internal earliest=$earliest_tok$ latest=$latest_tok$earliest_tok, latest_tok

 

<form version="1.1" theme="light">
  <label>Non-alphabetic tokens</label>
  <description>https://community.splunk.com/t5/Splunk-Search/How-to-include-arguments-in-search-macros-with-non-alphanumeric/m-p/696333#M236667</description>
  <fieldset submitButton="false">
    <input type="time" token="timepicker" searchWhenChanged="true">
      <label>pick time</label>
      <default>
        <earliest>-15m</earliest>
        <latest>now</latest>
      </default>
    </input>
  </fieldset>
  <row>
    <panel>
      <title>$timepicker.earliest$</title>
      <table>
        <search>
          <query>`non-alphabetic-token($timepicker.earliest$, $timepicker.latest$)`
| addinfo
| stats count by info_min_time info_max_time
| foreach info_*
    [eval &lt;&lt;FIELD&gt;&gt; = strftime(&lt;&lt;FIELD&gt;&gt;, "%F %T")]</query>
          <earliest>-24h@h</earliest>
          <latest>now</latest>
        </search>
        <option name="drilldown">none</option>
        <option name="refresh.display">progressbar</option>
      </table>
    </panel>
  </row>
</form>

 

Here are some sample interactions:

non-alphabetic-token-recent.png

non-alphabetic-token-past.png

  

View solution in original post

0 Karma

PickleRick
SplunkTrust
SplunkTrust

I'm not sure you understand the macros correctly.

if you define a macro with two parameters paramA and paramB it will get substituted in your search with whatever values you specify for them. These are separate layers.

0 Karma

yuanliu
SplunkTrust
SplunkTrust

Use macro params to pass these tokens.  Here is an example:

NameDefinitionArguments
non-alphabetic-token(2)index=_internal earliest=$earliest_tok$ latest=$latest_tok$earliest_tok, latest_tok

 

<form version="1.1" theme="light">
  <label>Non-alphabetic tokens</label>
  <description>https://community.splunk.com/t5/Splunk-Search/How-to-include-arguments-in-search-macros-with-non-alphanumeric/m-p/696333#M236667</description>
  <fieldset submitButton="false">
    <input type="time" token="timepicker" searchWhenChanged="true">
      <label>pick time</label>
      <default>
        <earliest>-15m</earliest>
        <latest>now</latest>
      </default>
    </input>
  </fieldset>
  <row>
    <panel>
      <title>$timepicker.earliest$</title>
      <table>
        <search>
          <query>`non-alphabetic-token($timepicker.earliest$, $timepicker.latest$)`
| addinfo
| stats count by info_min_time info_max_time
| foreach info_*
    [eval &lt;&lt;FIELD&gt;&gt; = strftime(&lt;&lt;FIELD&gt;&gt;, "%F %T")]</query>
          <earliest>-24h@h</earliest>
          <latest>now</latest>
        </search>
        <option name="drilldown">none</option>
        <option name="refresh.display">progressbar</option>
      </table>
    </panel>
  </row>
</form>

 

Here are some sample interactions:

non-alphabetic-token-recent.png

non-alphabetic-token-past.png

  

0 Karma

cherrypick
Path Finder

Amazing! Thank you. Yes I misunderstood macros.

0 Karma

cherrypick
Path Finder

Or is there another way to use re-usable SPL searches that can take these values into account?

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

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...

Customer success is front and center at .conf25

Hi Splunkers, If you are not able to be at .conf25 in person, you can still learn about all the latest news ...

.conf25 Global Broadcast: Don’t Miss a Moment

Hello Splunkers, .conf25 is only a click away.  Not able to make it to .conf25 in person? No worries, you can ...