<?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 How to returns 0 or null if no results with tstats over time? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-returns-0-or-null-if-no-results-with-tstats-over-time/m-p/476801#M133827</link>
    <description>&lt;P&gt;First of all, I apologize if I missed the answer somewhere and for my bad english.&lt;/P&gt;

&lt;P&gt;I try to supervise my hosts, indexes and sourcetypes over time with percentage. And I also try to make it dynamic so without keep update a csv file. &lt;/P&gt;

&lt;P&gt;Here is, the result expected: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;_time   host    index   sourcetype  lasttime    count   perc_count  total_events
01/01/2020  fwd01   firewall    pf:filterlog    1577919599  10701461    2   469641743
01/01/2020  inflin01    linux   auditd  0   0   0   0
02/01/2020  fwd01   firewall    pf:filterlog    1578005999  65224250    14  469641743
02/01/2020  inflin01    linux   auditd  0   0   0   0
03/01/2020  fwd01   firewall    pf:filterlog    1578092399  66539689    14  469641743
03/01/2020  inflin01    linux   auditd  0   0   0   0
04/01/2020  fwd01   firewall    pf:filterlog    1578178799  38504400    8   469641743
04/01/2020  inflin01    linux   auditd  0   0   0   0
05/01/2020  fwd01   firewall    pf:filterlog    1578265199  40818288    9   469641743
05/01/2020  inflin01    linux   auditd  0   0   0   0
06/01/2020  fwd01   firewall    pf:filterlog    1578351599  89271070    19  469641743
06/01/2020  inflin01    linux   auditd  0   0   0   0
07/01/2020  fwd01   firewall    pf:filterlog    1578437999  88244234    19  469641743
07/01/2020  inflin01    linux   auditd  0   0   0   0
08/01/2020  fwd01   firewall    pf:filterlog    1578500836  70338351    5   469641743
08/01/2020  inflin01    linux   auditd  0   0   0   0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;My search is something like that (on the last 7 days):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| tstats latest(_time) as lasttime count where index=* by _time host index sourcetype span=1d
| eventstats sum(count) as total_events by host index sourcetype 
| eval perc_count=round(count*100/total_events,0) 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But tstats returns me only the rows with 'pf:filterlog' as sourcetype because it's the only one which have data.&lt;BR /&gt;
The idea is to have conditions on perc_count &amp;lt;=2% for example or count=0 in order to raise an alert.&lt;/P&gt;

&lt;P&gt;I have already a search which works perfectly with 'lasttime' where each host or index or sourcetype (or all 3 at the same time) with custom threshold. So here, I want to identify the log decreases or nothing.&lt;/P&gt;

&lt;P&gt;How to tell to &lt;CODE&gt;tstats&lt;/CODE&gt;to returns 0 value if it have 0 result over time? Or any tricks with another commands to get the final results?&lt;BR /&gt;
I also already tried the &lt;CODE&gt;append&lt;/CODE&gt; command but with the host field is complicated to merge rows with identical host/index/sourcetype.&lt;/P&gt;</description>
    <pubDate>Wed, 08 Jan 2020 17:07:51 GMT</pubDate>
    <dc:creator>nrodrigues</dc:creator>
    <dc:date>2020-01-08T17:07:51Z</dc:date>
    <item>
      <title>How to returns 0 or null if no results with tstats over time?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-returns-0-or-null-if-no-results-with-tstats-over-time/m-p/476801#M133827</link>
      <description>&lt;P&gt;First of all, I apologize if I missed the answer somewhere and for my bad english.&lt;/P&gt;

&lt;P&gt;I try to supervise my hosts, indexes and sourcetypes over time with percentage. And I also try to make it dynamic so without keep update a csv file. &lt;/P&gt;

