Ad Widget

Collapse

Preprocessing regex -> How to access group matches

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • muelli
    Member
    • Jun 2021
    • 68

    #1

    Preprocessing regex -> How to access group matches

    Hello forum,
    I am trying to use a regex in preprocessing.
    The text ist
    Code:
    Service Local Status Time in State Distributed Node Status leaderl running (pid 6889) 67d 1h 46m 47s leader: 11; waiting: 0; follower: 2; total: 3 epmd running (pid 6892) 67d 1h 46m 47s status: local-only etcd running (pid 6895) 67d 1h 46m 47s health: green; healthy nodes: 3/3 postgresql running (pid 7346) 67d 1h 44m 18s leader: 12; offline: 0; syncing: 0; synced: 2 elasticsearch running (pid 6962) 67d 1h 46m 47s state: green; nodes online: 3/3 System Local Status Distributed Node Status disks /var/log/chef-backend: OK; /var/opt/chef-backend: OK health: green; healthy nodes: 3/3
    and I want to find the two values for "leader", in this example "11" and "12".

    I was playing around with regex101.com and got to this regex:
    Code:
    leader: (.\d?)
    which gives me a Match 1/Group 1 and Match 2/Group 1.
    When using output option \1 in Zabbix, I can access the 11 in this example. However using \2 does not give me the 12. I guess I have to access the Match2/Group1 another way.
    But as a matter of fact, I am clueless on how this can be achieved, I am no regex king.

    Can someone give me a hint?
    Thanks!
  • ISiroshtan
    Senior Member
    • Nov 2019
    • 324

    #2
    Hi Mate.

    As far as I'm aware, Zabbix regexp engine is not using "global" (don't return after 1st match) option. So unlike in regex101 by default, Zabbix regex engine will not have 2nd match.

    So what you want to do instead, make a regexp that actually has 2 groups matching both values as part of single match. For example:
    Code:
    leader: (.\d?).*leader: (.\d?)
    This way you should be able to call \2 for 2nd leader.

    P.S. i'd also use (\d\d?) or (\d{1,2}) or even better (\d+) as match groups, unless . is really needed there because it can actually be not a digit but a letter too.

    Comment

    • muelli
      Member
      • Jun 2021
      • 68

      #3
      Thanks alot, that works!

      Comment

      Working...