<?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 statement with SUM and passing data to a timechart. in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Using-IF-statement-with-SUM-and-passing-data-to-a-timechart/m-p/409620#M118172</link>
    <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/187291"&gt;@eliwasserman92&lt;/a&gt; try the following query&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Step 1&lt;/STRONG&gt;: Create sample events 5 each for &lt;CODE&gt;src_interface="tunnel.44"&lt;/CODE&gt; and &lt;CODE&gt;dest_interface="tunnel.44"&lt;/CODE&gt; with random &lt;CODE&gt;bytes_in, bytes_out&lt;/CODE&gt; as per your question. PS for dummy data time difference is &lt;CODE&gt;5 min&lt;/CODE&gt; using &lt;CODE&gt;duration=300&lt;/CODE&gt; sec. So run the search for &lt;CODE&gt;Last 30 Minute&lt;/CODE&gt; using relative time preset.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count=5 
| eval duration=300 
| accum duration 
| eval _time=_time-duration 
| eval bytes_in=random(),bytes_out=random() 
| eval bytes_in=substr(bytes_in,1,4), bytes_out=substr(bytes_out,1,4) 
| eval src_interface="tunnel.44" 
| append 
    [| makeresults count=5 
    | eval duration=300 
    | accum duration 
    | eval _time=_time-duration 
    | eval bytes_in=random(),bytes_out=random() 
    | eval bytes_in=substr(bytes_in,1,4), bytes_out=substr(bytes_out,1,4) 
    | eval dest_interface="tunnel.44"] 
| fields - duration
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Step 2:&lt;/STRONG&gt;  Create actual &lt;CODE&gt;Inbound traffic bytes&lt;/CODE&gt; and &lt;CODE&gt;Outbound traffic bytes&lt;/CODE&gt; from &lt;CODE&gt;bytes_in&lt;/CODE&gt; and &lt;CODE&gt;bytes_out&lt;/CODE&gt; using &lt;CODE&gt;src_interface&lt;/CODE&gt; and &lt;CODE&gt;dest_interface&lt;/CODE&gt; as per the use case. Original bytes_in and bytes_out in this step are retained to compare and confirm that &lt;CODE&gt;bytes_in&lt;/CODE&gt; becomes &lt;CODE&gt;outbound traffic bytes&lt;/CODE&gt; if &lt;CODE&gt;dest_interface&lt;/CODE&gt; is &lt;CODE&gt;tunnel.44&lt;/CODE&gt; and vice versa for &lt;CODE&gt;bytes_out&lt;/CODE&gt; which becomes &lt;CODE&gt;inbound traffic bytes&lt;/CODE&gt; if the &lt;CODE&gt;dest_interface&lt;/CODE&gt; is &lt;CODE&gt;tunnel.44&lt;/CODE&gt;. For &lt;CODE&gt;src_interface="tunnel.44"&lt;/CODE&gt;, &lt;CODE&gt;bytes_in&lt;/CODE&gt; remains as &lt;CODE&gt;Inbound traffic bytes&lt;/CODE&gt; and &lt;CODE&gt;bytes_out&lt;/CODE&gt; remains as &lt;CODE&gt;Outbound traffic bytes&lt;/CODE&gt;. All as described in the use case.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval inbound_traffic_bytes=case(src_interface=="tunnel.44",bytes_in,
    dest_interface=="tunnel.44",bytes_out), outbound_traffic_bytes=case(src_interface=="tunnel.44",bytes_out,
    dest_interface=="tunnel.44",bytes_in)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Step 3&lt;/STRONG&gt; Apply timechart on new fields &lt;CODE&gt;inbound_traffice_bytes&lt;/CODE&gt; and &lt;CODE&gt;outbound_traffic_bytes&lt;/CODE&gt;. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| timechart span=5m sum(inbound_traffic_bytes) as "Inbound" sum(outbound_traffic_bytes) as "Outbound"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Following is the Run anywhere dashboard code for you to try out and confirm.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;dashboard&amp;gt;
  &amp;lt;label&amp;gt;Inbound Outbound Traffic Timechart&amp;lt;/label&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;chart&amp;gt;
        &amp;lt;search&amp;gt;
          &amp;lt;query&amp;gt;| makeresults count=5 
