<?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: Time from Sub-query is Empty in Splunk Enterprise</title>
    <link>https://community.splunk.com/t5/Splunk-Enterprise/How-to-display-the-Time-SavedTime-from-the-saved-sourcetype/m-p/645380#M16479</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/214410"&gt;@isoutamo&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Thanks, my bad. I'm wondering how I missed that, really a good catch. I've adjusted the query and everything is working fine. But the update part is not working as I wish. I want to update the existing event from the&amp;nbsp;saved_sourcetype, but it's insering it as newEvent. Could you please advise whether this is how it works or is there a work-around to update the existing event.&lt;BR /&gt;&lt;BR /&gt;&amp;lt;/&amp;gt;source=testSource&lt;BR /&gt;| stats count earliest(_time) as time first(host) as host first(source) as source by EventCode&lt;BR /&gt;| join type=left EventCode [ search index=main sourcetype=saved_sourcetype earliest=1 latest=now()&lt;BR /&gt;| stats count as Known Values(Time) as SavedTime by EventCode]&lt;BR /&gt;| fillnull Known value=0&lt;BR /&gt;| eval SavedTime = coalesce(SavedTime, "N/A")&lt;BR /&gt;| eval savedTime=strptime(SavedTime, "%Y-%m-%d %H:%M:%S")&lt;BR /&gt;| eval insertRequired=if(Known=0, "Yes", "No")&lt;BR /&gt;| eval UpdateRequired=if(time &amp;lt; savedTime , "Yes", "No")&lt;BR /&gt;| eval SaveAction=case(&lt;BR /&gt;insertRequired == "Yes" AND UpdateRequired != "Yes", "insert",&lt;BR /&gt;UpdateRequired == "Yes", "update",&lt;BR /&gt;1=1, "ignore"&lt;BR /&gt;)&lt;BR /&gt;| where SaveAction != "ignore"&lt;BR /&gt;| eval SavedTime = if(SaveAction == "update", strftime(time, "%Y-%m-%d %H:%M:%S"), SavedTime)&lt;BR /&gt;| eval Time=strftime(time, "%Y-%m-%d %H:%M:%S")&lt;BR /&gt;| stats values(SavedTime) as SavedTime latest(Time) as Time values(Known) as Known first(host) as host last(source) as source values(SaveAction) as SaveAction, values(insertRequired) as insertRequired values(UpdateRequired) as UpdateRequired by EventCode&lt;BR /&gt;| fields - SavedTime, Known&lt;BR /&gt;| collect index=main sourcetype="saved_sourcetype"&amp;lt;/&amp;gt;&lt;/P&gt;</description>
    <pubDate>Fri, 02 Jun 2023 05:15:55 GMT</pubDate>
    <dc:creator>Thulasinathan_M</dc:creator>
    <dc:date>2023-06-02T05:15:55Z</dc:date>
    <item>
      <title>How to display the Time(SavedTime) from the saved sourcetype?</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/How-to-display-the-Time-SavedTime-from-the-saved-sourcetype/m-p/645335#M16476</link>
      <description>&lt;P&gt;I'm trying to store the results into a source_type and use the saved sourcetype to check whether the Event is already there in saved sourcetype or not. If it's not in saved sourcetype, I'm inserting the event. If the event is there in sourcetype and the time is greater than the time from current search then I'm updating the event with the earliest event. But the below query fails to display the Time(SavedTime) from the saved sourcetype and my query is failing to update events. Any advise would be very much appreciated. Thanks in advance!!&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;source=testSource
| stats count earliest(_time) as Time first(host) as host first(source) as source by EventCode
| join type=left EventCode [ search index=main sourcetype=saved_sourcetype | eval savedTime=strptime(Time, "%Y-%m-%d %H:%M:%S")
| stats count as Known values(Time) as sTime values(host) as host values(source) as source by EventCode]
| fillnull Known value=0
| eval insertRequired=if(Known=0, "Yes", "No")
| eval UpdateRequired=if(Time &amp;lt; savedTime , "Yes", "No")
| eval SaveAction=case(
insertRequired == "Yes" AND UpdateRequired != "Yes", "insert",
UpdateRequired == "Yes", "update",
1=1, "ignore"
)
| eval Time=strftime(Time, "%Y-%m-%d %H:%M:%S")
| stats count earliest(savedTime) as savedTime latest(Time) as Time values(Known) as Known first(host) as host last(source) as source by EventCode, SaveAction, insertRequired, UpdateRequired&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jun 2023 14:03:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/How-to-display-the-Time-SavedTime-from-the-saved-sourcetype/m-p/645335#M16476</guid>
      <dc:creator>Thulasinathan_M</dc:creator>
      <dc:date>2023-06-01T14:03:24Z</dc:date>
    </item>
    <item>
      <title>Re: Time from Sub-query is Empty</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/How-to-display-the-Time-SavedTime-from-the-saved-sourcetype/m-p/645376#M16478</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;If I look this correctly, you haven't any savedTime on stats in sub search?&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| join type=left EventCode 
    [ search index=main sourcetype=saved_sourcetype 
    | eval savedTime=strptime(Time, "%Y-%m-%d %H:%M:%S") 
    | stats count as Known values(Time) as sTime values(host) as host values(source) as source by EventCode] 
