<?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: retrieving timechart values when there are no events in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/retrieving-timechart-values-when-there-are-no-events/m-p/484867#M135733</link>
    <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="appName" AND sourcetype="YourSourceTypeHere" AND build="xyz" AND logLevel="ERROR"
| append [| makeresults]
| timechart span=1d count(logLevel) AS value
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 19 Jan 2020 20:13:25 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2020-01-19T20:13:25Z</dc:date>
    <item>
      <title>retrieving timechart values when there are no events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/retrieving-timechart-values-when-there-are-no-events/m-p/484863#M135729</link>
      <description>&lt;P&gt;I am running following query in Splunk&lt;BR /&gt;
&lt;STRONG&gt;index=appName build=xyz logLevel=ERROR | timechart span=1d count As value.&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;if there are any events, then it will return the data in the following columns [result 1]; which is exactly what I am looking for&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;result 1&lt;/STRONG&gt;&lt;BR /&gt;
_time                      | value&lt;BR /&gt;
19-Jan-2020           | 10&lt;BR /&gt;
18-Jan-2020           | 14&lt;/P&gt;

&lt;P&gt;The problem is when there are no results. it returns 0 events. What I want is the output should be something like this [result 2] when there are no results for my query &lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;result 2&lt;/STRONG&gt;&lt;BR /&gt;
_time                      | value&lt;BR /&gt;
19-Jan-2020           | 0&lt;BR /&gt;
18-Jan-2020           | 0&lt;/P&gt;

&lt;P&gt;I tried improving my query and I was able to achieve result 2, with query 2, but when there are events as result of my query the output gets messed up. &lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;query 2&lt;/STRONG&gt;&lt;BR /&gt;
&lt;STRONG&gt;index=appName | timechart span=60 count as valueInner | appendcols [| search index=appName build=xyz  lvl=ERROR | bucket  _time span=60s | stats count as value ] | fillnull value=0&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;How should I write a query which should give &lt;STRONG&gt;_time&lt;/STRONG&gt; and &lt;STRONG&gt;value&lt;/STRONG&gt; column irrespective of the result of events?&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jan 2020 11:14:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/retrieving-timechart-values-when-there-are-no-events/m-p/484863#M135729</guid>
      <dc:creator>ashish198511</dc:creator>
      <dc:date>2020-01-19T11:14:00Z</dc:date>
    </item>
    <item>
      <title>Re: retrieving timechart values when there are no events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/retrieving-timechart-values-when-there-are-no-events/m-p/484864#M135730</link>
      <description>&lt;P&gt;&lt;CODE&gt;timechart&lt;/CODE&gt; will fill in missing times if you specify the &lt;CODE&gt;cont&lt;/CODE&gt; option.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=appName build=xyz logLevel=ERROR | timechart span=1d cont=true count As value
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 19 Jan 2020 15:12:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/retrieving-timechart-values-when-there-are-no-events/m-p/484864#M135730</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2020-01-19T15:12:33Z</dc:date>
    </item>
    <item>
      <title>Re: retrieving timechart values when there are no events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/retrieving-timechart-values-when-there-are-no-events/m-p/484865#M135731</link>
      <description>&lt;P&gt;&lt;STRONG&gt;[UPDATED ANSWER]&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;Documenting query with &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Makeresults" target="_blank"&gt;makeresults&lt;/A&gt; command for generating 60 rows for last 60 seconds.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal log_level="INFO" earliest=-60s latest=now 
| timechart span=1s count 
| fillnull value=0 
| append 
    [| makeresults count=60 
    | eval count=1 
    | accum count 
    | eval _time=_time-count 
    | eval count=0]
