Ad Widget

Collapse

v6.4 - How do we add a RegEx expression to a template sensor?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • GRIFFCOMM
    Junior Member
    • Jan 2021
    • 11

    #1

    v6.4 - How do we add a RegEx expression to a template sensor?

    Hi, am creating a template, there is a postprocessing tab, i can add a RegEx expression, however it was an "output" box, and it HAS to be filled, well.... what do i put in it, as the output will be the result of the RegEx expression !
  • cyber
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Dec 2006
    • 4806

    #2
    There are 2 regex related preprocessing options... one is for transforming/extracting data from value (Regular expression) and other is to validate data by comparing it to regex (matches regular expression). I'm assuming you are using the first one. So you can use match groups in output to construct another value, suitable for you to use...

    ttps://www.zabbix.com/documentation/current/en/manual/config/items/preprocessing
    Regular expression Match the value to the <pattern> regular expression and replace value with <output>. The regular expression supports extraction of maximum 10 captured groups with the \N sequence. Failure to match the input value will make the item unsupported.
    Parameters:
    pattern - regular expression
    output - output formatting template. An \N (where N=1…9) escape sequence is replaced with the Nth matched group. A \0 escape sequence is replaced with the matched text.
    Please refer to regular expressions section for some existing examples.
    If you mark the Custom on fail checkbox, it is possible to select custom error-handling options: either to discard the value, set a specified value, or set a specified error message. In case of a failed preprocessing step, the item will not become unsupported if the option to discard the value or set a specified value is selected.

    Comment

    • GRIFFCOMM
      Junior Member
      • Jan 2021
      • 11

      #3
      We cant seem to get any REGEX working, we found the 2 options to test (Template > Item > Preprocessing) Match regular expression.

      REG = [^_]*
      TEXT = gxp2170_00110055
      The above will match all characters before the "_" in all online testers, in Zabbix it fails to do anything, is this a bug?
      Last edited by GRIFFCOMM; 04-03-2024, 08:22.

      Comment

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

        #4
        It matches anything but _. https://regex101.com/r/qOCSNn/1

        But to be able to output a match group you have to first "group" things.
        What is that you a re regexing there.. ? you want to extract everything before "_" ? Use "(.*)_(\d+)" (without ""-s) and set output to /1
        Example with 2 match groups...

        Click image for larger version

Name:	image.png
Views:	192
Size:	5.5 KB
ID:	480157
        Click image for larger version

Name:	image.png
Views:	190
Size:	22.6 KB
ID:	480158

        Comment

        Working...