<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to reference a string variable in a search to avoid retyping it? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-reference-a-string-variable-in-a-search-to-avoid-retyping/m-p/163053#M46272</link>
    <description>&lt;P&gt;This is the search that I'm trying to do but it does not return anything. I'm trying to create a string variable and referencing it in a search so that I don't have to retype it eight times. And if I wan't to change the string, I only have to do it once.&lt;/P&gt;

&lt;P&gt;| eval subnet="207.45.47.0/24" | search src_ip=subnet OR source_address=subnet OR src_translated_ip=subnet OR nat_source_address=subnet OR dest_ip=subnet OR destination_address=subnet OR dest_translated_ip=subnet OR nat_destination_address=subnet&lt;/P&gt;

&lt;P&gt;Is this allowed or is there a better way of doing it?&lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 17:52:34 GMT</pubDate>
    <dc:creator>rpolanco</dc:creator>
    <dc:date>2020-09-28T17:52:34Z</dc:date>
    <item>
      <title>How to reference a string variable in a search to avoid retyping it?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-reference-a-string-variable-in-a-search-to-avoid-retyping/m-p/163053#M46272</link>
      <description>&lt;P&gt;This is the search that I'm trying to do but it does not return anything. I'm trying to create a string variable and referencing it in a search so that I don't have to retype it eight times. And if I wan't to change the string, I only have to do it once.&lt;/P&gt;

&lt;P&gt;| eval subnet="207.45.47.0/24" | search src_ip=subnet OR source_address=subnet OR src_translated_ip=subnet OR nat_source_address=subnet OR dest_ip=subnet OR destination_address=subnet OR dest_translated_ip=subnet OR nat_destination_address=subnet&lt;/P&gt;

&lt;P&gt;Is this allowed or is there a better way of doing it?&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 17:52:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-reference-a-string-variable-in-a-search-to-avoid-retyping/m-p/163053#M46272</guid>
      <dc:creator>rpolanco</dc:creator>
      <dc:date>2020-09-28T17:52:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to reference a string variable in a search to avoid retyping it?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-reference-a-string-variable-in-a-search-to-avoid-retyping/m-p/163054#M46273</link>
      <description>&lt;P&gt;That should work, assuming the fields you are trying to match contain the exact string "207.45.47.0/24".  If you are trying to do a CIDR match you need to use the &lt;CODE&gt;cidrmatch&lt;/CODE&gt; eval function or change your 'subnet' string to "207.45.47.*".&lt;/P&gt;</description>
      <pubDate>Tue, 14 Oct 2014 15:55:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-reference-a-string-variable-in-a-search-to-avoid-retyping/m-p/163054#M46273</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2014-10-14T15:55:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to reference a string variable in a search to avoid retyping it?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-reference-a-string-variable-in-a-search-to-avoid-retyping/m-p/163055#M46274</link>
      <description>&lt;P&gt;You could create a search macro that takes one variable, and then plug that variable in multiple places. So for instance:&lt;/P&gt;

&lt;P&gt;Under &lt;STRONG&gt;Settings &amp;gt; Advanced search &amp;gt; Search macros &amp;gt; Add new&lt;/STRONG&gt;, &lt;/P&gt;

&lt;P&gt;create a new macro for the &lt;CODE&gt;search&lt;/CODE&gt; app that takes one argument (say, &lt;CODE&gt;addrmacro(1)&lt;/CODE&gt;)&lt;/P&gt;

&lt;P&gt;In the &lt;CODE&gt;Defintion&lt;/CODE&gt; section, write:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;src_ip=$arg1$ OR source_address=$arg1$ OR src_translated_ip=$arg1$ OR nat_source_address=$arg1$ OR dest_ip=$arg1$ OR destination_address=$arg1$ OR dest_translated_ip=$arg1$ OR nat_destination_address=$arg1$
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;In the &lt;CODE&gt;Arguments&lt;/CODE&gt; section, write &lt;CODE&gt;arg1&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;Then save it.&lt;/P&gt;

&lt;P&gt;Now, you should be able to use it on the search bar, like &lt;CODE&gt;addrmacro("207.45.47.0/24")&lt;/CODE&gt; with backquotes surrounding it, so Splunk knows it's a macro call. (I can't figure out how to write backquotes here, but imagine that they're there.)&lt;/P&gt;</description>
      <pubDate>Tue, 14 Oct 2014 15:58:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-reference-a-string-variable-in-a-search-to-avoid-retyping/m-p/163055#M46274</guid>
      <dc:creator>aweitzman</dc:creator>
      <dc:date>2014-10-14T15:58:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to reference a string variable in a search to avoid retyping it?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-reference-a-string-variable-in-a-search-to-avoid-retyping/m-p/163056#M46275</link>
      <description>&lt;P&gt;This is a good answer, but will still fail to return anything if the fields don't exactly match the argument.  My crystal ball is a little cloudy, but I believe the OP needs to use a pattern (207.45.47.*) instead of a CIDR.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Oct 2014 16:11:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-reference-a-string-variable-in-a-search-to-avoid-retyping/m-p/163056#M46275</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2014-10-14T16:11:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to reference a string variable in a search to avoid retyping it?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-reference-a-string-variable-in-a-search-to-avoid-retyping/m-p/163057#M46276</link>
      <description>&lt;P&gt;You're probably right. The OP will likely want to combine both answers to get what they really want.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Oct 2014 16:15:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-reference-a-string-variable-in-a-search-to-avoid-retyping/m-p/163057#M46276</guid>
      <dc:creator>aweitzman</dc:creator>
      <dc:date>2014-10-14T16:15:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to reference a string variable in a search to avoid retyping it?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-reference-a-string-variable-in-a-search-to-avoid-retyping/m-p/163058#M46277</link>
      <description>&lt;P&gt;I tried creating the macro and the search still does not return anything even if a type a specific IP instead of the subnet. This is the search:&lt;/P&gt;

&lt;P&gt;subnet("207.45.47.0/24")&lt;/P&gt;

&lt;P&gt;Not sure why it's not returning anything. The fields in the macro's definition match exactly.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Oct 2014 16:22:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-reference-a-string-variable-in-a-search-to-avoid-retyping/m-p/163058#M46277</guid>
      <dc:creator>rpolanco</dc:creator>
      <dc:date>2014-10-14T16:22:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to reference a string variable in a search to avoid retyping it?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-reference-a-string-variable-in-a-search-to-avoid-retyping/m-p/163059#M46278</link>
      <description>&lt;P&gt;Got it to work; I forgot the bacquotes.&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 14 Oct 2014 16:34:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-reference-a-string-variable-in-a-search-to-avoid-retyping/m-p/163059#M46278</guid>
      <dc:creator>rpolanco</dc:creator>
      <dc:date>2014-10-14T16:34:17Z</dc:date>
    </item>
  </channel>
</rss>