| dedup _time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/39858"&gt;@ashish198511&lt;/a&gt; if you intend is to &lt;CODE&gt;show a timechart of all 0 count&lt;/CODE&gt; in case search returns No Results, instead of showing the &lt;CODE&gt;No Results Found&lt;/CODE&gt; message, you can use the following append logic with &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Gentimes" target="_blank"&gt;gentimes&lt;/A&gt; (similar logic can be built with &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Makeresults" target="_blank"&gt;makeresults&lt;/A&gt; command as well). The append logic creates a timechart of 0 values and performs a final dedup to keep count from original timechart command if it exists.&lt;BR /&gt;
Following run anywhere example is based on Splunk's _internal index. Change the log_level from ERROR to FATAL (which rarely happens) and you will see that you get timechart of all 0 count instead of No Results Found.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal log_level="ERROR" earliest=-2d@d latest=now
| timechart span=1d count 
| fillnull value=0
| append
    [| gentimes start=-2 end=+1 increment=1d
    | fields starttime
    | eval _time=starttime,count=0
    | fields _time count] 
| fields - starttime
| dedup _time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Other alternative would be to build two panels with depends and rejects based on &lt;CODE&gt;$job.resultCount$&lt;/CODE&gt; and show only the panel with gentimes kind of logic above to show 0 count. The depends/rejects logic for No Results has been called out in Splunk Document as well as several questions here on Splunk Answers if you are interested in this approach.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 03:45:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/retrieving-timechart-values-when-there-are-no-events/m-p/484865#M135731</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2020-09-30T03:45:30Z</dc:date>
    </item>
    <item>
      <title>Re: retrieving timechart values when there are no events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/retrieving-timechart-values-when-there-are-no-events/m-p/484866#M135732</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;Blockquote&lt;BR /&gt;
@niketnilay Is it possible to give start and end in minutes? I am running this in a 1-minute window with span=1s&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Sun, 19 Jan 2020 19:21:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/retrieving-timechart-values-when-there-are-no-events/m-p/484866#M135732</guid>
      <dc:creator>ashish198511</dc:creator>
      <dc:date>2020-01-19T19:21:05Z</dc:date>
    </item>
    <item>
      <title>Re: retrieving timechart values when there are no events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/retrieving-timechart-values-when-there-are-no-events/m-p/484867#M135733</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index="appName" AND sourcetype="YourSourceTypeHere" AND build="xyz" AND logLevel="ERROR"
| append [| makeresults]
| timechart span=1d count(logLevel) AS value
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 19 Jan 2020 20:13:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/retrieving-timechart-values-when-there-are-no-events/m-p/484867#M135733</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2020-01-19T20:13:25Z</dc:date>
    </item>
    <item>
      <title>Re: retrieving timechart values when there are no events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/retrieving-timechart-values-when-there-are-no-events/m-p/484868#M135734</link>
      <description>&lt;P&gt;Please find updated answer!&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jan 2020 20:20:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/retrieving-timechart-values-when-there-are-no-events/m-p/484868#M135734</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2020-01-19T20:20:35Z</dc:date>
    </item>
    <item>
      <title>Re: retrieving timechart values when there are no events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/retrieving-timechart-values-when-there-are-no-events/m-p/484869#M135735</link>
      <description>&lt;P&gt;Simple solution of adding a dummy event using makeresults to ensure "No Results Found" message is not displayed! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;I went for generating dummy event for each time span &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jan 2020 20:25:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/retrieving-timechart-values-when-there-are-no-events/m-p/484869#M135735</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2020-01-19T20:25:18Z</dc:date>
    </item>
    <item>
      <title>Re: retrieving timechart values when there are no events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/retrieving-timechart-values-when-there-are-no-events/m-p/484870#M135736</link>
      <description>&lt;P&gt;till now, avoiding &lt;CODE&gt;"No Results Found"&lt;/CODE&gt; is &lt;CODE&gt;|appendpipe [eval count=0]&lt;/CODE&gt;&lt;BR /&gt;
from now,  &lt;CODE&gt;|  append [| makeresults]&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;simple and great!&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jan 2020 21:16:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/retrieving-timechart-values-when-there-are-no-events/m-p/484870#M135736</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-01-19T21:16:18Z</dc:date>
    </item>
    <item>
      <title>Re: retrieving timechart values when there are no events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/retrieving-timechart-values-when-there-are-no-events/m-p/484871#M135737</link>
      <description>&lt;P&gt;I am full of IT.  Ask anybody.&lt;/P&gt;</description>
      <pubDate>Sun, 19 Jan 2020 23:09:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/retrieving-timechart-values-when-there-are-no-events/m-p/484871#M135737</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2020-01-19T23:09:37Z</dc:date>
    </item>
    <item>
      <title>Re: retrieving timechart values when there are no events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/retrieving-timechart-values-when-there-are-no-events/m-p/484872#M135738</link>
      <description>&lt;P&gt;@woodcock this adds an additional row with value "1" when there are no events. Is there any way to skip it?&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jan 2020 03:41:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/retrieving-timechart-values-when-there-are-no-events/m-p/484872#M135738</guid>
      <dc:creator>ashish198511</dc:creator>
      <dc:date>2020-01-20T03:41:56Z</dc:date>
    </item>
    <item>
      <title>Re: retrieving timechart values when there are no events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/retrieving-timechart-values-when-there-are-no-events/m-p/484873#M135739</link>
      <description>&lt;P&gt;@woodcock realized the issue in my query. Now I am getting correct results.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jan 2020 04:35:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/retrieving-timechart-values-when-there-are-no-events/m-p/484873#M135739</guid>
      <dc:creator>ashish198511</dc:creator>
      <dc:date>2020-01-20T04:35:48Z</dc:date>
    </item>
    <item>
      <title>Re: retrieving timechart values when there are no events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/retrieving-timechart-values-when-there-are-no-events/m-p/484874#M135740</link>
      <description>&lt;P&gt;Well the answer provided by @woodcock is correct and I have accepted it as answer but the makeresults adds a row in the output. Is it possible to remove this row added by makeresults?&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jan 2020 09:37:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/retrieving-timechart-values-when-there-are-no-events/m-p/484874#M135740</guid>
      <dc:creator>ashish198511</dc:creator>
      <dc:date>2020-01-20T09:37:19Z</dc:date>
    </item>
    <item>
      <title>Re: retrieving timechart values when there are no events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/retrieving-timechart-values-when-there-are-no-events/m-p/484875#M135741</link>
      <description>&lt;P&gt;I changed your &lt;CODE&gt;count&lt;/CODE&gt; to &lt;CODE&gt;count(logLevel)&lt;/CODE&gt; which is VERY important.  You must not have added/noticed that because without that it does what you are seeing.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jan 2020 10:33:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/retrieving-timechart-values-when-there-are-no-events/m-p/484875#M135741</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2020-01-20T10:33:07Z</dc:date>
    </item>
    <item>
      <title>Re: retrieving timechart values when there are no events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/retrieving-timechart-values-when-there-are-no-events/m-p/484876#M135742</link>
      <description>&lt;P&gt;@woodcock I agree with your point. &lt;BR /&gt;
Is there a way to trim _time row added by makeresults in the final output?&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jan 2020 11:16:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/retrieving-timechart-values-when-there-are-no-events/m-p/484876#M135742</guid>
      <dc:creator>ashish198511</dc:creator>
      <dc:date>2020-01-20T11:16:54Z</dc:date>
    </item>
    <item>
      <title>Re: retrieving timechart values when there are no events</title>
      <link>https://community.splunk.com/t5/Splunk-Search/retrieving-timechart-values-when-there-are-no-events/m-p/484877#M135743</link>
      <description>&lt;P&gt;There isn't one; all events are consumed by &lt;CODE&gt;timechart&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jan 2020 12:32:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/retrieving-timechart-values-when-there-are-no-events/m-p/484877#M135743</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2020-01-20T12:32:00Z</dc:date>
    </item>
  </channel>
</rss>

