<?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: Looping in Splunk... in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Looping-in-Splunk/m-p/570064#M198696</link>
    <description>&lt;P&gt;Sorry I missed the by _time out&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=anIndex sourcetype=aSource StringA earliest=-480m latest=-240m
| bin _time span=30m
| stats count as A by _time

| appendcols [search index=anIndex sourcetype=aSouce StringB earliest=-480m latest=-240m 
| bin _time span=30m
| stats count as B by _time]

| eval _time = relative_time(now(), "-240m@m")

| eval percentage = round(( A / B) * 100)

| fields + _time, percentage&lt;/LI-CODE&gt;</description>
    <pubDate>Thu, 07 Oct 2021 13:17:36 GMT</pubDate>
    <dc:creator>ITWhisperer</dc:creator>
    <dc:date>2021-10-07T13:17:36Z</dc:date>
    <item>
      <title>Looping in Splunk...</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Looping-in-Splunk/m-p/570042#M198685</link>
      <description>&lt;P class="yiv2082877121MsoNormal"&gt;&lt;SPAN&gt;Trying to figure out how to loop in Splunk.&amp;nbsp; I have the below query and my end result is to map/chart into a timechart by the percentage over _time.&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2082877121MsoNormal"&gt;&lt;SPAN&gt;index=anIndex sourcetype=aSource StringA earliest=-480m latest=-240m | stats count as A&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2082877121MsoNormal"&gt;&lt;SPAN&gt;| appendcols [search index=anIndex sourcetype=aSouce StringB earliest=-480m latest=-240m | stats count as B ]&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2082877121MsoNormal"&gt;&lt;SPAN&gt;| eval _time = relative_time(now(), "-240m@m")&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2082877121MsoNormal"&gt;&lt;SPAN&gt;| eval percentage = round(( A / B) * 100)&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2082877121MsoNormal"&gt;&lt;SPAN&gt;| fields + _time, percentage&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2082877121MsoNormal"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="yiv2082877121MsoNormal"&gt;&lt;SPAN&gt;Variables that need to change with each loop.&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2082877121MsoNormal"&gt;&lt;SPAN&gt;Lets assume I want to show percentage starting from 4 hour in the past to the current time by 30 minute increments.&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2082877121MsoNormal"&gt;&lt;SPAN&gt;1) Index: the earliest and latest need to increment by +30 minutes starting at (latest=-480, earliest = -240) till I get to 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2082877121MsoNormal"&gt;&lt;SPAN&gt;2) _time will need to be relative to when I start (beginning&amp;nbsp;@ time now(), -240) and be adjusted on each loop by + 30 mins till I get to 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2082877121MsoNormal"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="yiv2082877121MsoNormal"&gt;&lt;SPAN&gt;I have looked at many examples but do not understand how to apply it to my requirements...&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 12:04:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Looping-in-Splunk/m-p/570042#M198685</guid>
      <dc:creator>sjringo</dc:creator>
      <dc:date>2021-10-07T12:04:32Z</dc:date>
    </item>
    <item>
      <title>Re: Looping in Splunk...</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Looping-in-Splunk/m-p/570055#M198691</link>
      <description>&lt;P&gt;Does this work for you?&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=anIndex sourcetype=aSource StringA earliest=-480m latest=-240m
| bin _time span=30m
| stats count as A

| appendcols [search index=anIndex sourcetype=aSouce StringB earliest=-480m latest=-240m 
| bin _time span=30m
| stats count as B ]

| eval _time = relative_time(now(), "-240m@m")

| eval percentage = round(( A / B) * 100)

| fields + _time, percentage&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 07 Oct 2021 12:39:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Looping-in-Splunk/m-p/570055#M198691</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2021-10-07T12:39:22Z</dc:date>
    </item>
    <item>
      <title>Re: Looping in Splunk...</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Looping-in-Splunk/m-p/570057#M198692</link>
      <description>&lt;P&gt;It's again the &lt;A href="https://community.splunk.com/t5/Splunk-Search/Timechart-of-a-percentage-using-data-from-X-hours-ago/m-p/567890#M197912" target="_blank"&gt;https://community.splunk.com/t5/Splunk-Search/Timechart-of-a-percentage-using-data-from-X-hours-ago/m-p/567890#M197912&lt;/A&gt; topic? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I still think you're not telling us what you want to achieve but what you're trying to force splunk to do.&lt;/P&gt;&lt;P&gt;I understand that you want to calculate some stats based on how many times StringA appears in events with sourcetype=A and how many times StringB appears in events with sourcetype=B.&lt;/P&gt;&lt;P&gt;But what is the desired result. Tell us what is this supposed to represent.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 12:42:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Looping-in-Splunk/m-p/570057#M198692</guid>
      <dc:creator>PickleRick</dc:creator>
      <dc:date>2021-10-07T12:42:51Z</dc:date>
    </item>
    <item>
      <title>Re: Looping in Splunk...</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Looping-in-Splunk/m-p/570058#M198693</link>
      <description>&lt;P&gt;SPL is not a procedural language so we have to think a little differently to get the job done.&amp;nbsp; Fortunately, it can do looping for us.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=anIndex sourcetype=aSource (StringA OR StringB) earliest=-480m latest=-240m 
