Search code examples
regexhttp-headerszabbix

Remove HTTP headers from Prometheus in Zabbix


I have a server that has a Nginx VTS module installed on it, which outputs metrics in prometheus format.

When I try to actively check web.page.get via Zabbix I get the HTTP header and then the data in the format below:

HTTP/1.1 200 OK

Server: nginx

Date: Thu, 24 Sep 2020 09:16:20 GMT

Content-Type: text/plain

Content-Length: 33769

Connection: close

Vary: Accept-Encoding



# HELP nginx_vts_info Nginx info
# TYPE nginx_vts_info gauge
nginx_vts_info{hostname="example",version="1.18.0"} 1
# HELP nginx_vts_start_time_seconds Nginx start time
# TYPE nginx_vts_start_time_seconds gauge
nginx_vts_start_time_seconds 1600367492.145

# snip output...

I wrote a regular expression that removes the header but only outputs the first line:

# \n\s?\n(.*)

# HELP nginx_vts_info Nginx info

Regex

How do I rewrite the expression so that the header is removed and the rest of the data is available?


Solution

  • Please try below regex

    \n\s?\n([\s\S]*)
    

    in regex . wont check newlines unless specific flags set. hence in your example, only the first line was returned. so rewriting it to include newlines as well will help.