<?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 Re: Replacing $var$ with var in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/Replacing-var-with-var/m-p/321508#M20686</link>
    <description>&lt;P&gt;Is that you Kiran? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;This works a treat. &lt;/P&gt;

&lt;P&gt;No not all the fields will exist. I just need to add this in front:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;notable&lt;/CODE&gt;&lt;BR /&gt;
| eval user= if(isnull(user),"",user )&lt;BR /&gt;
| eval dest= if(isnull(dest),"",dest )&lt;BR /&gt;
| eval src= if(isnull(src),"",src )&lt;BR /&gt;
| stats count by drilldown_search,dest,src,user&lt;BR /&gt;
| foreach * [eval drilldown_search=replace(drilldown_search,"\$&amp;lt;&amp;gt;\$", &amp;lt;&amp;gt;)]&lt;/P&gt;

&lt;P&gt;Shame I cannot condense the '| eval user= if(isnull(user),"",user )' etc into one statement where I do not need to know the names of $var$. &lt;/P&gt;

&lt;P&gt;Thanks.&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 16:25:00 GMT</pubDate>
    <dc:creator>nightflame</dc:creator>
    <dc:date>2020-09-29T16:25:00Z</dc:date>
    <item>
      <title>Replacing $var$ with var</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Replacing-var-with-var/m-p/321502#M20680</link>
      <description>&lt;P&gt;The `notable` macro returns a field drilldown_search with the variables $user$ and $dest" embedded in it.&lt;/P&gt;

&lt;P&gt;I would like to make use of this elsewhere and replace $user$ and $dest$ will the values of those fields respectively.&lt;/P&gt;

&lt;P&gt;Is there a simple way in SPL to tell Splunk to substitute $var$ for var?&lt;/P&gt;

&lt;P&gt;The best I have come up with is:&lt;/P&gt;

&lt;P&gt;`notable`&lt;BR /&gt;
| eval drilldown_search = if(like(drilldown_search,"%$user$%"), replace(drilldown_search,"\$user\$", user), drilldown_search)&lt;BR /&gt;
| eval drilldown_search = if(like(drilldown_search,"%$dest$%"), replace(drilldown_search,"\$dest\$", dest), drilldown_search)&lt;/P&gt;

&lt;P&gt;This seems a bit convoluted and I need a statement for each $var$.&lt;/P&gt;

&lt;P&gt;Also I found if I do not use the if(like(... then replace returns drilldown_search as null if it does not match.&lt;/P&gt;

&lt;P&gt;Is there a better way of doing this?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:22:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Replacing-var-with-var/m-p/321502#M20680</guid>
      <dc:creator>nightflame</dc:creator>
      <dc:date>2020-09-29T16:22:35Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing $var$ with var</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Replacing-var-with-var/m-p/321503#M20681</link>
      <description>&lt;P&gt;If you want to get rid of all instances of the $ character in your drilldown_search field, then rex should work:&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/SplunkCloud/6.6.3/SearchReference/Rex"&gt;http://docs.splunk.com/Documentation/SplunkCloud/6.6.3/SearchReference/Rex&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;| rex field=drilldown_search mode=sed "s/\$//g"&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2017 14:16:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Replacing-var-with-var/m-p/321503#M20681</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2017-10-23T14:16:00Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing $var$ with var</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Replacing-var-with-var/m-p/321504#M20682</link>
      <description>&lt;P&gt;That's not quite what I wanted. I want to replace $var$ the value of var, not "var" string. Note the lack of quotes around user in my replace example.&lt;/P&gt;

&lt;P&gt;So for example I have a field user="fred"&lt;/P&gt;

&lt;P&gt;Then I want to resolve $user$ to "fred", not "user"&lt;/P&gt;

&lt;P&gt;Hope that makes sense.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2017 14:35:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Replacing-var-with-var/m-p/321504#M20682</guid>
      <dc:creator>nightflame</dc:creator>
      <dc:date>2017-10-23T14:35:40Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing $var$ with var</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Replacing-var-with-var/m-p/321505#M20683</link>
      <description>&lt;P&gt;Have a try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  `notable`
| stats count by drilldown_search,dest,src,user
| foreach * [eval drilldown_search=replace(drilldown_search,"\$&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;\$", &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;)]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The important thing to note here is, &lt;CODE&gt;stats count&lt;/CODE&gt;  statement will ensure the fields that have values only will come out. If you need to accommodate null values, you may need to fiddle but the logic should work.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2017 15:36:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Replacing-var-with-var/m-p/321505#M20683</guid>
      <dc:creator>koshyk</dc:creator>
      <dc:date>2017-10-23T15:36:54Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing $var$ with var</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Replacing-var-with-var/m-p/321506#M20684</link>
      <description>&lt;P&gt;@nightflame, can you share some of the outputs of macro &lt;CODE&gt;notable&lt;/CODE&gt; with few drilldown_search field values. Can it return only $user$ or $dest$ or both?&lt;/P&gt;

&lt;P&gt;Besides the $user$ and/or $dest$ values being returned for field &lt;CODE&gt;drilldown_search&lt;/CODE&gt;, is the macro also returning &lt;CODE&gt;user&lt;/CODE&gt; and &lt;CODE&gt;dest&lt;/CODE&gt; fields? What are some of these fields values? Will it be possible for you to share macro code?&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2017 16:39:44 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Replacing-var-with-var/m-p/321506#M20684</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-10-23T16:39:44Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing $var$ with var</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Replacing-var-with-var/m-p/321507#M20685</link>
      <description>&lt;P&gt;Ah, it does. I misread, sorry. In that case, the answer by @koshyk should do the trick.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2017 17:08:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Replacing-var-with-var/m-p/321507#M20685</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2017-10-23T17:08:28Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing $var$ with var</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Replacing-var-with-var/m-p/321508#M20686</link>
      <description>&lt;P&gt;Is that you Kiran? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;This works a treat. &lt;/P&gt;

&lt;P&gt;No not all the fields will exist. I just need to add this in front:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;notable&lt;/CODE&gt;&lt;BR /&gt;
| eval user= if(isnull(user),"",user )&lt;BR /&gt;
| eval dest= if(isnull(dest),"",dest )&lt;BR /&gt;
| eval src= if(isnull(src),"",src )&lt;BR /&gt;
| stats count by drilldown_search,dest,src,user&lt;BR /&gt;
| foreach * [eval drilldown_search=replace(drilldown_search,"\$&amp;lt;&amp;gt;\$", &amp;lt;&amp;gt;)]&lt;/P&gt;

&lt;P&gt;Shame I cannot condense the '| eval user= if(isnull(user),"",user )' etc into one statement where I do not need to know the names of $var$. &lt;/P&gt;

&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:25:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Replacing-var-with-var/m-p/321508#M20686</guid>
      <dc:creator>nightflame</dc:creator>
      <dc:date>2020-09-29T16:25:00Z</dc:date>
    </item>
  </channel>
</rss>

