<?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: How to write a search to produce a table with specified fields based on certain tags found in results? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-produce-a-table-with-specified-fields/m-p/200359#M58082</link>
    <description>&lt;P&gt;I might take creative (or totally bland) field naming, but you could try using macros to do the table formatting then pass it the fields you want.   For instance, I did this with some logs of my own:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; ... | eval a1=eventtype 
| eval a2=bytes_in | eval a3=bytes_out | eval a4=ack_packets_in | eval a5=ack_packets_out 
| `my-table(a1 a2 a3 a4 a5)`
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That results in a table with fields labeled a1 through a5.  Obviously change those to whatever names you want.  This depends on a macro I created that consists of &lt;/P&gt;

&lt;P&gt;&lt;EM&gt;name: my-table(5)&lt;BR /&gt;
definition: table $arg1$ $arg2$ $arg3$ $arg4$ $arg5$&lt;BR /&gt;
arguments: arg1,arg2,arg3,arg4,arg5&lt;/EM&gt;&lt;/P&gt;

&lt;P&gt;You can create several of these only differing by the number of arguments, then you can call them all the same.  So if you have a my-table(4) and my-table(5), and you called &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | `my-table(myfield1 myfield2 myfield3 myfield4)`
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It would use the 4 argument version.&lt;/P&gt;

&lt;P&gt;To vary things, you could use some generic other field category, and maybe call it like this example below using a "built in" field EventCode and a "generated" fields OtherInfo1.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval OtherInfo1=if(isnotnull(somefield),somefield, someotherfield) | `my-table(EventCode, OtherInfo1)`
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Similarly, other types of those calculations may work, like &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval a2=if(bytes_in&amp;gt;0,bytes_in,EventCode)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Which I totally made up and is nonsense, but does work.&lt;/P&gt;

&lt;P&gt;BTW, be sure to set permissions appropriately on the macro!  You can browse the &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.0/Search/Usesearchmacros"&gt;docs on macros&lt;/A&gt; for more.&lt;/P&gt;</description>
    <pubDate>Fri, 12 Feb 2016 03:05:34 GMT</pubDate>
    <dc:creator>Richfez</dc:creator>
    <dc:date>2016-02-12T03:05:34Z</dc:date>
    <item>
      <title>How to write a search to produce a table with specified fields based on certain tags found in results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-produce-a-table-with-specified-fields/m-p/200356#M58079</link>
      <description>&lt;P&gt;I want to build a table with different fields depending on the search result.&lt;/P&gt;

&lt;P&gt;If a certain tag or another tag is found, I need to produce a table with certain fields OR if other tags are found, I need a table with other fields.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2016 19:51:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-produce-a-table-with-specified-fields/m-p/200356#M58079</guid>
      <dc:creator>alex1895</dc:creator>
      <dc:date>2016-02-10T19:51:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to produce a table with specified fields based on certain tags found in results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-produce-a-table-with-specified-fields/m-p/200357#M58080</link>
      <description>&lt;P&gt;Have you looked that this??&lt;/P&gt;

&lt;P&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.0/SearchReference/Fieldsummary"&gt;http://docs.splunk.com/Documentation/Splunk/6.2.0/SearchReference/Fieldsummary&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2016 20:25:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-produce-a-table-with-specified-fields/m-p/200357#M58080</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-02-10T20:25:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to produce a table with specified fields based on certain tags found in results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-produce-a-table-with-specified-fields/m-p/200358#M58081</link>
      <description>&lt;P&gt;Not really sure how this helps. I don't want to show statistic for each field. The table should just show the value of the fields for each event. That is my search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=* sourcetype!="XXX-CEF" vendor!="XXX" $ip$ OR $URL$ AND (tag=ids OR tag=attack OR tag=report OR tag=vulnerability OR tag=malware OR tag=operations) | table vendor* ,dvc*,ids_type,tag,action*,category,signature,src*,dest*,user,severity*,_raw
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I want to be able to adjust the table fields depending on what tags are included. &lt;/P&gt;</description>
      <pubDate>Wed, 10 Feb 2016 22:18:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-produce-a-table-with-specified-fields/m-p/200358#M58081</guid>
      <dc:creator>alex1895</dc:creator>
      <dc:date>2016-02-10T22:18:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to produce a table with specified fields based on certain tags found in results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-produce-a-table-with-specified-fields/m-p/200359#M58082</link>
      <description>&lt;P&gt;I might take creative (or totally bland) field naming, but you could try using macros to do the table formatting then pass it the fields you want.   For instance, I did this with some logs of my own:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; ... | eval a1=eventtype 
| eval a2=bytes_in | eval a3=bytes_out | eval a4=ack_packets_in | eval a5=ack_packets_out 
| `my-table(a1 a2 a3 a4 a5)`
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That results in a table with fields labeled a1 through a5.  Obviously change those to whatever names you want.  This depends on a macro I created that consists of &lt;/P&gt;

&lt;P&gt;&lt;EM&gt;name: my-table(5)&lt;BR /&gt;
definition: table $arg1$ $arg2$ $arg3$ $arg4$ $arg5$&lt;BR /&gt;
arguments: arg1,arg2,arg3,arg4,arg5&lt;/EM&gt;&lt;/P&gt;

&lt;P&gt;You can create several of these only differing by the number of arguments, then you can call them all the same.  So if you have a my-table(4) and my-table(5), and you called &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | `my-table(myfield1 myfield2 myfield3 myfield4)`
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It would use the 4 argument version.&lt;/P&gt;

&lt;P&gt;To vary things, you could use some generic other field category, and maybe call it like this example below using a "built in" field EventCode and a "generated" fields OtherInfo1.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval OtherInfo1=if(isnotnull(somefield),somefield, someotherfield) | `my-table(EventCode, OtherInfo1)`
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Similarly, other types of those calculations may work, like &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval a2=if(bytes_in&amp;gt;0,bytes_in,EventCode)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Which I totally made up and is nonsense, but does work.&lt;/P&gt;

&lt;P&gt;BTW, be sure to set permissions appropriately on the macro!  You can browse the &lt;A href="http://docs.splunk.com/Documentation/Splunk/6.2.0/Search/Usesearchmacros"&gt;docs on macros&lt;/A&gt; for more.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Feb 2016 03:05:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-produce-a-table-with-specified-fields/m-p/200359#M58082</guid>
      <dc:creator>Richfez</dc:creator>
      <dc:date>2016-02-12T03:05:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a search to produce a table with specified fields based on certain tags found in results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-produce-a-table-with-specified-fields/m-p/200360#M58083</link>
      <description>&lt;P&gt;Thanks, Great Answer. How do bring the condition if this tag matches, built this table, and if this tag matches built this table in? &lt;/P&gt;</description>
      <pubDate>Wed, 17 Feb 2016 03:49:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-write-a-search-to-produce-a-table-with-specified-fields/m-p/200360#M58083</guid>
      <dc:creator>alex1895</dc:creator>
      <dc:date>2016-02-17T03:49:35Z</dc:date>
    </item>
  </channel>
</rss>

