<?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: Adding a colum to stats results in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Adding-a-colum-to-stats-results/m-p/311558#M93366</link>
    <description>&lt;P&gt;Thanks! This works like a charm.&lt;BR /&gt;
I just started with splunk and would really be grateful if you clear some of my doubts.&lt;/P&gt;

&lt;P&gt;Can you explain how the stats command works here? &lt;BR /&gt;
Also whats the difference between if and case? &lt;/P&gt;</description>
    <pubDate>Wed, 12 Jul 2017 19:39:16 GMT</pubDate>
    <dc:creator>amritanshgupta</dc:creator>
    <dc:date>2017-07-12T19:39:16Z</dc:date>
    <item>
      <title>Adding a colum to stats results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Adding-a-colum-to-stats-results/m-p/311556#M93364</link>
      <description>&lt;P&gt;Hey!&lt;/P&gt;

&lt;P&gt;Right now I have a search - &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="tcp:6555"| search Message_Type =IP  | stats sum(Bytes) AS Bytes by IP | sort -Bytes | head 10 | eval Bytes = case(Bytes/pow(1024,1) &amp;lt;1024, tostring(round(tonumber(Bytes)/pow(1024,1),2))."K", Bytes/pow(1024,2) &amp;lt;1024, tostring(round(tonumber(Bytes)/pow(1024,2),2))."M", Bytes/pow(1024,3) &amp;lt;1000, tostring(round(tonumber(Bytes)/pow(1024,3),2))."G", true(), Bytes) 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Which gives me &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;192.168.abc.abc     1.23M    
173.241.abc.abc     436.03K      
40.118.acb.abc  422.66K      
192.168.abc.abc     255.59K      
50.19.abc.abc   83.63K
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;.... &lt;/P&gt;

&lt;P&gt;till 10 unique values for IPs.&lt;BR /&gt;
What I want to do now is a separate column that states if the IP has posted an event in the past 10 minutes.&lt;BR /&gt;
I had something like this in mind &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="tcp:6565"| search Message_Type =IP  | stats sum(Bytes) AS Bytes by IP | sort -Bytes | head 10 | eval Bytes = case(Bytes/pow(1024,1) &amp;lt;1024, tostring(round(tonumber(Bytes)/pow(1024,1),2))."K", Bytes/pow(1024,2) &amp;lt;1024, tostring(round(tonumber(Bytes)/pow(1024,2),2))."M", Bytes/pow(1024,3) &amp;lt;1000, tostring(round(tonumber(Bytes)/pow(1024,3),2))."G", true(), Bytes) | eval tnow = now()-_time | eval Status = case(tnow &amp;lt;=300, "Up", tnow&amp;gt;300, "Down") 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I kind of understand why this doesnt work but how can I make it work?&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2017 19:24:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Adding-a-colum-to-stats-results/m-p/311556#M93364</guid>
      <dc:creator>amritanshgupta</dc:creator>
      <dc:date>2017-07-12T19:24:14Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a colum to stats results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Adding-a-colum-to-stats-results/m-p/311557#M93365</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="tcp:6555"| search Message_Type =IP  | stats max(_time) AS latest_time sum(Bytes) AS Bytes by IP | sort -Bytes | head 10 | eval Bytes = case(Bytes/pow(1024,1) &amp;lt;1024, tostring(round(tonumber(Bytes)/pow(1024,1),2))."K", Bytes/pow(1024,2) &amp;lt;1024, tostring(round(tonumber(Bytes)/pow(1024,2),2))."M", Bytes/pow(1024,3) &amp;lt;1000, tostring(round(tonumber(Bytes)/pow(1024,3),2))."G", true(), Bytes)  | eval eventInLastTenMinutes=if((latest_time&amp;gt;=relative_time(now(), "-10m")), "Yes", "No")
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Jul 2017 19:31:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Adding-a-colum-to-stats-results/m-p/311557#M93365</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-07-12T19:31:17Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a colum to stats results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Adding-a-colum-to-stats-results/m-p/311558#M93366</link>
      <description>&lt;P&gt;Thanks! This works like a charm.&lt;BR /&gt;
I just started with splunk and would really be grateful if you clear some of my doubts.&lt;/P&gt;

&lt;P&gt;Can you explain how the stats command works here? &lt;BR /&gt;
Also whats the difference between if and case? &lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2017 19:39:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Adding-a-colum-to-stats-results/m-p/311558#M93366</guid>
      <dc:creator>amritanshgupta</dc:creator>
      <dc:date>2017-07-12T19:39:16Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a colum to stats results</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Adding-a-colum-to-stats-results/m-p/311559#M93367</link>
      <description>&lt;P&gt;A single &lt;CODE&gt;stats&lt;/CODE&gt; can do many different types of summaries of the data.  I told it to look for the highest value for &lt;CODE&gt;_time&lt;/CODE&gt; ( I could also have used &lt;CODE&gt;latest(_time)&lt;/CODE&gt; ) as well as summarizing the bytes for each IP.  There is no real difference between &lt;CODE&gt;if&lt;/CODE&gt; and &lt;CODE&gt;case&lt;/CODE&gt;; the latter is really just a string of the former.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2017 19:42:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Adding-a-colum-to-stats-results/m-p/311559#M93367</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-07-12T19:42:29Z</dc:date>
    </item>
  </channel>
</rss>

