<?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 format the SPL as code? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-format-the-SPL-as-code/m-p/457706#M129265</link>
    <description>&lt;P&gt;Yes perfect @aohls&lt;/P&gt;</description>
    <pubDate>Wed, 21 Aug 2019 14:34:47 GMT</pubDate>
    <dc:creator>venkat0896</dc:creator>
    <dc:date>2019-08-21T14:34:47Z</dc:date>
    <item>
      <title>How to format the SPL as code?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-format-the-SPL-as-code/m-p/457700#M129259</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I am working on a dashboard. i am creating a table to monitor the count, average response time and maximum response time of the Api calls.&lt;/P&gt;

&lt;P&gt;I need some assistance with the rex field&lt;BR /&gt;
here is my logger:&lt;/P&gt;

&lt;P&gt;2019-08-20 10:37:02,690 INFO  &lt;A href="https://community.splunk.com/default%20task-248"&gt;package name&lt;/A&gt; [header-values] [METRICS] Response Time for POST /service url: 1658 ms, httpResponseCode=200&lt;/P&gt;

&lt;P&gt;here is my search query &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="/log/server.log"
/api1
OR /api2
OR /api3
"[METRICS] Response Time" 
| rex field=_raw " (?&amp;lt;Request&amp;gt;/.*):" 
| rex field=_raw "(?&amp;lt;Time&amp;gt;.*?)ms" 
| stats  count as Total,  
avg(Time) as "Average Response Time (ms)", 
max(Time) as "Maximum Response Time (ms)" by Request 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The table is generating but only the count is working. please assist with rex field to get the average response time&lt;BR /&gt;
&lt;STRONG&gt;Expected result&lt;/STRONG&gt; &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Request Count Average response time Maximum response time
/api1        1               ms                       ms
/api2         1              ms                        ms
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thanks in advance !!&lt;/P&gt;</description>
      <pubDate>Wed, 21 Aug 2019 08:12:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-format-the-SPL-as-code/m-p/457700#M129259</guid>
      <dc:creator>venkat0896</dc:creator>
      <dc:date>2019-08-21T08:12:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to format the SPL as code?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-format-the-SPL-as-code/m-p/457701#M129260</link>
      <description>&lt;P&gt;@ansusabu can you take a look on this ?&lt;/P&gt;</description>
      <pubDate>Wed, 21 Aug 2019 12:41:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-format-the-SPL-as-code/m-p/457701#M129260</guid>
      <dc:creator>venkat0896</dc:creator>
      <dc:date>2019-08-21T12:41:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to format the SPL as code?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-format-the-SPL-as-code/m-p/457702#M129261</link>
      <description>&lt;P&gt;Your event looks to have a space before ms, have you confirmed Time is getting values? &lt;BR /&gt;
Maybe&lt;CODE&gt;| rex field=_raw "(?.?) ms"&lt;/CODE&gt;  would work.&lt;BR /&gt;
Edit: not displaying right but &lt;CODE&gt;(?&amp;lt;Time&amp;gt;.?) ms&lt;/CODE&gt; &lt;/P&gt;</description>
      <pubDate>Wed, 21 Aug 2019 12:50:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-format-the-SPL-as-code/m-p/457702#M129261</guid>
      <dc:creator>aohls</dc:creator>
      <dc:date>2019-08-21T12:50:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to format the SPL as code?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-format-the-SPL-as-code/m-p/457703#M129262</link>
      <description>&lt;P&gt;Please edit your question to format the SPL as code.  Do that by highlighting the SPL and then clicking the &lt;CODE&gt;101010&lt;/CODE&gt; icon.  Then please correct the &lt;CODE&gt;rex&lt;/CODE&gt; statements.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Aug 2019 13:06:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-format-the-SPL-as-code/m-p/457703#M129262</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2019-08-21T13:06:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to format the SPL as code?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-format-the-SPL-as-code/m-p/457704#M129263</link>
      <description>&lt;P&gt;@aohls &lt;BR /&gt;
