Ad Widget

Collapse

Multiline Regular Expressions - Multiple values

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • markfree
    Senior Member
    • Apr 2019
    • 868

    #1

    Multiline Regular Expressions - Multiple values

    I was trying to collect some data from a file using regular expressions and for that I was looking for an optimal solution.

    My file is something like the example below.
    Code:
    (...)
    (someParms=on)
    
    ## [some comments] ##
    parm1=410962
    parm2=205481
    parm3=138871
    parm4=670
    parm5=6
    parm6="Oct 25 16:27"
    parm7="Oct 25 16:34"
    parm8=on
    parm9='Oct 25 16:34:53 dnsmasq'
    
    ## [some comments] ##
    (otherParms=on)
    (...)
    So, I wish to collect the values from 6 parameters. Parm2 to 5 and parm7 to 8.

    Using regular expressions I can create individual items and collect each parameter individually using key "vfs.file.regexp".
    For example:
    Code:
    vfs.file.regexp[/path/to/file/fileName,"parm2=(.*)",,,,\1]
    This way, It sure gives me the expected value, but, thinking about it, doing this way would create at least 6 readings for the same file.
    So, maybe there's a better way to collect this parameters with a single file reading.

    I thought of using "vfs.file.contents" key and preprocessing it with something like this:
    Code:
    parm2=(.*)|parm3=(.*)|parm4=(.*)|parm5=(.*)|parm7= (.*)|parm8=(.*)\m
    But that doesn't really add up results, and Zabbix doesn't accept multiline flag.

    Anyone knows a good way to collect just those target lines with a single regular expression?
    Last edited by markfree; 25-10-2021, 23:40.
  • markfree
    Senior Member
    • Apr 2019
    • 868

    #2
    Using dependent items seems a good choice indeed. That would stop the multiple reading for the same file.
    The way I see, the master item would capture the file contents completely so the dependent items can filter the data.

    This way, a good filter for the master item seems a good option as it would avoid wasted data saved in the DB.
    The master item could read the file and only save in the DB what is actually needed. That seems an optimal solution for me.

    As mentioned above, I thought of using regular expressions, but could not find one to filter all needed parameters.
    So, is there a way to preprocess or filter the master item to reduce data saved in the DB or something like that?

    Comment

    • markfree
      Senior Member
      • Apr 2019
      • 868

      #3
      Your suggestion not to keep history does the trick. I totally forgot that.
      This way, master item reads the file and only dependent items will keep the target data.
      That was a cyber-suggestion.
      Thanks a lot.

      Comment

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

        #4
        Look up "dependent items", please.

        You can pull data with one item and distribute values from different lines to different dependent items. Each time your main item gets and update, all dependent...

        Comment

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

          #5
          You do not need to preprocess your "main" data". Just collect its value...
          You just need to create a "dependent item" for each value you want to extract. Master item points to your "main" data item. There' s even "wizard" column in item list...
          Choose correct preprocessing, in this case regex should be fine ...set correct regex (parm1=(\d+) ) and return value (\1]. Items data type must be correct for this return value..., I guess unsigned int ...
          Repeat for each item you need to extract...
          If you get things working you can set "do not keep history" for main item, so it will not be saved to DB at all. Only dependent items values will...
          If you have default templates installed, you can take a look on "Template App Apache by Zabbix agent", where is one "Apache: Get status" item and several different dependent items. Recognized by green "main" item name as prefix...

          Comment

          Working...