<?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: How to combine events with time range as a variable in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-combine-events-with-time-range-as-a-variable/m-p/124172#M33563</link>
    <description>&lt;P&gt;I used the map. The key for me was both endtimeu and the fact the map search command fails quietly if you try somelike eval="$myvar$" and you don't escape the quotes: eval=\"$myvar$\" within that map search.&lt;/P&gt;</description>
    <pubDate>Fri, 17 Jul 2015 21:11:18 GMT</pubDate>
    <dc:creator>dougmartin</dc:creator>
    <dc:date>2015-07-17T21:11:18Z</dc:date>
    <item>
      <title>How to combine events with time range as a variable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-combine-events-with-time-range-as-a-variable/m-p/124169#M33560</link>
      <description>&lt;P&gt;I have a log table and I need to match up the user_id with potential PRE log-in user_ids&lt;BR /&gt;
user_id | page_referer | event_time&lt;BR /&gt;
1199      | blah.com/sign_in | 01/02/2015 1:01:33 am&lt;BR /&gt;
2244      | blah.com/sign_in | 01/22/2015 7:55:33 am&lt;/P&gt;

&lt;P&gt;user_id | page_referer | event_time&lt;BR /&gt;
2200      | blah.com/before_sign_in | 01/02/2015 1:01:25 am&lt;BR /&gt;
4488      | blah.com/before_sign_in | 01/22/2015 7:55:12 am&lt;BR /&gt;
4499      | blah.com/before_sign_in | 01/22/2015 7:55:15 am&lt;/P&gt;

&lt;P&gt;so 1199 should matchup with 2200 and 2244 match up with 4488 &amp;amp; 4499 in a result like this:&lt;BR /&gt;
user_id | other user_id (MV field ok)&lt;BR /&gt;
1199     | 2200&lt;BR /&gt;
2244     | 4488, 4499&lt;/P&gt;

&lt;P&gt;Part of the problem I'm having is how to construct a subsearch, or join (or appendcols, etc) where I need to use the event_timestamp as a search ( event_timestamp-90 as the lower range and event_timestamp as the upper range).&lt;BR /&gt;
I could end up with the final result table, or some other join/transaction that can group these pre/post login user_ids.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 06:41:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-combine-events-with-time-range-as-a-variable/m-p/124169#M33560</guid>
      <dc:creator>dougmartin</dc:creator>
      <dc:date>2020-09-29T06:41:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine events with time range as a variable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-combine-events-with-time-range-as-a-variable/m-p/124170#M33561</link>
      <description>&lt;P&gt;Eww. True time windowing is hard. Bucketing is easier, but loses potential matches across a minute boundary. And, if your logs are dense and full over overlapping events, this is hopeless. &lt;/P&gt;

&lt;P&gt;Try something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;yoursearch | eval post_login=if(match(page_referer,"blah.com/sign_in "),user_id,null())
 | pre_login=if(match(page_referer,"blah.com/before_sign_in "),user_id,null())
 | stats values(pre_login) AS pre_login, values(post_login) AS post_login  by _time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That makes a &lt;EM&gt;ton&lt;/EM&gt; of assumptions about your data, but if your events are sparse it might be good enough. &lt;/P&gt;

&lt;P&gt;Another approach, closer to what you are thinking, is to use &lt;CODE&gt;localize&lt;/CODE&gt; &amp;amp; &lt;CODE&gt;map&lt;/CODE&gt;. If you have lots of data, this won't scale. If you have lots of overlapping logins, this won't work. &lt;/P&gt;

&lt;P&gt;This is a &lt;EM&gt;rough&lt;/EM&gt; example of what to try, I don't use this command, so my syntax may be sketchy.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;page_referer ="blah.com/sign_in" | localize timebefore=90s timeafter=0 
| map search="search page_referer=* starttimeu=$starttime$ endtimeu=$endtime$ | eval post_login=if(match(page_referer,'blah.com/sign_in '),user_id,null()) | pre_login=if(match(page_referer,'blah.com/before_sign_in '),user_id,null()) |  stats values(pre_login) AS pre_login, values(post_login) AS post_login"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That is a pretty ghetto example. Expect to do some debugging. I just hope it gives you some ideas.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jul 2015 16:44:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-combine-events-with-time-range-as-a-variable/m-p/124170#M33561</guid>
      <dc:creator>jacobwilkins</dc:creator>
      <dc:date>2015-07-15T16:44:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine events with time range as a variable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-combine-events-with-time-range-as-a-variable/m-p/124171#M33562</link>
      <description>&lt;P&gt;Here's an alternative approach:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your search for blah.com/sign_in OR blah.com/before_sign_in | transaction maxspan=90s endswith="blah.com/sign_in" startswith="blah.com/before_sign_in"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This may need a "dummy" transaction field, if so you could for example use &lt;CODE&gt;sourcetype&lt;/CODE&gt; if all events are from the same sourcetype. This also will not work if you have overlapping transactions, this problem is intrinsic to your log files - you'd need some differentiator such as a session ID to tell overlapping transactions apart. This also may not succeed in adding both pre-events to your login event.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jul 2015 22:02:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-combine-events-with-time-range-as-a-variable/m-p/124171#M33562</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2015-07-15T22:02:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to combine events with time range as a variable</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-combine-events-with-time-range-as-a-variable/m-p/124172#M33563</link>
      <description>&lt;P&gt;I used the map. The key for me was both endtimeu and the fact the map search command fails quietly if you try somelike eval="$myvar$" and you don't escape the quotes: eval=\"$myvar$\" within that map search.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Jul 2015 21:11:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-combine-events-with-time-range-as-a-variable/m-p/124172#M33563</guid>
      <dc:creator>dougmartin</dc:creator>
      <dc:date>2015-07-17T21:11:18Z</dc:date>
    </item>
  </channel>
</rss>