| eval duration=300 
| accum duration 
| eval _time=_time-duration 
| eval bytes_in=random(),bytes_out=random() 
| eval bytes_in=substr(bytes_in,1,4), bytes_out=substr(bytes_out,1,4) 
| eval src_interface="tunnel.44" 
| append 
    [| makeresults count=5 
    | eval duration=300 
    | accum duration 
    | eval _time=_time-duration 
    | eval bytes_in=random(),bytes_out=random() 
    | eval bytes_in=substr(bytes_in,1,4), bytes_out=substr(bytes_out,1,4) 
    | eval dest_interface="tunnel.44"] 
| fields - duration

| eval inbound_traffic_bytes=case(src_interface=="tunnel.44",bytes_in,
    dest_interface=="tunnel.44",bytes_out), outbound_traffic_bytes=case(src_interface=="tunnel.44",bytes_out,
    dest_interface=="tunnel.44",bytes_in)
| timechart span=5m sum(inbound_traffic_bytes) as "Inbound" sum(outbound_traffic_bytes) as "Outbound"&amp;lt;/query&amp;gt;
          &amp;lt;earliest&amp;gt;-30m@m&amp;lt;/earliest&amp;gt;
          &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
          &amp;lt;sampleRatio&amp;gt;1&amp;lt;/sampleRatio&amp;gt;
        &amp;lt;/search&amp;gt;
      &amp;lt;/chart&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
&amp;lt;/dashboard&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 30 Sep 2020 00:48:46 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2020-09-30T00:48:46Z</dc:date>
    <item>
      <title>Using IF statement with SUM and passing data to a timechart.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-IF-statement-with-SUM-and-passing-data-to-a-timechart/m-p/409619#M118171</link>
      <description>&lt;P&gt;I am interested in quantifying  &lt;STRONG&gt;inbound&lt;/STRONG&gt;/&lt;STRONG&gt;outbound&lt;/STRONG&gt; traffic traversing an IPsec tunnel on a Palo Alto firewall and visualizing the results with a Splunk timechart. &lt;/P&gt;

&lt;P&gt;The firewall creates a single syslog event per session, with a typical event containing the following fields:&lt;BR /&gt;
&lt;CODE&gt;src_interface=tunnel.44&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;dest_interface=ethernet1/1&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;bytes=3299&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;bytes_in=456&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;bytes_out=2843&lt;/CODE&gt; &lt;/P&gt;

&lt;P&gt;In order to filter the traffic to this particular tunnel in &lt;STRONG&gt;both directions&lt;/STRONG&gt;, we can create a search that includes  &lt;CODE&gt;src_interface=tunnel.44 OR dest_interface=tunnel.44&lt;/CODE&gt;. Additionally, the &lt;CODE&gt;bytes&lt;/CODE&gt; field represents the total traffic passed during the session, so we are ultimately going to focus on &lt;CODE&gt;bytes_in&lt;/CODE&gt;and &lt;CODE&gt;bytes_out&lt;/CODE&gt; fields.&lt;/P&gt;

&lt;P&gt;The splunk search would start like this:&lt;BR /&gt;
&lt;CODE&gt;index=sampleindex dvc_name=samplefirewall dest_interface=tunnel.44 OR src_interface=tunnel.44&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;The challenge will be in quantifying the data.  To demonstrate the traffic for &lt;CODE&gt;tunnel.44&lt;/CODE&gt; we need to add the following logic:&lt;BR /&gt;
&lt;CODE&gt;bytes_in IF src_interface=tunnel.44&lt;/CODE&gt; = inbound&lt;BR /&gt;
&lt;CODE&gt;bytes_out IF dest_interface=tunnel.44&lt;/CODE&gt; = inbound&lt;BR /&gt;
&lt;CODE&gt;bytes_in IF dest_interface=tunnel.44&lt;/CODE&gt; = outbound&lt;BR /&gt;
&lt;CODE&gt;bytes_out IF src_interface=tunnel.44&lt;/CODE&gt; = outbound&lt;/P&gt;