| bucket span=30m _time
| stats sum(eval(like(_raw, "%StringA%"))) as A, sum(eval(like(_raw, "%StringB%"))) as B by _time
| eval percentage = round(( A / B) * 100)
| fields _time, percentage&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 07 Oct 2021 12:43:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Looping-in-Splunk/m-p/570058#M198693</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2021-10-07T12:43:32Z</dc:date>
    </item>
    <item>
      <title>Re: Looping in Splunk...</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Looping-in-Splunk/m-p/570063#M198695</link>
      <description>&lt;P&gt;I added ( | bin _time span=30m) and the results were one percentage calculation.&amp;nbsp; What I am looking for is the percentage calculation over time .&amp;nbsp; I am looking for results like this, lets assume we run the query at 4 AM.&amp;nbsp; Starting&amp;nbsp;@ midnight then moving forward till we get till 4 AM.&lt;/P&gt;&lt;P&gt;_time&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Percentage&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;earliest&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;latest&lt;/P&gt;&lt;P&gt;2021-10-07 00:00:00&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; P1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;-480&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -240&lt;/P&gt;&lt;P&gt;2021-10-07 00:30:00&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; P2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;-450&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -210&lt;/P&gt;&lt;P&gt;2021-10-07 01:00:00&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; P3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;-420&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -180&lt;/P&gt;&lt;P&gt;2021-10-07 04:00:00&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; PX&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;-240&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -0&lt;/P&gt;&lt;P&gt;Then I would use the timechart on ( _time, Percentage) which would show me how the percentage moves up/down every 30 mins from midnight till 4 AM.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 13:10:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Looping-in-Splunk/m-p/570063#M198695</guid>
      <dc:creator>sjringo</dc:creator>
      <dc:date>2021-10-07T13:10:31Z</dc:date>
    </item>
    <item>
      <title>Re: Looping in Splunk...</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Looping-in-Splunk/m-p/570064#M198696</link>
      <description>&lt;P&gt;Sorry I missed the by _time out&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=anIndex sourcetype=aSource StringA earliest=-480m latest=-240m
| bin _time span=30m
| stats count as A by _time

| appendcols [search index=anIndex sourcetype=aSouce StringB earliest=-480m latest=-240m 
| bin _time span=30m
| stats count as B by _time]

| eval _time = relative_time(now(), "-240m@m")

| eval percentage = round(( A / B) * 100)

| fields + _time, percentage&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 07 Oct 2021 13:17:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Looping-in-Splunk/m-p/570064#M198696</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2021-10-07T13:17:36Z</dc:date>
    </item>
    <item>
      <title>Re: Looping in Splunk...</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Looping-in-Splunk/m-p/570065#M198697</link>
      <description>&lt;P class="yiv2033251992MsoNormal"&gt;&lt;SPAN&gt;Pseudo code, mixture of Java and SPL:&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2033251992MsoNormal"&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="yiv2033251992MsoNormal"&gt;&lt;SPAN&gt;int aSpan = 240;&amp;nbsp;&amp;nbsp; &amp;lt;- 4 hours&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2033251992MsoNormal"&gt;&lt;SPAN&gt;for (int anInt = -510; anInt &amp;gt; 0; anInt -30) {&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2033251992MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2033251992MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; index=anIndex sourcetype=aSourceType StringA earliest=-(anInt)m latest=-(anInt+aSpan)m | stats count as A&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2033251992MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; | appendcols [search index=anIndex sourcetype=aSourceType StringB -(anInt)m latest=-(anInt+aSpan)m | stats count as B ]&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2033251992MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; | eval _time = relative_time(now(), "-(anInt)m@m")&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2033251992MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; | eval percentage = round((A / B) * 100)&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2033251992MsoNormal"&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; | + fields _time, percentage&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P class="yiv2033251992MsoNormal"&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 13:27:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Looping-in-Splunk/m-p/570065#M198697</guid>
      <dc:creator>sjringo</dc:creator>
      <dc:date>2021-10-07T13:27:30Z</dc:date>
    </item>
    <item>
      <title>Re: Looping in Splunk...</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Looping-in-Splunk/m-p/570071#M198698</link>
      <description>&lt;P&gt;Much, Much better...&amp;nbsp; One thing is that _time is the same for each percentage result, which makes sense since the _time eval is:&lt;/P&gt;&lt;P&gt;| eval _time = relative_time(now(), "-240m@m")&lt;/P&gt;&lt;P&gt;How would I make it move in 30 minute intervals which is the bin span ?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 14:01:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Looping-in-Splunk/m-p/570071#M198698</guid>
      <dc:creator>sjringo</dc:creator>
      <dc:date>2021-10-07T14:01:00Z</dc:date>
    </item>
    <item>
      <title>Re: Looping in Splunk...</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Looping-in-Splunk/m-p/570072#M198699</link>
      <description>&lt;P&gt;Try removing that line&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 14:05:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Looping-in-Splunk/m-p/570072#M198699</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2021-10-07T14:05:41Z</dc:date>
    </item>
    <item>
      <title>Re: Looping in Splunk...</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Looping-in-Splunk/m-p/570074#M198701</link>
      <description>&lt;P&gt;That did the trick.&amp;nbsp; Once again thanks for your help!&lt;/P&gt;&lt;P&gt;My procedural brain was just not seeing the problem correctly...&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 14:14:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Looping-in-Splunk/m-p/570074#M198701</guid>
      <dc:creator>sjringo</dc:creator>
      <dc:date>2021-10-07T14:14:18Z</dc:date>
    </item>
    <item>
      <title>Re: Looping in Splunk...</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Looping-in-Splunk/m-p/570089#M198704</link>
      <description>&lt;P&gt;Yes, SPL is not procedural, although there are ways to do loops of a sort, but they wouldn't have helped in your case.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 16:50:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Looping-in-Splunk/m-p/570089#M198704</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2021-10-07T16:50:14Z</dc:date>
    </item>
  </channel>
</rss>

