<?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: Using IF with multiple conditions in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Using-IF-with-multiple-conditions/m-p/340351#M5183</link>
    <description>&lt;P&gt;Hi @DalJeanis&lt;BR /&gt;
I made a mistake. I send a message but it didn't appear.&lt;BR /&gt;
The last solution sned by @gvmorley works perfect.&lt;BR /&gt;
Best regards&lt;BR /&gt;
Laurent &lt;/P&gt;</description>
    <pubDate>Tue, 07 Mar 2017 00:57:51 GMT</pubDate>
    <dc:creator>LNebout</dc:creator>
    <dc:date>2017-03-07T00:57:51Z</dc:date>
    <item>
      <title>Using IF with multiple conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Using-IF-with-multiple-conditions/m-p/340342#M5174</link>
      <description>&lt;P&gt;Hi Splunkers,&lt;BR /&gt;
The partner of my company send me a new log file with more details.....&lt;BR /&gt;
i do apologise for the inconvenience。 本当にごめんなさい！！！&lt;BR /&gt;
On the new log file , I have an event to define the beginning :&lt;BR /&gt;
LOG IN -- &amp;gt;               Mar 1 21:45:41 XDSauth: 1488433541 |ConnectorSession.setNextServiceName |next service name = X&lt;BR /&gt;
                                  Mar 1 21:45:41 XDSauth: 1488433541 |ServiceHdlr.serviceTerminated |next service = X&lt;BR /&gt;
LOG OUT --&amp;gt;            Mar 1 21:47:05 XDSauth: 1488433625 |ServiceHdlr.serviceTerminated |next service = X &lt;BR /&gt;
Where X is the user name.&lt;/P&gt;

&lt;P&gt;But the problem is : ServiceHdlr.serviceTerminated&lt;BR /&gt;
I have this event twice.&lt;BR /&gt;
One after ConnectorSession.setNextServiceName and the next is to define the end of connection.&lt;/P&gt;

&lt;P&gt;I tried a new approach :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=XDSauth | fieldformat Epoch_Time = strftime(Epoch_Time, "%F %T.%3N")  
 | rex field=_raw ".*\d+\|.+\|\d+\|(?&amp;lt;fld_key&amp;gt;[^ ]+)\s.*" 
 | where User="WIN7-007" |table User, Status , Epoch_Time  , fld_key  
 |streamstats count current=t reset_on_change=true by fld_key
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Result :&lt;BR /&gt;
User                Status                                                                          Epoch_Time                              fld_key          count&lt;BR /&gt;
WIN7-007    ServiceHdlr.serviceTerminated                                2017-03-02 14:47:05.000     145c414    1&lt;BR /&gt;
WIN7-007    ServiceHdlr.serviceTerminated                                2017-03-02 14:45:41.000     3a4822         1&lt;BR /&gt;&lt;BR /&gt;
WIN7-007    ConnectorSession.setNextServiceName              2017-03-02 14:45:39.000     3a4822         2   &lt;/P&gt;

&lt;P&gt;If it's possible I would like to obtain this result :&lt;BR /&gt;
User                Status                                                                          Epoch_Time                              fld_key          count&lt;BR /&gt;
WIN7-007    ServiceHdlr.serviceTerminated                                2017-03-02 14:45:41.000     3a4822         1&lt;BR /&gt;&lt;BR /&gt;
WIN7-007    ConnectorSession.setNextServiceName              2017-03-02 14:45:39.000     3a4822         2&lt;/P&gt;

&lt;P&gt;Delete the ServiceHdlr.serviceTerminated line  where fld_key of ServiceHdlr.serviceTerminated is different than  fld_key of ConnectorSession.setNextServiceName&lt;/P&gt;

&lt;P&gt;Have a nice day&lt;BR /&gt;
Laurent&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 13:08:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Using-IF-with-multiple-conditions/m-p/340342#M5174</guid>
      <dc:creator>LNebout</dc:creator>
      <dc:date>2020-09-29T13:08:07Z</dc:date>
    </item>
    <item>
      <title>Re: Using IF with multiple conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Using-IF-with-multiple-conditions/m-p/340343#M5175</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;Not sure if this is exactly what you're looking for, but you could try using a &lt;CODE&gt;transaction&lt;/CODE&gt; for this.&lt;/P&gt;