&lt;P&gt;I am looking to:&lt;BR /&gt;
1. Use a statement to collect the &lt;CODE&gt;bytes_in&lt;/CODE&gt; and &lt;CODE&gt;bytes_out&lt;/CODE&gt; and aggregate them into &lt;STRONG&gt;inbound&lt;/STRONG&gt; and &lt;STRONG&gt;outbound&lt;/STRONG&gt; &lt;BR /&gt;
2. Chart the inbound/outbound on a timechart visualization.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jun 2019 14:38:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-IF-statement-with-SUM-and-passing-data-to-a-timechart/m-p/409619#M118171</guid>
      <dc:creator>eliwasserman92</dc:creator>
      <dc:date>2019-06-06T14:38:45Z</dc:date>
    </item>
    <item>
      <title>Re: Using IF statement with SUM and passing data to a timechart.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-IF-statement-with-SUM-and-passing-data-to-a-timechart/m-p/409620#M118172</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/187291"&gt;@eliwasserman92&lt;/a&gt; try the following query&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Step 1&lt;/STRONG&gt;: Create sample events 5 each for &lt;CODE&gt;src_interface="tunnel.44"&lt;/CODE&gt; and &lt;CODE&gt;dest_interface="tunnel.44"&lt;/CODE&gt; with random &lt;CODE&gt;bytes_in, bytes_out&lt;/CODE&gt; as per your question. PS for dummy data time difference is &lt;CODE&gt;5 min&lt;/CODE&gt; using &lt;CODE&gt;duration=300&lt;/CODE&gt; sec. So run the search for &lt;CODE&gt;Last 30 Minute&lt;/CODE&gt; using relative time preset.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count=5 
| eval duration=300 
| accum duration 
| eval _time=_time-duration 
| eval bytes_in=random(),bytes_out=random() 
| eval bytes_in=substr(bytes_in,1,4), bytes_out=substr(bytes_out,1,4) 
| eval src_interface="tunnel.44" 
| append 
    [| makeresults count=5 
    | eval duration=300 
    | accum duration 
    | eval _time=_time-duration 
    | eval bytes_in=random(),bytes_out=random() 
    | eval bytes_in=substr(bytes_in,1,4), bytes_out=substr(bytes_out,1,4) 
    | eval dest_interface="tunnel.44"] 
| fields - duration
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Step 2:&lt;/STRONG&gt;  Create actual &lt;CODE&gt;Inbound traffic bytes&lt;/CODE&gt; and &lt;CODE&gt;Outbound traffic bytes&lt;/CODE&gt; from &lt;CODE&gt;bytes_in&lt;/CODE&gt; and &lt;CODE&gt;bytes_out&lt;/CODE&gt; using &lt;CODE&gt;src_interface&lt;/CODE&gt; and &lt;CODE&gt;dest_interface&lt;/CODE&gt; as per the use case. Original bytes_in and bytes_out in this step are retained to compare and confirm that &lt;CODE&gt;bytes_in&lt;/CODE&gt; becomes &lt;CODE&gt;outbound traffic bytes&lt;/CODE&gt; if &lt;CODE&gt;dest_interface&lt;/CODE&gt; is &lt;CODE&gt;tunnel.44&lt;/CODE&gt; and vice versa for &lt;CODE&gt;bytes_out&lt;/CODE&gt; which becomes &lt;CODE&gt;inbound traffic bytes&lt;/CODE&gt; if the &lt;CODE&gt;dest_interface&lt;/CODE&gt; is &lt;CODE&gt;tunnel.44&lt;/CODE&gt;. For &lt;CODE&gt;src_interface="tunnel.44"&lt;/CODE&gt;, &lt;CODE&gt;bytes_in&lt;/CODE&gt; remains as &lt;CODE&gt;Inbound traffic bytes&lt;/CODE&gt; and &lt;CODE&gt;bytes_out&lt;/CODE&gt; remains as &lt;CODE&gt;Outbound traffic bytes&lt;/CODE&gt;. All as described in the use case.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval inbound_traffic_bytes=case(src_interface=="tunnel.44",bytes_in,
    dest_interface=="tunnel.44",bytes_out), outbound_traffic_bytes=case(src_interface=="tunnel.44",bytes_out,
    dest_interface=="tunnel.44",bytes_in)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Step 3&lt;/STRONG&gt; Apply timechart on new fields &lt;CODE&gt;inbound_traffice_bytes&lt;/CODE&gt; and &lt;CODE&gt;outbound_traffic_bytes&lt;/CODE&gt;. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| timechart span=5m sum(inbound_traffic_bytes) as "Inbound" sum(outbound_traffic_bytes) as "Outbound"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Following is the Run anywhere dashboard code for you to try out and confirm.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;dashboard&amp;gt;
  &amp;lt;label&amp;gt;Inbound Outbound Traffic Timechart&amp;lt;/label&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;chart&amp;gt;
        &amp;lt;search&amp;gt;
          &amp;lt;query&amp;gt;| makeresults count=5 
