Ad Widget

Collapse

Testing preprocessing regexes with regex101.com

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • troffasky
    Senior Member
    • Jul 2008
    • 587

    #1

    Testing preprocessing regexes with regex101.com

    Server 7.0.22.
    I am trying to write a template to collect metrics from cloudflared.
    Master item fetches
    web.page.get[127.0.0.1,/metrics,20241]
    This outputs something like:
    Code:
    HTTP/1.1 200 OK
    
    Connection: close
    
    Transfer-Encoding: chunked
    
    Content-Type: text/plain; version=0.0.4; charset=utf-8; escaping=underscores
    
    Date: Mon, 16 Feb 2026 09:32:01 GMT
    
    
    
    # HELP build_info Build and version information
    # TYPE build_info gauge
    build_info{goversion="go1.24.11",revision="2026-01-20-11:14 UTC",type="",version="2026.1.1"} 1
    # HELP cloudflared_config_local_config_pushes Number of local configuration pushes to the edge
    # TYPE cloudflared_config_local_config_pushes counter
    cloudflared_config_local_config_pushes 0
    # HELP cloudflared_config_local_config_pushes_errors Number of errors occurred during local configuration pushes
    # TYPE cloudflared_config_local_config_pushes_errors counter
    cloudflared_config_local_config_pushes_errors 0
    ....many many more lines...
    This is my regex for collecting a metric:

    (?<=^cloudflared_config_local_config_pushes ).*

    You can see it matches the value 0:

    Click image for larger version  Name:	image.png Views:	0 Size:	192.1 KB ID:	511137

    Preprocessing on dependent item created as follows [just trust me that this is the regex as above in the box]:

    Click image for larger version  Name:	ksnip_20260216-103915.png Views:	0 Size:	21.3 KB ID:	511138

    But this does not work. Always returns:
    Preprocessing failed for: HTTP/1.1 200 OK..Connection: close..Transfer-Encoding: chunked..Content-Type: text/plain; version...
    1. Failed: cannot perform regular expression "(?<=^cloudflared_config_local_config_pushes ).*" match for value of type "none": pattern does not match​
    Why is the type 'none'? Obviously I want numeric but set it to Text to help debug. What is wrong with my regex?
    Last edited by troffasky; 16-02-2026, 12:45.
  • guntis_liepins
    Junior Member
    • Oct 2025
    • 29

    #2
    One note: zabbix uses PCRE/PCRE2 (depends on version) regular expressions without gm modifiers.
    This worker for me
    (cloudflared_config_local_config_pushes_errors)(\s +)(\d+)
    Capture group \3 (Output)
    I have no idea why lookbehind does not work

    Comment

    • troffasky
      Senior Member
      • Jul 2008
      • 587

      #3
      Thanks for looking at this, but that also doesn't work in Zabbix, with the same error [I have tried with and without ^]

      Preprocessing failed for: HTTP/1.1 200 OK..Connection: close..Transfer-Encoding: chunked..Content-Type: text/plain; version...
      1. Failed: cannot perform regular expression "(^cloudflared_config_local_config_pushes)(\s +)(\d+)" match for value of type "none": pattern does not match
      That regex doesn't work with regex101 FWIW:
      Click image for larger version

Name:	image.png
Views:	16
Size:	187.8 KB
ID:	511147

      Comment

      • guntis_liepins
        Junior Member
        • Oct 2025
        • 29

        #4
        Zabbix run regexp without gm modifier. Disable them in regex101.
        Click image for larger version  Name:	image.png Views:	0 Size:	31.1 KB ID:	511149

        Comment

        • troffasky
          Senior Member
          • Jul 2008
          • 587

          #5
          Guess what does work, though?
          Code:
          (^HTTP/1.1) (\d+)             \2
          Returns "200".
          And what does not work?
          Code:
          (^Connection:) (.+)          \2
          Same type "none" error.
          This does work though:
          Code:
          (Connection:) (.+)          \2
          Returns "Close".
          Anchoring with ^ is causing me a problem. ^ only works on Line 1.
          Last edited by troffasky; 16-02-2026, 14:55.

          Comment

          • troffasky
            Senior Member
            • Jul 2008
            • 587

            #6
            Do not need ^, I can trick it into working with \n
            Code:
            (\ncloudflared_config_local_config_pushes) (\d+)          \2
            returns 0 as expected.

            Comment

            • guntis_liepins
              Junior Member
              • Oct 2025
              • 29

              #7
              oh my regexp had extra space slipped in when paste

              Comment

              • troffasky
                Senior Member
                • Jul 2008
                • 587

                #8
                Documentation for regex preprocessing is poor.

                says "Please refer to regular expressions section for some existing examples"

                Has no examples of preprocessing regexes.
                Even just a link to some factory templates that use it would be a start!

                Comment

                • cyber
                  Senior Member
                  Zabbix Certified SpecialistZabbix Certified Professional
                  • Dec 2006
                  • 4841

                  #9
                  Looking at example data in first post... Isn't this prometheus output? You could just use prometheus related preprocessing for it instead of torturing yourself with regexes?

                  Comment

                  • troffasky
                    Senior Member
                    • Jul 2008
                    • 587

                    #10
                    I wouldn't know Prometheus if it bit me on the a***. So if you say it is then I guess it is Shame you did not reply on 16th
                    TBH it's not obvious to me that it's any easier than regexes but using the Prometheus LLD is probably where the real value is:

                    I manually created 4 instances of many metrics [because it looks like cloudflared always establishes 4 tunnels] which LLD would have been better for.

                    Comment

                    • cyber
                      Senior Member
                      Zabbix Certified SpecialistZabbix Certified Professional
                      • Dec 2006
                      • 4841

                      #11
                      And now you know..

                      Comment

                      Working...