&lt;P&gt;This first bit of code is to simulate your data:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval _raw="Mar 1 21:45:39 XDSauth: 1488433539 |ConnectorSession.setNextServiceName |next service name = WIN7-007" | eval fld_key="3a4822"
| append [|makeresults | eval _raw="Mar 1 21:45:41 XDSauth: 1488433541 |ServiceHdlr.serviceTerminated |next service = WIN7-007" | eval fld_key="3a4822"]
| append [|makeresults | eval _raw="Mar 1 21:47:05 XDSauth: 1488433625 |ServiceHdlr.serviceTerminated |next service = WIN7-007" | eval fld_key="145c414"]
| fields - _time
| rex "^(?&amp;lt;org_time&amp;gt;\w{3}\s\d{1,2}\s\d{2}:\d{2}:\d{2})\s\w+:\s(?&amp;lt;epoch_time&amp;gt;\d+)\s\|(?&amp;lt;status&amp;gt;[^|]+)\s\|[^=]+=\s(?&amp;lt;user&amp;gt;.+)$"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Which give us:&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/2586i4D86158271B8BACF/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Note: Your example logs and subsequent results are slightly different with regards to time. I've used the data where all of the times are different, as I suspect this is more likely to be the case.&lt;/P&gt;

&lt;P&gt;As we're going to use transaction, we need a &lt;CODE&gt;_time&lt;/CODE&gt; field, so just &lt;CODE&gt;eval&lt;/CODE&gt; this with:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval _time=epoch_time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;We'll also want to &lt;CODE&gt;sort&lt;/CODE&gt; the data by this &lt;CODE&gt;_time&lt;/CODE&gt; field, so that transaction is consistent with regards to start and end.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| sort - _time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Next, use a transaction where you define the &lt;CODE&gt;startswith&lt;/CODE&gt; and &lt;CODE&gt;endswith&lt;/CODE&gt; parameters. We also want to keep all of the fields as multi-value fields, so use &lt;CODE&gt;mvlist=t&lt;/CODE&gt;. Finally, we're saying that there will only be 2 events in each &lt;CODE&gt;transaction&lt;/CODE&gt; and that the user and fld_key will how we do the grouping.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| transaction mvlist=t maxevents=2 startswith=eval(status == "ConnectorSession.setNextServiceName") endswith=eval(status == "ServiceHdlr.serviceTerminated") fld_key user
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;We only want the transactions. I.e. we don't want that 3rd event which you were looking to get rid of. So:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| where eventcount=2
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Finally, we can use &lt;CODE&gt;stats&lt;/CODE&gt; to get the results, format the times to be a bit more readable and drop the &lt;CODE&gt;_time&lt;/CODE&gt; field as we don't need it:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| stats first(eval(mvsort(epoch_time))) as earliest last(eval(mvsort(epoch_time))) as latest values(duration) as duration values(status) as status by _time,user,fld_key
| eval earliest=strftime(earliest,"%d-%m-%Y %H:%M:%S"), latest=strftime(latest,"%d-%m-%Y %H:%M:%S")
| fields - _time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Which should then look like this:&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/2587i3005D8EFCF4A72AB/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;Again, I'm not 100% sure this is what you're looking for, but it's another approach. Just be careful with the parameters for the &lt;CODE&gt;transaction&lt;/CODE&gt; command, to ensure that it fits with your data.&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;Here's the whole thing, as it may be easier to copy and paste:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw="Mar 1 21:45:39 XDSauth: 1488433539 |ConnectorSession.setNextServiceName |next service name = WIN7-007" 
| eval fld_key="3a4822" 
| append 
    [| makeresults 
    | eval _raw="Mar 1 21:45:41 XDSauth: 1488433541 |ServiceHdlr.serviceTerminated |next service = WIN7-007" 
    | eval fld_key="3a4822"] 
| append 
    [| makeresults 
    | eval _raw="Mar 1 21:47:05 XDSauth: 1488433625 |ServiceHdlr.serviceTerminated |next service = WIN7-007" 
    | eval fld_key="145c414"] 
