<?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 search for status code in log message in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-for-status-code-in-log-message/m-p/41188#M178926</link>
    <description>&lt;P&gt;I think you're confusing some things here: first of all, there are two main commands related to applying regular expressions to searches. One is &lt;CODE&gt;rex&lt;/CODE&gt;, which is used for creating a field extraction inline in your search. It does not filter anything, it just creates a field with a value if it finds a match based on the regex it's supplied with. The other one is &lt;CODE&gt;regex&lt;/CODE&gt; which filters search results based on a regex.&lt;/P&gt;

&lt;P&gt;So, if you want to FILTER the results using a regex, &lt;CODE&gt;regex&lt;/CODE&gt; is the command you should use. However, in your case, I don't see the point in using &lt;CODE&gt;regex&lt;/CODE&gt;, because all you are doing is filtering on some static text. My suggestion would be to just add this as a filter in your initial search command instead:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... AND "Complete with HTTP Response code : 404"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;...or, you could still extract the response code separately and then filter based on the value of that field:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex "Complete with HTTP Response code : (?&amp;lt;response_code&amp;gt;\d+)" | search response_code=404
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 21 Aug 2012 20:15:31 GMT</pubDate>
    <dc:creator>Ayn</dc:creator>
    <dc:date>2012-08-21T20:15:31Z</dc:date>
    <item>
      <title>How to search for status code in log message</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-for-status-code-in-log-message/m-p/41186#M178924</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I am trying to search for status code 404 in the below log message in my log file. The entries in my log file are as below&lt;BR /&gt;
    &lt;STRONG&gt;Complete with HTTP Response code : 404 in 100 ms.&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;
       &lt;STRONG&gt;Complete with HTTP Response code : 200 in 404 ms.&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;I am using regex as  rex "(?&amp;lt;404errrcode&amp;gt;;Complete with HTTP Response code : 404|Complete with HTTP Response code : 404)"&lt;BR /&gt;
The problem I am facing is, this regex is returning all the entries which ever is matching with 404. So I am getting the count even for status code 200 since 404 is present in that line.&lt;/P&gt;

&lt;P&gt;Can you please help me to come up with regex to give the count for only 404 which is present after (:) and it should not match with milli seconds (ms) value.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Aug 2012 19:49:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-for-status-code-in-log-message/m-p/41186#M178924</guid>
      <dc:creator>kodali21055</dc:creator>
      <dc:date>2012-08-21T19:49:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to search for status code in log message</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-for-status-code-in-log-message/m-p/41187#M178925</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;(?&amp;lt;404errorcode&amp;gt;Complete\swith\sHTTP\sResponse\scode\s:\s404\sin\s\d+\sms)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Aug 2012 20:06:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-for-status-code-in-log-message/m-p/41187#M178925</guid>
      <dc:creator>johandk</dc:creator>
      <dc:date>2012-08-21T20:06:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to search for status code in log message</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-for-status-code-in-log-message/m-p/41188#M178926</link>
      <description>&lt;P&gt;I think you're confusing some things here: first of all, there are two main commands related to applying regular expressions to searches. One is &lt;CODE&gt;rex&lt;/CODE&gt;, which is used for creating a field extraction inline in your search. It does not filter anything, it just creates a field with a value if it finds a match based on the regex it's supplied with. The other one is &lt;CODE&gt;regex&lt;/CODE&gt; which filters search results based on a regex.&lt;/P&gt;

&lt;P&gt;So, if you want to FILTER the results using a regex, &lt;CODE&gt;regex&lt;/CODE&gt; is the command you should use. However, in your case, I don't see the point in using &lt;CODE&gt;regex&lt;/CODE&gt;, because all you are doing is filtering on some static text. My suggestion would be to just add this as a filter in your initial search command instead:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... AND "Complete with HTTP Response code : 404"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;...or, you could still extract the response code separately and then filter based on the value of that field:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | rex "Complete with HTTP Response code : (?&amp;lt;response_code&amp;gt;\d+)" | search response_code=404
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Aug 2012 20:15:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-for-status-code-in-log-message/m-p/41188#M178926</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2012-08-21T20:15:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to search for status code in log message</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-for-status-code-in-log-message/m-p/41189#M178927</link>
      <description>&lt;P&gt;Hi, Thanks for the information.&lt;BR /&gt;
I am using the search as &lt;BR /&gt;
 rex "Complete with HTTP Response code : (?&lt;HTTP_RESPONSE_CODE&gt;\d+)" | chart count by http_response_code&lt;/HTTP_RESPONSE_CODE&gt;&lt;/P&gt;

&lt;P&gt;My requirement is to count the total no. of requests with status code 200.&lt;/P&gt;

&lt;P&gt;With this, I am getting the columns as 200, 204, 404, 500.&lt;BR /&gt;
Is it possible to rename the columns 200 to http_status_code 200&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 12:18:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-for-status-code-in-log-message/m-p/41189#M178927</guid>
      <dc:creator>kodali21055</dc:creator>
      <dc:date>2020-09-28T12:18:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to search for status code in log message</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-search-for-status-code-in-log-message/m-p/41190#M178928</link>
      <description>&lt;P&gt;I guess it could be done, but isn't it enough that it says "http_response_code" in the column header?&lt;/P&gt;

&lt;P&gt;If not, a general solution would be to use &lt;CODE&gt;eval&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;rex ... | eval http_response_code="http_response_code ".http_response_code | chart ...
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 Sep 2020 12:18:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-search-for-status-code-in-log-message/m-p/41190#M178928</guid>
      <dc:creator>Ayn</dc:creator>
      <dc:date>2020-09-28T12:18:32Z</dc:date>
    </item>
  </channel>
</rss>

