Ad Widget

Collapse

RegExp unexpected results

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ryan_frank
    Junior Member
    • Sep 2020
    • 9

    #1

    RegExp unexpected results

    Implementing vfs.file.regexp checks to look for data inside a file (capture for inventory and validation). Following the instructions from the manual I created the entry per the guidelines: vfs.file.regexp[file,regexp,<encoding>,<start line>,<end line>,<output>]
    Code:
    $ /usr/sbin/zabbix_agentd -t "vfs.file.regexp[/etc/opt/app/ENV,"^VERSION",,,,]"
    vfs.file.regexp[/etc/opt/app/ENV,^VERSION,,,,] [s|VERSION=7.1]

    I get the whole output, awesome right! nope... then I add the output option to juts get the 7.1 it does not work...
    Code:
    $ /usr/sbin/zabbix_agentd -t "vfs.file.regexp[/etc/opt/app/ENV,"^VERSION",,,,\0]"
    vfs.file.regexp[/etc/opt/app/ENV,^VERSION,,,,\0] [s|VERSION]

    \0 zero works! shows me the item matched.
    Code:
    $ /usr/sbin/zabbix_agentd -t "vfs.file.regexp[/etc/opt/app/ENV,"^VERSION",,,,\1]"
    vfs.file.regexp[/etc/opt/app/ENV,^VERSION,,,,\1] [s|]

    Nothing for \1-\9...

    If I make the regex any more complicated I am greeted with an "Invalid key format" even if just adding ranges of numbers/characters...
    Code:
    $ /usr/sbin/zabbix_agentd -t "vfs.file.regexp[/etc/opt/app/ENV,"VERSION=[0-9].[0-9]",,,,]"
    vfs.file.regexp[/etc/opt/app/ENV,VERSION[0-9],,,,] [m|ZBX_NOTSUPPORTED] [Invalid item key format.]

    Any ideas on what I am doing wrong? Why wont the output work and why does any expanded options in the regexp yield the invalid format, I have tested in regexp and it works outside of zabbix.
    Code:
    $ cat /etc/opt/app/ENV | grep '^VERSION=[0-9].[0-9]'
    VERSION=7.1
  • Hamardaban
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • May 2019
    • 2713

    #2
    You didn't specify a group in the regular expression. So \1 doesn't output anything. \0 matches the entire expression.
    vfs.file.regexp[/etc/opt/app/ENV,"(^VERSION=[0-9]\.[0-9])",,,,\1]

    Comment

    • ryan_frank
      Junior Member
      • Sep 2020
      • 9

      #3
      Originally posted by Hamardaban
      You didn't specify a group in the regular expression. So \1 doesn't output anything. \0 matches the entire expression.
      vfs.file.regexp[/etc/opt/app/ENV,"(^VERSION=[0-9]\.[0-9])",,,,\1]
      Well I will be... THANK YOU! setting the group gave me what I needed! "^VERSION=([0-9]\.[0-9].*)",,,,\1 worked like a charm...

      Thank you for helping clear up my stupidity... Still have a lot to learn about regexp...

      Comment

      Working...