<?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 SPL Search  Query as code ?? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-format-SPL-Search-Query-as-code/m-p/498221#M138799</link>
    <description>&lt;P&gt;This probably should be a new question.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex "\|(?&amp;lt;Request&amp;gt;[^\|]+)"
| rex "ResponseCode=(?&amp;lt;StatusCode&amp;gt;\d+)\|ResponseTime=(?&amp;lt;ResponseTime&amp;gt;\d+)"
| stats count as Total,
 count(eval(match(StatusCode, "2\d\d"))) as "200 Response", count(eval(match(StatusCode, "5\d\d"))) as "500 Response",count(eval(match(StatusCode, "4\d\d"))) as "400 Response", avg(Time) as "Average response time"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 03 Feb 2020 16:38:11 GMT</pubDate>
    <dc:creator>richgalloway</dc:creator>
    <dc:date>2020-02-03T16:38:11Z</dc:date>
    <item>
      <title>How to format SPL Search  Query as code ??</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-format-SPL-Search-Query-as-code/m-p/498211#M138789</link>
      <description>&lt;P&gt;HI All&lt;/P&gt;

&lt;P&gt;i am creating a dashboard in SPLUNK .. i am trying capture the API counts and response time .&lt;BR /&gt;
here is a sample logger &lt;BR /&gt;
|METRICS|[SERVICE]=XYZ|POST|[URI]=/a/b/c|[HTTP-STATUS-CODE]=200|[RESPONSE_TIME]=209ms"&lt;/P&gt;

&lt;P&gt;i need it to displayed like &lt;/P&gt;

&lt;P&gt;request total 200 400 500 avg response maximum response&lt;BR /&gt;
a/b/c       2       1     1       0         209ms             249ms&lt;/P&gt;

&lt;P&gt;i tried with query &lt;BR /&gt;
source="abc" &lt;BR /&gt;
("[SERVICE]=XYZ" "[URI]=") &lt;BR /&gt;
| rex field=_raw " \[URI\]=(?&amp;lt;Request&amp;gt;.&lt;EM&gt;?)|" &lt;BR /&gt;
| rex field=_raw " \[RESPONSE_TIME\]=(?&amp;lt;Time&amp;gt;.&lt;/EM&gt;?)ms" &lt;BR /&gt;
| stats count as Total, &lt;BR /&gt;
count(eval(searchmatch("[HTTP-STATUS-CODE]=2*"))) as "2xx Successful Requests", count(eval(searchmatch("[HTTP-STATUS-CODE]=5*"))) as "5xx Technical Errors",count(eval(searchmatch("HTTP-STATUS-CODE]=4*"))) as "4xx Request Errors", avg(Time) as "Average Response (ms)", max(Time) as "Max Response (ms)" by Request &lt;/P&gt;

&lt;P&gt;Appreciate your Help on this ..&lt;BR /&gt;
Thanks in Advance !!&lt;/P&gt;</description>
      <pubDate>Wed, 30 Sep 2020 03:57:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-format-SPL-Search-Query-as-code/m-p/498211#M138789</guid>
      <dc:creator>venkat0896</dc:creator>
      <dc:date>2020-09-30T03:57:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to format SPL Search  Query as code ??</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-format-SPL-Search-Query-as-code/m-p/498212#M138790</link>
      <description>&lt;P&gt;Please provide some sample events, if you can.  Anonymize the data as necessary.&lt;BR /&gt;
What results to you get from your current query?&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jan 2020 13:25:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-format-SPL-Search-Query-as-code/m-p/498212#M138790</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2020-01-30T13:25:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to format SPL Search  Query as code ??</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-format-SPL-Search-Query-as-code/m-p/498213#M138791</link>
      <description>&lt;P&gt;Request Count Avg response time  200 response    400 response    500 response&lt;BR /&gt;
a/b/c         1           1068 ms                     1                              0                       0&lt;BR /&gt;
x/y/z          1           900 ms                       0                              1                        0&lt;BR /&gt;
q/w/e        1           1300 ms                     0                               0                         1&lt;/P&gt;

&lt;P&gt;i am trying to monitor the service with the number of counts, response returned and the response time&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jan 2020 14:08:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-format-SPL-Search-Query-as-code/m-p/498213#M138791</guid>
      <dc:creator>venkat0896</dc:creator>
      <dc:date>2020-01-30T14:08:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to format SPL Search  Query as code ??</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-format-SPL-Search-Query-as-code/m-p/498214#M138792</link>
      <description>&lt;P&gt;Those events are not in the format specified in your question.  The &lt;CODE&gt;rex&lt;/CODE&gt; commands will not match that data.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jan 2020 14:28:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-format-SPL-Search-Query-as-code/m-p/498214#M138792</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2020-01-30T14:28:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to format SPL Search  Query as code ??</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-format-SPL-Search-Query-as-code/m-p/498215#M138793</link>
      <description>&lt;P&gt;Yes.. can you help on this.. ?&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jan 2020 14:42:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-format-SPL-Search-Query-as-code/m-p/498215#M138793</guid>
      <dc:creator>venkat0896</dc:creator>
      <dc:date>2020-01-30T14:42:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to format SPL Search  Query as code ??</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-format-SPL-Search-Query-as-code/m-p/498216#M138794</link>
      <description>&lt;P&gt;you should use the code formatter to post SPL - from the looks of it, some of your formatting has been lost&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jan 2020 17:47:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-format-SPL-Search-Query-as-code/m-p/498216#M138794</guid>
      <dc:creator>nickhills</dc:creator>
      <dc:date>2020-01-30T17:47:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to format SPL Search  Query as code ??</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-format-SPL-Search-Query-as-code/m-p/498217#M138795</link>
      <description>&lt;P&gt;Hi @venkat0896  try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|makeresults |eval _raw="|METRICS|[SERVICE]=XYZ|POST|[URI]=/a/b/c|[HTTP-STATUS-CODE]=200|[RESPONSE_TIME]=209ms"

