<?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: Macros using data from search in Knowledge Management</title>
    <link>https://community.splunk.com/t5/Knowledge-Management/Macros-using-data-from-search/m-p/33591#M298</link>
    <description>&lt;P&gt;Finally worked it out. Turns out you cannot have newlines in macros but you can in a search.&lt;/P&gt;

&lt;P&gt;So my example above was not entirely correct it should have been.&lt;/P&gt;

&lt;P&gt;Working search&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=blah | 
eval desc=if(floor(bitData)%2&amp;gt;0,"This Text, ","") | 
eval desc=desc+ if(floor(bitData/2)%2&amp;gt;0,"That Text, ","") |
table _time, bitData, desc
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Macro that doesn't work&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval desc=desc+ if(floor($bitField$/2)%2&amp;gt;0,"That Text, ","") |
eval desc=desc+ if(floor($bitField$/2)%2&amp;gt;0,"That Text, ","")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Macro that does work&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval desc=desc+ if(floor($bitField$/2)%2&amp;gt;0,"That Text, ","") | eval desc=desc+ if(floor($bitField$/2)%2&amp;gt;0,"That Text, ","")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I have them all on newlines as there are 16 rows for the entire macro and I wanted it to be readable and easy to edit.&lt;/P&gt;

&lt;P&gt;So its a bit inconsistent that newlines are allowed in a search but not in a macro. Should I submit this as a bug?&lt;/P&gt;

&lt;P&gt;Thanks to those that tried to assist.&lt;/P&gt;</description>
    <pubDate>Sat, 16 Feb 2013 00:46:23 GMT</pubDate>
    <dc:creator>phoenixdigital</dc:creator>
    <dc:date>2013-02-16T00:46:23Z</dc:date>
    <item>
      <title>Macros using data from search</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/Macros-using-data-from-search/m-p/33588#M295</link>
      <description>&lt;P&gt;Seems like a pretty simple thing I am trying to do but it wont work.&lt;/P&gt;

&lt;P&gt;I have some bitwise data which I want to convert into a string equivalent. So in this example I want to see if bit 0 or bit 1 is set.&lt;BR /&gt;
Bit0 = This Text&lt;BR /&gt;
Bit1 = That Text&lt;/P&gt;

&lt;P&gt;This search works perfectly&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=blah | eval desc=if(floor(bitData)%2&amp;gt;0,"This Text, ","") | eval desc=desc+ if(floor(bitData/2)%2&amp;gt;0,"That Text, ","") | table _time, bitData, desc
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now I actually have 16 bitfields and want to reuse this eval chain quite a bit so thought I would make a macro out of it.&lt;/P&gt;

&lt;P&gt;However this does not work&lt;/P&gt;

&lt;P&gt;Macro definition&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval desc=desc+ if(floor($bitField$/2)%2&amp;gt;0,"That Text, ","") | eval desc=desc+ if(floor($bitField$/2)%2&amp;gt;0,"That Text, ","")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This search does not work though&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    sourcetype=blah | `myMacro(bitData)` | table _time, bitData, desc
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I get the errors&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Error in 'SearchParser': Missing a search command before ' '.
Unknown search command 'gen'.
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;What gives here?&lt;/P&gt;</description>
      <pubDate>Fri, 15 Feb 2013 05:11:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/Macros-using-data-from-search/m-p/33588#M295</guid>
      <dc:creator>phoenixdigital</dc:creator>
      <dc:date>2013-02-15T05:11:11Z</dc:date>
    </item>
    <item>
      <title>Re: Macros using data from search</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/Macros-using-data-from-search/m-p/33589#M296</link>
      <description>&lt;P&gt;There doesn't appear to be anything wrong with your syntax.  Click the blue [i] next to the printer icon on the right of the search bar, after executing your search.  Scroll down to eventSearch to see how your macro is being expanded in the search.  It's likely a typo.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Feb 2013 06:46:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/Macros-using-data-from-search/m-p/33589#M296</guid>
      <dc:creator>Ron_Naken</dc:creator>
      <dc:date>2013-02-15T06:46:36Z</dc:date>
    </item>
    <item>
      <title>Re: Macros using data from search</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/Macros-using-data-from-search/m-p/33590#M297</link>
      <description>&lt;P&gt;The fields in a macro are named. You need to pass the field into the macro like this :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=blah | `myMacro(bitData=bitData)` | table _time, bitData, desc
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 15 Feb 2013 08:41:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/Macros-using-data-from-search/m-p/33590#M297</guid>
      <dc:creator>jonuwz</dc:creator>
      <dc:date>2013-02-15T08:41:25Z</dc:date>
    </item>
    <item>
      <title>Re: Macros using data from search</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/Macros-using-data-from-search/m-p/33591#M298</link>
      <description>&lt;P&gt;Finally worked it out. Turns out you cannot have newlines in macros but you can in a search.&lt;/P&gt;

&lt;P&gt;So my example above was not entirely correct it should have been.&lt;/P&gt;

&lt;P&gt;Working search&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=blah | 
eval desc=if(floor(bitData)%2&amp;gt;0,"This Text, ","") | 
eval desc=desc+ if(floor(bitData/2)%2&amp;gt;0,"That Text, ","") |
table _time, bitData, desc
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Macro that doesn't work&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval desc=desc+ if(floor($bitField$/2)%2&amp;gt;0,"That Text, ","") |
eval desc=desc+ if(floor($bitField$/2)%2&amp;gt;0,"That Text, ","")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Macro that does work&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval desc=desc+ if(floor($bitField$/2)%2&amp;gt;0,"That Text, ","") | eval desc=desc+ if(floor($bitField$/2)%2&amp;gt;0,"That Text, ","")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I have them all on newlines as there are 16 rows for the entire macro and I wanted it to be readable and easy to edit.&lt;/P&gt;

&lt;P&gt;So its a bit inconsistent that newlines are allowed in a search but not in a macro. Should I submit this as a bug?&lt;/P&gt;

&lt;P&gt;Thanks to those that tried to assist.&lt;/P&gt;</description>
      <pubDate>Sat, 16 Feb 2013 00:46:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/Macros-using-data-from-search/m-p/33591#M298</guid>
      <dc:creator>phoenixdigital</dc:creator>
      <dc:date>2013-02-16T00:46:23Z</dc:date>
    </item>
    <item>
      <title>Re: Macros using data from search</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/Macros-using-data-from-search/m-p/33592#M299</link>
      <description>&lt;P&gt;That middle section would be &lt;BR /&gt;
    | &lt;CODE&gt;myMacro(bitField=bitData)&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Feb 2017 15:04:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/Macros-using-data-from-search/m-p/33592#M299</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-02-06T15:04:36Z</dc:date>
    </item>
  </channel>
</rss>