| fillnull Known value=0 &lt;/LI-CODE&gt;&lt;P&gt;If you want that savedTime exists after stats you must add it into stats' parameters.&lt;/P&gt;&lt;P&gt;Maybe this should be&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;    [ search index=main sourcetype=saved_sourcetype 
    | eval savedTime=strptime(Time, "%Y-%m-%d %H:%M:%S") 
    | stats count as Known values(savedTime) as savedTime values(host) as host values(source) as source by EventCode] &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;r. Ismo&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jun 2023 14:03:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/How-to-display-the-Time-SavedTime-from-the-saved-sourcetype/m-p/645376#M16478</guid>
      <dc:creator>isoutamo</dc:creator>
      <dc:date>2023-06-01T14:03:06Z</dc:date>
    </item>
    <item>
      <title>Re: Time from Sub-query is Empty</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/How-to-display-the-Time-SavedTime-from-the-saved-sourcetype/m-p/645380#M16479</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/214410"&gt;@isoutamo&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Thanks, my bad. I'm wondering how I missed that, really a good catch. I've adjusted the query and everything is working fine. But the update part is not working as I wish. I want to update the existing event from the&amp;nbsp;saved_sourcetype, but it's insering it as newEvent. Could you please advise whether this is how it works or is there a work-around to update the existing event.&lt;BR /&gt;&lt;BR /&gt;&amp;lt;/&amp;gt;source=testSource&lt;BR /&gt;| stats count earliest(_time) as time first(host) as host first(source) as source by EventCode&lt;BR /&gt;| join type=left EventCode [ search index=main sourcetype=saved_sourcetype earliest=1 latest=now()&lt;BR /&gt;| stats count as Known Values(Time) as SavedTime by EventCode]&lt;BR /&gt;| fillnull Known value=0&lt;BR /&gt;| eval SavedTime = coalesce(SavedTime, "N/A")&lt;BR /&gt;| eval savedTime=strptime(SavedTime, "%Y-%m-%d %H:%M:%S")&lt;BR /&gt;| eval insertRequired=if(Known=0, "Yes", "No")&lt;BR /&gt;| eval UpdateRequired=if(time &amp;lt; savedTime , "Yes", "No")&lt;BR /&gt;| eval SaveAction=case(&lt;BR /&gt;insertRequired == "Yes" AND UpdateRequired != "Yes", "insert",&lt;BR /&gt;UpdateRequired == "Yes", "update",&lt;BR /&gt;1=1, "ignore"&lt;BR /&gt;)&lt;BR /&gt;| where SaveAction != "ignore"&lt;BR /&gt;| eval SavedTime = if(SaveAction == "update", strftime(time, "%Y-%m-%d %H:%M:%S"), SavedTime)&lt;BR /&gt;| eval Time=strftime(time, "%Y-%m-%d %H:%M:%S")&lt;BR /&gt;| stats values(SavedTime) as SavedTime latest(Time) as Time values(Known) as Known first(host) as host last(source) as source values(SaveAction) as SaveAction, values(insertRequired) as insertRequired values(UpdateRequired) as UpdateRequired by EventCode&lt;BR /&gt;| fields - SavedTime, Known&lt;BR /&gt;| collect index=main sourcetype="saved_sourcetype"&amp;lt;/&amp;gt;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jun 2023 05:15:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/How-to-display-the-Time-SavedTime-from-the-saved-sourcetype/m-p/645380#M16479</guid>
      <dc:creator>Thulasinathan_M</dc:creator>
      <dc:date>2023-06-02T05:15:55Z</dc:date>
    </item>
    <item>
      <title>Re: Time from Sub-query is Empty</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/How-to-display-the-Time-SavedTime-from-the-saved-sourcetype/m-p/645383#M16480</link>
      <description>&lt;P&gt;Please use &amp;lt;/&amp;gt; block on editor when you paste code! It's much easier to read and we can be sure that it's exactly what you have paste.&lt;/P&gt;&lt;P&gt;I see there a couple of issues:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;SavedTime and savedTime are two separate variables (maybe editor has changed those and both are using same CamelCases?)&lt;/LI&gt;&lt;LI&gt;You cannot use&amp;nbsp;savedTime=strptime(SavedTime, "%Y-%m-%d %H:%M:%S") for mv variable, if returns always null, not converted values&lt;/LI&gt;&lt;LI&gt;You couldn't do strptime for value "N/A"&lt;/LI&gt;&lt;LI&gt;Use always index=&amp;lt;your index&amp;gt; on search, you cannot be sure what are users default search indexes!&lt;/LI&gt;&lt;LI&gt;Try to avoid to use main index! Always create separate indexes for different purposes, even on your own test instance&lt;/LI&gt;&lt;LI&gt;When you have only couple of values (e.g. in SaveAction) it's better to use SaveAction in ("insert", "update") instead of use SaveAction != "ignore". Splunk is not good for look negations in performance point of view.&amp;nbsp;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jun 2023 14:32:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/How-to-display-the-Time-SavedTime-from-the-saved-sourcetype/m-p/645383#M16480</guid>
      <dc:creator>isoutamo</dc:creator>
      <dc:date>2023-06-01T14:32:53Z</dc:date>
    </item>
    <item>
      <title>Re: Time from Sub-query is Empty</title>
      <link>https://community.splunk.com/t5/Splunk-Enterprise/How-to-display-the-Time-SavedTime-from-the-saved-sourcetype/m-p/645387#M16481</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/253572"&gt;@Thulasinathan_M&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/214410"&gt;@isoutamo&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Thanks, my bad. I'm wondering how I missed that, really a good catch. I've adjusted the query and everything is working fine. But the update part is not working as I wish. I want to update the existing event from the&amp;nbsp;saved_sourcetype, but it's insering it as newEvent. Could you please advise whether this is how it works or is there a work-around to update the existing event.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;The &lt;FONT face="courier new,courier"&gt;collect&lt;/FONT&gt; command only writes new events.&amp;nbsp; Indexed events cannot be changed in any way, by any method.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jun 2023 14:45:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Enterprise/How-to-display-the-Time-SavedTime-from-the-saved-sourcetype/m-p/645387#M16481</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2023-06-01T14:45:08Z</dc:date>
    </item>
  </channel>
</rss>

