Ad Widget

Collapse

Problem with vfs.file.regexp

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Glukas
    Junior Member
    • Nov 2021
    • 17

    #1

    Problem with vfs.file.regexp

    I am trying to use vfs.file.regexp on Zabbix 5.0 as per manual - 1 Zabbix agent [Zabbix Documentation 5.0]
    Code:
    Examples:
    ⇒ vfs.file.regexp[/etc/passwd,zabbix]
    ⇒ vfs.file.regexp[/path/to/some/file,"([0-9]+)$",,3,5,\1]
    ⇒ vfs.file.regexp[/etc/passwd,"^zabbix:.:([0-9]+)",,,,\1] → getting the ID of user [I]zabbix[/I]
    And first example works:
    Code:
    root@centos8:~# zabbix_get -s 127.0.0.1 -k vfs.file.regexp[/etc/passwd,zabbix]
    zabbix:x:984:980:Zabbix Monitoring System:/var/lib/zabbix:/sbin/nologin
    But third one does not:
    Code:
    root@centos8:~# zabbix_get -s 127.0.0.1 -k vfs.file.regexp[/etc/passwd,"^zabbix:.:([0-9]+)",,,,\1]
    ZBX_NOTSUPPORTED: Invalid item key format.
    What I am doing wrong?
    Last edited by Glukas; 08-11-2021, 11:27.
  • Glukas
    Junior Member
    • Nov 2021
    • 17

    #2
    I did copied all.
    But the regex in manual missing escapes:
    Manual:
    Code:
    vfs.file.regexp[/etc/passwd,"^zabbix:.:([0-9]+)",,,,\1]
    Your code:
    Code:
    vfs.file.regexp[/etc/passwd,\"^zabbix:.:\([0-9]+\)\",,,,\\1]
    Thanks!
    Looks like manual should be corrected with your code.

    Comment

    • Glukas
      Junior Member
      • Nov 2021
      • 17

      #3
      Although it still does it wrong...
      I am trying to use it for NFS3 stats on /proc/net/rpc/nfs:

      Code:
      cat /proc/net/rpc/nfs |grep proc3
      proc3 22 7 98347 0 1 13 5 1 0 0 2 0 0 0 0 0 0 0 15 24801 16 8 0
      Per manual, usage is:
      vfs.file.regexp[file,regexp,<encoding>,<start line>,<end line>,<output>]

      So the output should be the value of parameter number I want to get.
      Without parameters it is OK:
      Code:
      zabbix_get -s 127.0.0.1 -k vfs.file.regexp[/proc/net/rpc/nfs,^proc3,,,,]
      proc3 22 7 98358 0 1 13 5 1 0 0 2 0 0 0 0 0 0 0 15 24801 16 8 0
      With parameter 0 it is OK too:
      Code:
      root@centos8:~# zabbix_get -s 127.0.0.1 -k vfs.file.regexp[/proc/net/rpc/nfs,\"^proc3\",,,,\\0]
      proc3
      But any other than 0 number returns nothing:
      Code:
      root@centos8:~# zabbix_get -s 127.0.0.1 -k vfs.file.regexp[/proc/net/rpc/nfs,\"^proc3\",,,,\\5]
       
      root@centos8:~# zabbix_get -s 127.0.0.1 -k vfs.file.regexp[/proc/net/rpc/nfs,\"^proc3\",,,,\\7]
       
      root@centos8:~#
      Last edited by Glukas; 08-11-2021, 15:04.

      Comment

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

        #4
        First.. no manual is not missing anything. It describes exactly how things are supposed to be written in Zabbix. if you are using command line tools, you need to adapt to command line "quirks", like what exactly ""-s mean for bash and how you can avoid some character to be interpreted by shell etc... That's why you need escaping.

        Second... No... you are not capturing any group in your regex, so only thing that works for you is \0, which returns whole line. if you want to return 5th or 7th field, you actually need to create define your regex accordingly ...

        "^proc3 (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) (\d+)" for full capturing... but you can probably replace end of it also with .* from the point where you do not need anything captured...

        Comment

        • Glukas
          Junior Member
          • Nov 2021
          • 17

          #5
          Got it.
          Thanks!

          Comment

          Working...