<?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: double fields If Statements in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/double-fields-If-Statements/m-p/481753#M135000</link>
    <description>&lt;P&gt;-HI &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/190455"&gt;@mklhs&lt;/a&gt;,&lt;BR /&gt;
could you share a sample?&lt;BR /&gt;
I try to interpret you need:&lt;BR /&gt;
you have a transation identified by an ID that's the same in all events on server_a and server_b,&lt;BR /&gt;
you want to calculate the time difference between these two servers (latency) and then the time difference from server_b to server_a,&lt;BR /&gt;
to calculate the first you have two events with the same ID=12345 like these&lt;BR /&gt;
2019-11-11 12:09:20 server_a 12345&lt;BR /&gt;
2019-11-11 12:09:30 server_b 12345&lt;BR /&gt;
so the difference is 10 seconds.&lt;BR /&gt;
Then you have:&lt;BR /&gt;
2019-11-11 12:09:40 server_b 12345&lt;BR /&gt;
2019-11-11 12:09:55 server_a 12345&lt;BR /&gt;
so the difference is 15 seconds.&lt;BR /&gt;
You want to display these latecies, is it correct?&lt;/P&gt;

&lt;P&gt;So you can run something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval host="server_a", time="2019-11-11 12:10:10", ID="12345"
| append [ | makeresults | eval host="server_b", time="2019-11-11 12:10:20", ID="12345" ]
| append [ | makeresults | eval host="server_b", time="2019-11-11 12:10:30", ID="12345" ]
| append [ | makeresults | eval host="server_a", time="2019-11-11 12:10:45", ID="12345" ]
| stats first(eval(if(host="server_a",time,NULL))) AS first_a first(eval(if(host="server_b",time,NULL))) AS first_b last(eval(if(host="server_a",time,NULL))) AS last_a last(eval(if(host="server_b",time,NULL))) AS last_b BY ID
| eval latency_1=strptime(first_b,"%Y-%m-%d %H:%M:%S")-strptime(first_a,"%Y-%m-%d %H:%M:%S"), latency_2=strptime(last_a,"%Y-%m-%d %H:%M:%S")-strptime(last_b,"%Y-%m-%d %H:%M:%S")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Ciao.&lt;BR /&gt;
Giuseppe&lt;/P&gt;</description>
    <pubDate>Wed, 30 Sep 2020 02:55:03 GMT</pubDate>
    <dc:creator>gcusello</dc:creator>
    <dc:date>2020-09-30T02:55:03Z</dc:date>
    <item>
      <title>double fields If Statements</title>
      <link>https://community.splunk.com/t5/Splunk-Search/double-fields-If-Statements/m-p/481750#M134997</link>
      <description>&lt;P&gt;Hello Guys,&lt;/P&gt;

&lt;P&gt;i try to generate different fields using if 2.&lt;/P&gt;

&lt;P&gt;I would like to write a query which looks at the following:&lt;/P&gt;

&lt;P&gt;if sender==x then eval field_a==time_a and eval field_b==time_b&lt;BR /&gt;
if else sender===y then eval field_x==time and eval field_y==time_y&lt;/P&gt;

&lt;P&gt;To the general scenario I want to calculate the duration of the processing of log files. For this log files are sent from a server_a to a server_b where they are processed and sent back to server_a.&lt;/P&gt;

&lt;P&gt;Here I want to write a query which calculates how long the file needs from server_a to server_b... how long from server_b to server_a and total duration... speaks server_a -&amp;gt; server_b -&amp;gt; server_a&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 02:55:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/double-fields-If-Statements/m-p/481750#M134997</guid>
      <dc:creator>mklhs</dc:creator>
      <dc:date>2020-09-30T02:55:54Z</dc:date>
    </item>
    <item>
      <title>Re: double fields If Statements</title>
      <link>https://community.splunk.com/t5/Splunk-Search/double-fields-If-Statements/m-p/481751#M134998</link>
      <description>&lt;P&gt;HI mklhs,&lt;BR /&gt;