| fields - _time 
| rex "^(?&amp;lt;org_time&amp;gt;\w{3}\s\d{1,2}\s\d{2}:\d{2}:\d{2})\s\w+:\s(?&amp;lt;epoch_time&amp;gt;\d+)\s\|(?&amp;lt;status&amp;gt;[^|]+)\s\|[^=]+=\s(?&amp;lt;user&amp;gt;.+)$" 
| eval _time=epoch_time 
| sort - _time 
| transaction mvlist=t maxevents=2 startswith=eval(status == "ConnectorSession.setNextServiceName") endswith=eval(status == "ServiceHdlr.serviceTerminated") fld_key user 
| where eventcount=2 
| stats first(eval(mvsort(epoch_time))) as earliest last(eval(mvsort(epoch_time))) as latest values(duration) as duration values(status) as status by _time,user,fld_key 
| eval earliest=strftime(earliest,"%d-%m-%Y %H:%M:%S"), latest=strftime(latest,"%d-%m-%Y %H:%M:%S") 
| fields - _time
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Mar 2017 03:30:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Using-IF-with-multiple-conditions/m-p/340343#M5175</guid>
      <dc:creator>gvmorley</dc:creator>
      <dc:date>2017-03-06T03:30:56Z</dc:date>
    </item>
    <item>
      <title>Re: Using IF with multiple conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Using-IF-with-multiple-conditions/m-p/340344#M5176</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/76202"&gt;@gvmorley&lt;/a&gt;&lt;BR /&gt;
Thanks for your message and solution.&lt;BR /&gt;
I'm so sorry , i made a mistake on my question.&lt;BR /&gt;
Mistake : &lt;BR /&gt;
Delete the ServiceHdlr.serviceTerminated line where fld_key of ServiceHdlr.serviceTerminated is different than fld_key of ConnectorSession.setNextServiceName&lt;/P&gt;

&lt;P&gt;Good question :&lt;BR /&gt;
Delete the ServiceHdlr.serviceTerminated line where fld_key of ServiceHdlr.serviceTerminated is &lt;STRONG&gt;same&lt;/STRONG&gt; than fld_key of ConnectorSession.setNextServiceName&lt;/P&gt;

&lt;P&gt;I'M sorry &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/76202"&gt;@gvmorley&lt;/a&gt;&lt;BR /&gt;
Laurent&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 13:08:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Using-IF-with-multiple-conditions/m-p/340344#M5176</guid>
      <dc:creator>LNebout</dc:creator>
      <dc:date>2020-09-29T13:08:10Z</dc:date>
    </item>
    <item>
      <title>Re: Using IF with multiple conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Using-IF-with-multiple-conditions/m-p/340345#M5177</link>
      <description>&lt;P&gt;Just add this to your base search to throw away any "singletons":&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eventstats count AS count_for_this_fld_key BY user fld_key | search count_for_this_fld_key&amp;gt;1 | fields - count_for_this_fld_key
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Mar 2017 05:10:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Using-IF-with-multiple-conditions/m-p/340345#M5177</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-03-06T05:10:50Z</dc:date>
    </item>
    <item>
      <title>Re: Using IF with multiple conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Using-IF-with-multiple-conditions/m-p/340346#M5178</link>
      <description>&lt;P&gt;Thanks for your message but i made a mistake on my question......&lt;BR /&gt;
I have this :&lt;BR /&gt;
Line 1 --&amp;gt; WIN7-007 ServiceHdlr.serviceTerminated 2017-03-02 14:47:05.000 145c414 1&lt;BR /&gt;
Line 2 --&amp;gt; WIN7-007 ServiceHdlr.serviceTerminated 2017-03-02 14:45:41.000 3a4822 1 &lt;BR /&gt;
Line 3 --&amp;gt; WIN7-007 ConnectorSession.setNextServiceName 2017-03-02 14:45:39.000 3a4822 2&lt;/P&gt;

&lt;P&gt;I want to delete &lt;BR /&gt;
Line 2 --&amp;gt;WIN7-007 ServiceHdlr.serviceTerminated 2017-03-02 14:45:41.000 3a4822 1 &lt;/P&gt;

&lt;P&gt;And obtain the result :&lt;BR /&gt;
Line 1 --&amp;gt; WIN7-007 ServiceHdlr.serviceTerminated 2017-03-02 14:47:05.000 145c414 1&lt;BR /&gt;
Line 3 --&amp;gt; WIN7-007 ConnectorSession.setNextServiceName 2017-03-02 14:45:39.000 3a4822 2&lt;/P&gt;

&lt;P&gt;Sorry @woodcock&lt;BR /&gt;
Laurent&lt;/P&gt;</description>
      <pubDate>Mon, 06 Mar 2017 05:16:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Using-IF-with-multiple-conditions/m-p/340346#M5178</guid>
      <dc:creator>LNebout</dc:creator>
      <dc:date>2017-03-06T05:16:50Z</dc:date>
    </item>
    <item>
      <title>Re: Using IF with multiple conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Using-IF-with-multiple-conditions/m-p/340347#M5179</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;You could try:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw="Mar 1 21:45:39 XDSauth: 1488433539 |ConnectorSession.setNextServiceName |next service name = WIN7-007" 
