<?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: Counting events only once using different fields in specific orders. in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Counting-events-only-once-using-different-fields-in-specific/m-p/135921#M37173</link>
    <description>&lt;P&gt;If your fields are properly extracted then &lt;CODE&gt;isnotnull(field)&lt;/CODE&gt; should work as well. For the default case at the end I usually use &lt;CODE&gt;1=1&lt;/CODE&gt;, that's universally recognizable as not doing anything special by everyone looking at it later.&lt;/P&gt;</description>
    <pubDate>Sun, 30 Nov 2014 23:44:08 GMT</pubDate>
    <dc:creator>martin_mueller</dc:creator>
    <dc:date>2014-11-30T23:44:08Z</dc:date>
    <item>
      <title>Counting events only once using different fields in specific orders.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Counting-events-only-once-using-different-fields-in-specific/m-p/135917#M37169</link>
      <description>&lt;P&gt;A potentially simple question that i'm just missing the obvious answer to &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Say for example we have the following events.&lt;/P&gt;

&lt;P&gt;line 1 : time, fred, wilma&lt;BR /&gt;
line 2 : time,fred, barney, &lt;BR /&gt;
line 3 : time,fred, barney, wilma, bam&lt;BR /&gt;
line 4 : time,barney, wilma, bam&lt;/P&gt;

&lt;P&gt;We want the following counts of events creating columns of total, bam, barney, fred and wilma in a &lt;STRONG&gt;&lt;EM&gt;specific order&lt;/EM&gt;&lt;/STRONG&gt; and once counted these are not to be counted again even if the field exists.&lt;/P&gt;

&lt;P&gt;Column : # (Line where it should have come from.)&lt;BR /&gt;
Total : 4 (lines 1 to 4)&lt;BR /&gt;
bam : 2 (lines 3,4)&lt;BR /&gt;
barney : 1 (line 2)&lt;BR /&gt;
fred : 1 (line 1).&lt;BR /&gt;
wilma : 0 (no lines remaining).&lt;/P&gt;

&lt;P&gt;I was also thinking if there was a precedence/priotity order to eventtypes or tags that I could utilise to get the same result.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Nov 2014 23:47:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Counting-events-only-once-using-different-fields-in-specific/m-p/135917#M37169</guid>
      <dc:creator>Lucas_K</dc:creator>
      <dc:date>2014-11-27T23:47:48Z</dc:date>
    </item>
    <item>
      <title>Re: Counting events only once using different fields in specific orders.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Counting-events-only-once-using-different-fields-in-specific/m-p/135918#M37170</link>
      <description>&lt;P&gt;You could do something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats count | eval dummy = "line 1 : time, fred, wilma
line 2 : time,fred, barney,
line 3 : time,fred, barney, wilma, bam
line 4 : time,barney, wilma, bam" | makemv dummy delim="
" | mvexpand dummy | rename dummy as _raw

| eval dominant_character = case(searchmatch("bam"), "bam", searchmatch("barney"), "barney", searchmatch("fred"), "fred", searchmatch("wilma"), "wilma")
| stats count by dominant_character
| addcoltotals count
| fillnull dominant_character value="Total"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Do you need the result list to include zeros and follow the desired order as well?&lt;/P&gt;</description>
      <pubDate>Sat, 29 Nov 2014 14:03:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Counting-events-only-once-using-different-fields-in-specific/m-p/135918#M37170</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-11-29T14:03:52Z</dc:date>
    </item>
    <item>
      <title>Re: Counting events only once using different fields in specific orders.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Counting-events-only-once-using-different-fields-in-specific/m-p/135919#M37171</link>
      <description>&lt;P&gt;Ah yes searchmatch!&lt;/P&gt;

&lt;P&gt;As I was looking for the existance of a fieldname so searchmatch("myfield=*") works like a charm &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;I did need a zero's filling the rest of the non-dominant character.&lt;/P&gt;

&lt;P&gt;Resulting example search for multiple hosts. Iwill actually need around 30 columns but this gives a good idea of how it will work.&lt;/P&gt;

&lt;P&gt;index=blah host=blah*&lt;BR /&gt;
| eval dominant_character = case(searchmatch("auth=&lt;EM&gt;"), "auth", searchmatch("ssh=&lt;/EM&gt;"), "ssh", searchmatch("trap=&lt;EM&gt;"), "trap", searchmatch("&lt;/EM&gt;"), "other"))&lt;BR /&gt;
| stats count(dominant_character) AS Count by host, dominant_character&lt;BR /&gt;
| chart sum(Count) AS Count over host by dominant_character &lt;BR /&gt;
| addtotals | fillnull value=0 | fields host Total * other&lt;/P&gt;

&lt;P&gt;Result:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;host    Total   auth    ssh trap    other
blah1   10452   362 0   21   10069
blah2   1796    629 590 3   574
blah3   7970    362 0   3   7605
blah4   5042    362 0   3   4677
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thank you very much Martin! I was hoping to get an answer from you &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 18:18:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Counting-events-only-once-using-different-fields-in-specific/m-p/135919#M37171</guid>
      <dc:creator>Lucas_K</dc:creator>
      <dc:date>2020-09-28T18:18:00Z</dc:date>
    </item>
    <item>
      <title>Re: Counting events only once using different fields in specific orders.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Counting-events-only-once-using-different-fields-in-specific/m-p/135920#M37172</link>
      <description>&lt;P&gt;I did find an issue where if there isn't a single host with a particular field it will not show at all.&lt;/P&gt;

&lt;P&gt;I could create a single evaled host event that contains a single value for every column and then just remove this at the end just prior to it being displayed.&lt;BR /&gt;
edit: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| addtotals 
| append [search | stats count 
| eval host="dummy_host" | eval auth=0 | eval ssh=0 | eval underObs=0 | eval chatter=0 | eval authFail=0 | eval telnetErr=0 | eval backupFail=0 | eval trap=0 
| eval pmd=0 | eval swo=0 | eval acl=0 | eval disPkt=0 | eval LBerr=0 | eval errConn=0 | eval getPeer=0 | eval disk=0 | eval hm=0 | eval lcnm=0 | eval ctp=0 
| eval crc=0 | eval cnmMgr=0 | eval cardSeat=0 | eval tools=0 | eval underObs=0 | eval chatter=0| fields - count]
| fillnull value=0 | fields host Total auth * other
| search host!=dummy_host
| addcoltotals
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 30 Nov 2014 23:41:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Counting-events-only-once-using-different-fields-in-specific/m-p/135920#M37172</guid>
      <dc:creator>Lucas_K</dc:creator>
      <dc:date>2014-11-30T23:41:31Z</dc:date>
    </item>
    <item>
      <title>Re: Counting events only once using different fields in specific orders.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Counting-events-only-once-using-different-fields-in-specific/m-p/135921#M37173</link>
      <description>&lt;P&gt;If your fields are properly extracted then &lt;CODE&gt;isnotnull(field)&lt;/CODE&gt; should work as well. For the default case at the end I usually use &lt;CODE&gt;1=1&lt;/CODE&gt;, that's universally recognizable as not doing anything special by everyone looking at it later.&lt;/P&gt;</description>
      <pubDate>Sun, 30 Nov 2014 23:44:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Counting-events-only-once-using-different-fields-in-specific/m-p/135921#M37173</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-11-30T23:44:08Z</dc:date>
    </item>
  </channel>
</rss>