| eval duration=300 
| accum duration 
| eval _time=_time-duration 
| eval bytes_in=random(),bytes_out=random() 
| eval bytes_in=substr(bytes_in,1,4), bytes_out=substr(bytes_out,1,4) 
| eval src_interface="tunnel.44" 
| append 
    [| makeresults count=5 
    | eval duration=300 
    | accum duration 
    | eval _time=_time-duration 
    | eval bytes_in=random(),bytes_out=random() 
    | eval bytes_in=substr(bytes_in,1,4), bytes_out=substr(bytes_out,1,4) 
    | eval dest_interface="tunnel.44"] 
| fields - duration

| eval inbound_traffic_bytes=case(src_interface=="tunnel.44",bytes_in,
    dest_interface=="tunnel.44",bytes_out), outbound_traffic_bytes=case(src_interface=="tunnel.44",bytes_out,
    dest_interface=="tunnel.44",bytes_in)
| timechart span=5m sum(inbound_traffic_bytes) as "Inbound" sum(outbound_traffic_bytes) as "Outbound"&amp;lt;/query&amp;gt;
          &amp;lt;earliest&amp;gt;-30m@m&amp;lt;/earliest&amp;gt;
          &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
          &amp;lt;sampleRatio&amp;gt;1&amp;lt;/sampleRatio&amp;gt;
        &amp;lt;/search&amp;gt;
      &amp;lt;/chart&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
&amp;lt;/dashboard&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Sep 2020 00:48:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-IF-statement-with-SUM-and-passing-data-to-a-timechart/m-p/409620#M118172</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2020-09-30T00:48:46Z</dc:date>
    </item>
    <item>
      <title>Re: Using IF statement with SUM and passing data to a timechart.</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-IF-statement-with-SUM-and-passing-data-to-a-timechart/m-p/409621#M118173</link>
      <description>&lt;P&gt;Thank you @niketnilay for the detailed response.  &lt;/P&gt;

&lt;P&gt;My final successful search was as follows:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;`index=sampleindex dvc_name=sampledevice dest_interface=tunnel.44 OR src_interface=tunnel.44
| eval inbound_traffic_bytes=case(src_interface=="tunnel.44",bytes_in,
     dest_interface=="tunnel.44",bytes_out), outbound_traffic_bytes=case(src_interface=="tunnel.44",bytes_out,
     dest_interface=="tunnel.44",bytes_in)
| eval inbound_traffic_megabytes=inbound_traffic_bytes/1024/1024
| eval outbound_traffic_megabytes=outbound_traffic_bytes/1024/1024
| timechart sum(inbound_traffic_megabytes) as "Inbound" sum(outbound_traffic_megabytes) as "Outbound" `
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Jun 2019 19:12:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-IF-statement-with-SUM-and-passing-data-to-a-timechart/m-p/409621#M118173</guid>
      <dc:creator>eliwasserman92</dc:creator>
      <dc:date>2019-06-06T19:12:04Z</dc:date>
    </item>
  </channel>
</rss>