it isn't so clear for me the values when the if conditions are false: &lt;BR /&gt;
in Splunk you use the if condition in an eval command, inserting the condition to verify and the values for condition=true and condition=false:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval field=if(condition,value_for condition_true,value_for condition_false)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Anyway, you can use if condition in an eval command, something like this (using the value "no time" when the if condition is false:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your_search
| eval field_a=if(sender="x",time_a,"no time"), field_b=if(sender="x",time_b,"no time"), field_x=if(sender="y",time_x,"no time"), field_y=if(sender="y",time_y,"no time")
| ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You can see more at &lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonEvalFunctions"&gt;https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/CommonEvalFunctions&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Ciao.&lt;BR /&gt;
Giuseppe&lt;/P&gt;</description>
      <pubDate>Mon, 11 Nov 2019 10:48:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/double-fields-If-Statements/m-p/481751#M134998</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2019-11-11T10:48:22Z</dc:date>
    </item>
    <item>
      <title>Re: double fields If Statements</title>
      <link>https://community.splunk.com/t5/Splunk-Search/double-fields-If-Statements/m-p/481752#M134999</link>
      <description>&lt;P&gt;Thank you very much for your answer! Unfortunately it is not what I am looking for. I would like to set up a monitoring to detect if the latency of the file processing is too high. I have to calculate the time from server_a to server_b and back again. Per direction and in total. I can identify the event running from server_a -&amp;gt; server_b -&amp;gt; server_a by a unique id. I calculate the duration for 3 possible event_types in my current query, but so far I can't tell if the calculated duration is valid from server_a to server_b or from server_b to server_a.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 02:55:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/double-fields-If-Statements/m-p/481752#M134999</guid>
      <dc:creator>mklhs</dc:creator>
      <dc:date>2020-09-30T02:55:57Z</dc:date>
    </item>
    <item>
      <title>Re: double fields If Statements</title>
      <link>https://community.splunk.com/t5/Splunk-Search/double-fields-If-Statements/m-p/481753#M135000</link>
      <description>&lt;P&gt;-HI &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/190455"&gt;@mklhs&lt;/a&gt;,&lt;BR /&gt;
could you share a sample?&lt;BR /&gt;
I try to interpret you need:&lt;BR /&gt;
you have a transation identified by an ID that's the same in all events on server_a and server_b,&lt;BR /&gt;
you want to calculate the time difference between these two servers (latency) and then the time difference from server_b to server_a,&lt;BR /&gt;
to calculate the first you have two events with the same ID=12345 like these&lt;BR /&gt;
2019-11-11 12:09:20 server_a 12345&lt;BR /&gt;
2019-11-11 12:09:30 server_b 12345&lt;BR /&gt;
so the difference is 10 seconds.&lt;BR /&gt;
Then you have:&lt;BR /&gt;
2019-11-11 12:09:40 server_b 12345&lt;BR /&gt;
2019-11-11 12:09:55 server_a 12345&lt;BR /&gt;
so the difference is 15 seconds.&lt;BR /&gt;
You want to display these latecies, is it correct?&lt;/P&gt;

&lt;P&gt;So you can run something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults | eval host="server_a", time="2019-11-11 12:10:10", ID="12345"
| append [ | makeresults | eval host="server_b", time="2019-11-11 12:10:20", ID="12345" ]
| append [ | makeresults | eval host="server_b", time="2019-11-11 12:10:30", ID="12345" ]
| append [ | makeresults | eval host="server_a", time="2019-11-11 12:10:45", ID="12345" ]
| stats first(eval(if(host="server_a",time,NULL))) AS first_a first(eval(if(host="server_b",time,NULL))) AS first_b last(eval(if(host="server_a",time,NULL))) AS last_a last(eval(if(host="server_b",time,NULL))) AS last_b BY ID
| eval latency_1=strptime(first_b,"%Y-%m-%d %H:%M:%S")-strptime(first_a,"%Y-%m-%d %H:%M:%S"), latency_2=strptime(last_a,"%Y-%m-%d %H:%M:%S")-strptime(last_b,"%Y-%m-%d %H:%M:%S")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Ciao.&lt;BR /&gt;
Giuseppe&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 02:55:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/double-fields-If-Statements/m-p/481753#M135000</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2020-09-30T02:55:03Z</dc:date>
    </item>
    <item>
      <title>Re: double fields If Statements</title>
      <link>https://community.splunk.com/t5/Splunk-Search/double-fields-If-Statements/m-p/481754#M135001</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval field_a = if(sender=="x", time_a, null()), field_b = if(sender=="x", null()), field_x = if(sender=="y", time_x, null(), field_y = if(sender=="y", time_y, null())
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 12 Nov 2019 00:32:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/double-fields-If-Statements/m-p/481754#M135001</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2019-11-12T00:32:37Z</dc:date>
    </item>
  </channel>
</rss>

