<?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 make loop in splunk query in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/how-to-make-loop-in-splunk-query/m-p/576443#M47230</link>
    <description>&lt;P&gt;Splunk doesn't have loops like programming languages.&amp;nbsp; The &lt;FONT face="courier new,courier"&gt;foreach&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;map&lt;/FONT&gt; commands let you iterate over fields or events, respectively, but those don't do what you describe.&lt;/P&gt;&lt;P&gt;The closest you can get is the &lt;FONT face="courier new,courier"&gt;streamstats&lt;/FONT&gt; command with the &lt;FONT face="courier new,courier"&gt;range&lt;/FONT&gt; function.&amp;nbsp; This command computes the difference between the current value of the 'time' field and the previous one.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| streamstats window=1 range(time) as Time&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 26 Nov 2021 15:51:33 GMT</pubDate>
    <dc:creator>richgalloway</dc:creator>
    <dc:date>2021-11-26T15:51:33Z</dc:date>
    <item>
      <title>how to make loop in splunk query</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/how-to-make-loop-in-splunk-query/m-p/576439#M47229</link>
      <description>&lt;P&gt;I have a query that returns multiple times and I need to step through this result doing a subtraction count between one and the other.&lt;/P&gt;&lt;P&gt;Example:&lt;BR /&gt;Time = time[0] - time[1]&lt;BR /&gt;Time = time[1] - time[2]&lt;/P&gt;&lt;P&gt;etc ....&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;My search looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;lt;my search&amp;gt;&lt;BR /&gt;| eval Time=_time&lt;BR /&gt;| stats values(Time) as Time by UserName| eval reconnection=if(UserName == UserName, tonumber(mvindex(Time,1))-tonumber(mvindex(Time,0)), "falha")&lt;BR /&gt;| where reconnection&amp;gt;0 AND reconnection&amp;lt;600&lt;BR /&gt;| eval reconnection=tostring(reconnection, "duration")&lt;/P&gt;</description>
      <pubDate>Fri, 26 Nov 2021 15:17:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/how-to-make-loop-in-splunk-query/m-p/576439#M47229</guid>
      <dc:creator>carinahOliveira</dc:creator>
      <dc:date>2021-11-26T15:17:27Z</dc:date>
    </item>
    <item>
      <title>Re: how to make loop in splunk query</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/how-to-make-loop-in-splunk-query/m-p/576443#M47230</link>
      <description>&lt;P&gt;Splunk doesn't have loops like programming languages.&amp;nbsp; The &lt;FONT face="courier new,courier"&gt;foreach&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;map&lt;/FONT&gt; commands let you iterate over fields or events, respectively, but those don't do what you describe.&lt;/P&gt;&lt;P&gt;The closest you can get is the &lt;FONT face="courier new,courier"&gt;streamstats&lt;/FONT&gt; command with the &lt;FONT face="courier new,courier"&gt;range&lt;/FONT&gt; function.&amp;nbsp; This command computes the difference between the current value of the 'time' field and the previous one.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| streamstats window=1 range(time) as Time&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Nov 2021 15:51:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/how-to-make-loop-in-splunk-query/m-p/576443#M47230</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2021-11-26T15:51:33Z</dc:date>
    </item>
    <item>
      <title>Re: how to make loop in splunk query</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/how-to-make-loop-in-splunk-query/m-p/576449#M47231</link>
      <description>&lt;P&gt;I managed to solve it and I'll leave the solution here in case anyone needs it.&lt;/P&gt;&lt;P&gt;As mentioned earlier, there is no way to create a loop, but we can create a range and use it to iterate&lt;/P&gt;&lt;P&gt;Here's how I did it:&lt;/P&gt;&lt;P&gt;---------------------&lt;BR /&gt;| eval i = mvrange(0,10)&lt;BR /&gt;| mvexpand i&lt;/P&gt;&lt;P&gt;----------------------&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;lt;my search&amp;gt;&lt;/P&gt;&lt;P&gt;| eval Time=_time&lt;BR /&gt;| stats values(Time) as Time by UserName&lt;/P&gt;&lt;P&gt;| eval i = mvrange(0,10)&lt;BR /&gt;| mvexpand i&lt;/P&gt;&lt;P&gt;| eval reconnection=if(UserName==UserName, tonumber(mvindex(Time,i+1))-tonumber(mvindex(Time,i)), "falha")&lt;BR /&gt;| where reconnection&amp;gt;0 AND reconnection&amp;lt;600&lt;/P&gt;&lt;P&gt;| eval reconnection=tostring(reconnection, "duration")&lt;/P&gt;</description>
      <pubDate>Fri, 26 Nov 2021 18:31:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/how-to-make-loop-in-splunk-query/m-p/576449#M47231</guid>
      <dc:creator>carinahOliveira</dc:creator>
      <dc:date>2021-11-26T18:31:59Z</dc:date>
    </item>
  </channel>
</rss>