2019-08-20 10:37:02,690 INFO &lt;A href="https://community.splunk.com/default%20task-248"&gt;package name&lt;/A&gt; [header-values] [METRICS] Response Time for POST /service url: 1658 ms, httpResponseCode=200&lt;BR /&gt;
1658 is the value.&lt;BR /&gt;
i tried leaving a space before ms .. not working&lt;/P&gt;</description>
      <pubDate>Wed, 21 Aug 2019 13:08:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-format-the-SPL-as-code/m-p/457704#M129263</guid>
      <dc:creator>venkat0896</dc:creator>
      <dc:date>2019-08-21T13:08:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to format the SPL as code?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-format-the-SPL-as-code/m-p/457705#M129264</link>
      <description>&lt;P&gt;We have ms within our logs as well; the focus log section I used to test was "=2074 ms" &lt;BR /&gt;
&lt;CODE&gt;(?&amp;lt;Time&amp;gt;.?)ms&lt;/CODE&gt; This did not work for me, no results&lt;BR /&gt;
  &lt;CODE&gt;(?&amp;lt;Time&amp;gt;.?) ms&lt;/CODE&gt; Has a space and works ok but only gets the end number, 4 in my case.&lt;BR /&gt;
  &lt;CODE&gt;(?&amp;lt;Time&amp;gt;\d+) ms&lt;/CODE&gt; This worked the best as it is getting the full number.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Aug 2019 14:22:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-format-the-SPL-as-code/m-p/457705#M129264</guid>
      <dc:creator>aohls</dc:creator>
      <dc:date>2019-08-21T14:22:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to format the SPL as code?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-format-the-SPL-as-code/m-p/457706#M129265</link>
      <description>&lt;P&gt;Yes perfect @aohls&lt;/P&gt;</description>
      <pubDate>Wed, 21 Aug 2019 14:34:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-format-the-SPL-as-code/m-p/457706#M129265</guid>
      <dc:creator>venkat0896</dc:creator>
      <dc:date>2019-08-21T14:34:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to format the SPL as code?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-format-the-SPL-as-code/m-p/457707#M129266</link>
      <description>&lt;P&gt;I find it useful to check my regexes with a tool like Regex 101 before plugging it into rex commands.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | rex "(?&amp;lt;Request&amp;gt;\/.*):"
 | rex "(?&amp;lt;Time&amp;gt;\d+) ms"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;As  aohls mentioned, you need a space before the ms, but also you should be capturing more than a single character. I've specified one or more digits.&lt;BR /&gt;
Similarly, you need to specify more than a single character for the Request path.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Aug 2019 16:39:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-format-the-SPL-as-code/m-p/457707#M129266</guid>
      <dc:creator>cathalmcginley</dc:creator>
      <dc:date>2019-08-21T16:39:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to format the SPL as code?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-format-the-SPL-as-code/m-p/457708#M129267</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/183175"&gt;@venkat0896&lt;/a&gt; instead of having two rex on _raw you can write a single i.e. &lt;CODE&gt;| rex "(?&amp;lt;api_name&amp;gt;\/[^\:]+)\:\s(?&amp;lt;Time&amp;gt;[^\s]+)\sms,"&lt;/CODE&gt;&lt;BR /&gt;
Following is a run anywhere search based on your data.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| fields - _time
| eval _raw="2019-08-20 10:37:02,690 INFO [package name] (default task-248) [header-values] [METRICS] Response Time for POST /base/one/two: 1658 ms, httpResponseCode=200"
| rex "(?&amp;lt;api_name&amp;gt;\/[^\:]+)\:\s(?&amp;lt;Time&amp;gt;[^\s]+)\sms,"
| fields api_name Time _raw
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Sep 2020 01:50:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-format-the-SPL-as-code/m-p/457708#M129267</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2020-09-30T01:50:54Z</dc:date>
    </item>
  </channel>
</rss>

