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
Revered Legend

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
Revered Legend

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
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

[Puzzles] Solve, Learn, Repeat: Matching cron expressions

This puzzle (first published here) is based on matching timestamps to cron expressions.All the timestamps ...

Design, Compete, Win: Submit Your Best Splunk Dashboards for a .conf26 Pass

Hello Splunkers,  We’re excited to kick off a Splunk Dashboard contest! We know that dashboards are a primary ...

May 2026 Splunk Expert Sessions: Security & Observability

Level Up Your Operations: May 2026 Splunk Expert Sessions Whether you are refining your security posture or ...