Splunk Search

Help with regex to Extract HTTP reponse codes

vrmandadi
Builder

Hello all,

I have the below sample events

8 Aug 2017 14:45:54 [WARN ] http_srv: Total latency exceeded threshold: 0.180145 seconds (internal 0.180000 s) origin 0.140000 seconds MCHit 0 Status: **200** IP: 69.xxx.xxx.13:2062 URL: 

sample event 2

18 Aug 2017 15:06:30 [WARN ] http_cli: Origin latency exceeded threshold: 0.141100 seconds GET Status: **200**[OK] Bytes: 10081 Origin URL: http://linear-scope010.com/LIVE/1007/hls/ae/MSNBC_HD/900.m3u8 refReqId 13542238 reqWait 0 (id 3289754508)

sample event 3

Aug 2017 17:58:07 [WARN ] http_srv: DONE 4199750 0.023084 **404**[Not ...

sample event 4-this does not have the http code

22 Aug 2017 15:50:27 [WARN ] Content Generator: Discontinuity Sequence mismatch adding 982 at frag 1989008, adjusting previous (id 26007997)

I want a help with regex to extract the HTTP Response codes of events which have http_srv or http_cli in the events and save them in field called HTTP_Code .
Thanks in advance

0 Karma
1 Solution

somesoni2
SplunkTrust
SplunkTrust

Give this a try

your base search | rex "(http_srv|http_cli).+(?<HTTP_Code>\d{3})(\[|\sIP)"

View solution in original post

gcusello
SplunkTrust
SplunkTrust

Hi vrmandadi,
I'm not able to extract HTTP_Values for all samples using only one regex, but I can do it in two regexes:
to extract HTTP_Code from samples 1, you can use the following regex

(http_srv|http_cli).*Status:\s(?<HTTP_Code1>\d+)\s

instead for the Sample 2 and 3 use this regex

(http_srv|http_cli).*\s(?<HTTP_Code2>\d+)(\[OK|\[Not)

After you can merge results using coalesce function:

| eval HTTP_Code=coalesce(HTTP_Code1,HTTP_Code2)

Bye.
Giuseppe

0 Karma

somesoni2
SplunkTrust
SplunkTrust

Give this a try

your base search | rex "(http_srv|http_cli).+(?<HTTP_Code>\d{3})(\[|\sIP)"

vrmandadi
Builder

Hello @somesoni2

Thanks for the somesh it worked

0 Karma
Get Updates on the Splunk Community!

Routing logs with Splunk OTel Collector for Kubernetes

The Splunk Distribution of the OpenTelemetry (OTel) Collector is a product that provides a way to ingest ...

Welcome to the Splunk Community!

(view in My Videos) We're so glad you're here! The Splunk Community is place to connect, learn, give back, and ...

Tech Talk | Elevating Digital Service Excellence: The Synergy of Splunk RUM & APM

Elevating Digital Service Excellence: The Synergy of Real User Monitoring and Application Performance ...