Regular Expressions 101

Community Patterns

Nginx parse error log msg

0

Regular Expression
Python

r"
^(?P<timestamp>.{19})\ \[(?P<severity>\w{4,6})\] \ \d+\#\d+:\ (\*\d+\ )? (?P<err_msg> (?:\"\S+\"\sis\snot\s)? (?P<err_type>\w+)[\s(] (?:requests,\ excess:\ (?P<err_rate>\d+\.\d+) \ by\ zone\ \"(?P<err_zone>\S+)\" |.+?) ) (?: ,\ client:\ (?P<remote_addr>\d+\.\d+\.\d+\.\d+) ,\ server:\ (?P<server>[^,\a]+) (?:,\ request:\ \"(?P<method>[A-Z]{3,4}?) \ (?P<uri>\/\S*?)(?P<uri_query>\?\S+)? \ (?P<protocol>\S+)\" )? (?:,\ upstream:\ \"(?P<upstream>.+?)\")? (?:,\ host:\ \"(?P<req_host>\S+)\")? (?:,\ referrer:\ \"(?P<referrer>\S+)\")? |) $
"
xs

Description

Regex to parse nginx error logs, that can't be converted to json in nginx.

To use with fluentbit update group labels from "?P<label>" to "?<label>"

Submitted by diepes - 10 months ago