|rex field=_raw "\[SERVICE\]=(?P&amp;lt;service&amp;gt;[^\|]+)\|POST\|\[URI\]=(?P&amp;lt;request&amp;gt;[^\|]+)\|\[HTTP-STATUS-CODE\]=(?P&amp;lt;status&amp;gt;\d+)\|\[RESPONSE_TIME\]=(?P&amp;lt;responseTime&amp;gt;\d+)ms"
|eventstats count(eval(like(status,"2%"))) as "200s", count(eval(like(status,"5%"))) as "500s",count(eval(like(status,"4%"))) as "400s"
|stats count(200s) as 200s count(400s) as 400s count(500s) as 500s count as total avg(responseTime) as avgResponse max(responseTime) as maxResponse by request
|table request total 200s 400s 500s avgResponse maxResponse
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The first "makeresults" line above generates the test data - replace line 1 with your realy query.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jan 2020 18:07:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-format-SPL-Search-Query-as-code/m-p/498217#M138795</guid>
      <dc:creator>nickhills</dc:creator>
      <dc:date>2020-01-30T18:07:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to format SPL Search  Query as code ??</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-format-SPL-Search-Query-as-code/m-p/498218#M138796</link>
      <description>&lt;P&gt;I couldn't get the query to work with the sample event.  This query works, however.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="abc"
("[SERVICE]=XYZ" "[URI]=")
| rex field=_raw "\[URI]=(?&amp;lt;Request&amp;gt;[^\|]+)" 
| rex field=_raw "\[RESPONSE_TIME]=(?&amp;lt;Time&amp;gt;\d+)ms" 
| rex "\[HTTP-STATUS-CODE]=(?&amp;lt;StatusCode&amp;gt;\d+)"
| stats count as Total,
count(eval(match(StatusCode, "2\d\d"))) as "2xx Successful Requests", count(eval(match(StatusCode, "5\d\d"))) as "5xx Technical Errors",count(eval(match(StatusCode, "4\d\d"))) as "4xx Request Errors", avg(Time) as "Average Response (ms)", max(Time) as "Max Response (ms)" by Request
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Jan 2020 18:13:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-format-SPL-Search-Query-as-code/m-p/498218#M138796</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2020-01-30T18:13:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to format SPL Search  Query as code ??</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-format-SPL-Search-Query-as-code/m-p/498219#M138797</link>
      <description>&lt;P&gt;Thanks @richgalloway  .. it worked &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jan 2020 11:28:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-format-SPL-Search-Query-as-code/m-p/498219#M138797</guid>
      <dc:creator>venkat0896</dc:creator>
      <dc:date>2020-01-31T11:28:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to format SPL Search  Query as code ??</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-format-SPL-Search-Query-as-code/m-p/498220#M138798</link>
      <description>&lt;P&gt;Hi @richgalloway this is another Logging i see like &lt;BR /&gt;
POST|/private/v1/a/b/c/d|testing234||US|xyz|xyz|||xyz|xyz|||METRICS|--|ResponseCode=200|ResponseTime=7481","origin":"rep"&lt;/P&gt;

&lt;P&gt;in this Logging how to use the rex to get the table view &lt;/P&gt;

&lt;P&gt;for example &lt;BR /&gt;
Request                            Count Avg response time 200 response 400 response 500 response&lt;BR /&gt;
/private/v1/a/b/c/d           1              7481                      1                              0                     0&lt;/P&gt;

&lt;P&gt;Thanks in Advance !!&lt;/P&gt;</description>
      <pubDate>Mon, 03 Feb 2020 15:26:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-format-SPL-Search-Query-as-code/m-p/498220#M138798</guid>
      <dc:creator>venkat0896</dc:creator>
      <dc:date>2020-02-03T15:26:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to format SPL Search  Query as code ??</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-format-SPL-Search-Query-as-code/m-p/498221#M138799</link>
      <description>&lt;P&gt;This probably should be a new question.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| rex "\|(?&amp;lt;Request&amp;gt;[^\|]+)"
| rex "ResponseCode=(?&amp;lt;StatusCode&amp;gt;\d+)\|ResponseTime=(?&amp;lt;ResponseTime&amp;gt;\d+)"
| stats count as Total,
 count(eval(match(StatusCode, "2\d\d"))) as "200 Response", count(eval(match(StatusCode, "5\d\d"))) as "500 Response",count(eval(match(StatusCode, "4\d\d"))) as "400 Response", avg(Time) as "Average response time"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 03 Feb 2020 16:38:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-format-SPL-Search-Query-as-code/m-p/498221#M138799</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2020-02-03T16:38:11Z</dc:date>
    </item>
  </channel>
</rss>

