Ad Widget

Collapse

Preprocessing - convert string to integer

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • codemaker
    Junior Member
    • Aug 2019
    • 10

    #1

    Preprocessing - convert string to integer

    Hi,

    I'm facing this issue and I would like to get some guidance. I'm monitoring a file by using "vfs.file.contents[/tmp/progress.zab]" item with "log" as the type of information. The file's content is something similar to:
    Code:
    5
    0
    50
    100
    I would like to preprocess it to get the final result as:
    Code:
    STEP 5
    100
    I'm using the following pre-processing rule:
    Code:
    Name: Regular expression
    Parameters: (^\d?)([0-9]{1,3}$)
    Output: STEP \1 \2
    I'm getting the following error:
    Code:
    Item preprocessing step #1 failed: cannot perform regular expression match: pattern does not match, type "string", value "5 0 100"
    The output of the item is string but I want to treat the numbers as "numbers". How can I do that?
  • maxiorek
    Junior Member
    • Jan 2020
    • 1

    #2
    I had similar problem and I've solved it.
    In my case the output value is a single digit from 0 to 6. The original value was text, I've converted it to a digit using regular expressions in preprocessing steps, but for Zabbix it was still a text value (because regular expression is just for text type information). I've added as the last step "In range" and I've put there values 0 for min and 6 for max. After that I could change the item's type of information to a numeric and my values are stored as numbers, so I can use advantages such as drawing charts and using many trigger functions.

    However I'm not sure if it works for you. When you have type of information set to a text do you get a number value or a number with spaces? I'm wondering if everything is ok with your regular expression. If it is fine and returned values are numbers without spaces try to do the same what I've done. Of course you have to adjust minimum and maximum values to your data.

    Validation preprocessing steps (which is "In range") are available from Zabbix version 4.4.

    Comment

    Working...