| eval fld_key="3a4822" 
| append 
    [| makeresults 
    | eval _raw="Mar 1 21:45:41 XDSauth: 1488433541 |ServiceHdlr.serviceTerminated |next service = WIN7-007" 
    | eval fld_key="3a4822"] 
| append 
    [| makeresults 
    | eval _raw="Mar 1 21:47:05 XDSauth: 1488433625 |ServiceHdlr.serviceTerminated |next service = WIN7-007" 
    | eval fld_key="145c414"] 
| fields - _time 
| rex "^(?&amp;lt;orig_time&amp;gt;\w{3}\s\d{1,2}\s\d{2}:\d{2}:\d{2})\s\w+:\s(?&amp;lt;epoch_time&amp;gt;\d+)\s\|(?&amp;lt;status&amp;gt;[^|]+)\s\|[^=]+=\s(?&amp;lt;user&amp;gt;.+)$" 
| eval _time=epoch_time
| sort + _time
| eval user_key=user."-".fld_key
| dedup user_key
| sort - _time
| table user status epoch_time fld_key
| eval epoch_time=strftime(epoch_time,"%d-%m-%Y %H:%M:%S")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It will keep the earliest event where fld_key and user are the same. It's hard to tell without seeing the data, but if this is always the "ConnectorSession" event, then you should be OK.&lt;/P&gt;

&lt;P&gt;You'll definitely need to test this against a much larger set of data, to make sure that the assumptions are correct.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Mar 2017 14:48:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Using-IF-with-multiple-conditions/m-p/340347#M5179</guid>
      <dc:creator>gvmorley</dc:creator>
      <dc:date>2017-03-06T14:48:16Z</dc:date>
    </item>
    <item>
      <title>Re: Using IF with multiple conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Using-IF-with-multiple-conditions/m-p/340348#M5180</link>
      <description>&lt;P&gt;OK, then this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | eventstats count AS count_for_this_fld_key BY user fld_key | search count_for_this_fld_key=1 OR ConnectorSession | fields - count_for_this_fld_key
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Mar 2017 15:01:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Using-IF-with-multiple-conditions/m-p/340348#M5180</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-03-06T15:01:12Z</dc:date>
    </item>
    <item>
      <title>Re: Using IF with multiple conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Using-IF-with-multiple-conditions/m-p/340349#M5181</link>
      <description>&lt;P&gt;That's work perfectly !!!!!!!!!!!!!!!!!!!!!&lt;BR /&gt;
Thanks !!!!!!&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 00:40:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Using-IF-with-multiple-conditions/m-p/340349#M5181</guid>
      <dc:creator>LNebout</dc:creator>
      <dc:date>2017-03-07T00:40:56Z</dc:date>
    </item>
    <item>
      <title>Re: Using IF with multiple conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Using-IF-with-multiple-conditions/m-p/340350#M5182</link>
      <description>&lt;P&gt;... you said delete it where it is different, but your example has deleted the one that matched.  &lt;/P&gt;

&lt;P&gt;Which do you want?&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 00:53:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Using-IF-with-multiple-conditions/m-p/340350#M5182</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-03-07T00:53:48Z</dc:date>
    </item>
    <item>
      <title>Re: Using IF with multiple conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Using-IF-with-multiple-conditions/m-p/340351#M5183</link>
      <description>&lt;P&gt;Hi @DalJeanis&lt;BR /&gt;
I made a mistake. I send a message but it didn't appear.&lt;BR /&gt;
The last solution sned by @gvmorley works perfect.&lt;BR /&gt;
Best regards&lt;BR /&gt;
Laurent &lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 00:57:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Using-IF-with-multiple-conditions/m-p/340351#M5183</guid>
      <dc:creator>LNebout</dc:creator>
      <dc:date>2017-03-07T00:57:51Z</dc:date>
    </item>
    <item>
      <title>Re: Using IF with multiple conditions</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Using-IF-with-multiple-conditions/m-p/340352#M5184</link>
      <description>&lt;P&gt;You need to avoid &lt;CODE&gt;transaction&lt;/CODE&gt; if at all possible.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 21:19:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Using-IF-with-multiple-conditions/m-p/340352#M5184</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-03-07T21:19:46Z</dc:date>
    </item>
  </channel>
</rss>