&lt;P&gt;Here is, the result expected: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;_time   host    index   sourcetype  lasttime    count   perc_count  total_events
01/01/2020  fwd01   firewall    pf:filterlog    1577919599  10701461    2   469641743
01/01/2020  inflin01    linux   auditd  0   0   0   0
02/01/2020  fwd01   firewall    pf:filterlog    1578005999  65224250    14  469641743
02/01/2020  inflin01    linux   auditd  0   0   0   0
03/01/2020  fwd01   firewall    pf:filterlog    1578092399  66539689    14  469641743
03/01/2020  inflin01    linux   auditd  0   0   0   0
04/01/2020  fwd01   firewall    pf:filterlog    1578178799  38504400    8   469641743
04/01/2020  inflin01    linux   auditd  0   0   0   0
05/01/2020  fwd01   firewall    pf:filterlog    1578265199  40818288    9   469641743
05/01/2020  inflin01    linux   auditd  0   0   0   0
06/01/2020  fwd01   firewall    pf:filterlog    1578351599  89271070    19  469641743
06/01/2020  inflin01    linux   auditd  0   0   0   0
07/01/2020  fwd01   firewall    pf:filterlog    1578437999  88244234    19  469641743
07/01/2020  inflin01    linux   auditd  0   0   0   0
08/01/2020  fwd01   firewall    pf:filterlog    1578500836  70338351    5   469641743
08/01/2020  inflin01    linux   auditd  0   0   0   0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;My search is something like that (on the last 7 days):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| tstats latest(_time) as lasttime count where index=* by _time host index sourcetype span=1d
| eventstats sum(count) as total_events by host index sourcetype 
| eval perc_count=round(count*100/total_events,0) 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But tstats returns me only the rows with 'pf:filterlog' as sourcetype because it's the only one which have data.&lt;BR /&gt;
The idea is to have conditions on perc_count &amp;lt;=2% for example or count=0 in order to raise an alert.&lt;/P&gt;

&lt;P&gt;I have already a search which works perfectly with 'lasttime' where each host or index or sourcetype (or all 3 at the same time) with custom threshold. So here, I want to identify the log decreases or nothing.&lt;/P&gt;

&lt;P&gt;How to tell to &lt;CODE&gt;tstats&lt;/CODE&gt;to returns 0 value if it have 0 result over time? Or any tricks with another commands to get the final results?&lt;BR /&gt;
I also already tried the &lt;CODE&gt;append&lt;/CODE&gt; command but with the host field is complicated to merge rows with identical host/index/sourcetype.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jan 2020 17:07:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-returns-0-or-null-if-no-results-with-tstats-over-time/m-p/476801#M133827</guid>
      <dc:creator>nrodrigues</dc:creator>
      <dc:date>2020-01-08T17:07:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to returns 0 or null if no results with tstats over time?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-returns-0-or-null-if-no-results-with-tstats-over-time/m-p/476802#M133828</link>
      <description>&lt;P&gt;I think your best bet would be too create a lookup of all the host, index, sourcetypes combinations you would expect to see. Perhaps by running a search like the following over the past 30 days:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | tstats count by host, index, sourcetype | table host, index, sourcetype | outputlookup lookupname.csv
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then you can start your search by outputting the results of that lookup and then using a left join with a subsearch that uses your original logic to add the count, perc_count, and total_count fields that you want. By using a left join, you will either have a value in the desired fields or they'll be null. Then you can use the fillnull command to populate them with zeros or use a where isnull(count) to detect these combos that didn't report events. The logic would look like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| inputlookup lookupname.csv
| join type=left host, index, sourcetype
[| tstats latest(_time) as lasttime count where index=* by _time host index sourcetype span=1d
 | eventstats sum(count) as total_events by host index sourcetype 
 | eval perc_count=round(count*100/total_events,0)]
| where isnull(count)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Sep 2020 03:43:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-returns-0-or-null-if-no-results-with-tstats-over-time/m-p/476802#M133828</guid>
      <dc:creator>acfecondo75</dc:creator>
      <dc:date>2020-09-30T03:43:36Z</dc:date>
    </item>
  </channel>
</rss>

