Ad Widget

Collapse

Getting numeric data from the item value string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • karlism
    Junior Member
    • Sep 2015
    • 10

    #1

    Getting numeric data from the item value string

    Hello,

    I'm having hard time figuring out the problem that I'm trying to solve.

    The goal that I want to achieve is to monitor master and slave DNS servers to see if DNS zones on them are in sync. That can be easily done by monitoring zone SOA record and using net.dns.record item key as every time zone is updated it's serial number changes and it is easy to notice mismatch. I get items with string values like this from each DNS server:
    "example.com SOA ns.example.com hostmaster.example.com 2016060600 300 120 2419200 7200"
    So far so good.

    Unfortunately trigger function documentation page says that "All functions return numeric values only. Comparison to strings is not supported" so I'm out of luck comparing values of these items directly.

    What I would like to achieve is to extract numeric serial number value ("2016060600" in the example above) from the SOA record item string. Is it possible at all or should I give up and use external scripts to achieve my goal?

    Thanks!
  • DmitryL
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • May 2016
    • 278

    #2
    Hello karlism!

    As i see, unfortunately there are no built in possibility to convert string to number, or extract numbers from strings in zabbix.
    You can find Feature Request that should help in your case.


    As for now i would recommend using external scripts. There are very common functions to solve your problem.

    Best regards,
    Dmitry

    Comment

    • sudo092
      Junior Member
      • Sep 2018
      • 7

      #3
      I came here looking for an answer at one point and then found out that as of Zabbix 3.4 (I believe) you can use item preprocessing to convert string values to integers with regex. So I thought i'd share my experience with it.

      I'll use an example of converting MySQL "Slave_io_running" string states to numeric metrics....

      In the item preprocessing tab i used two steps to convert string values into integers using match and replace functionality like this...

      Name Parameters Output

      Regular expression (.*) \1:No=0:Yes=1:Connecting=2
      Regular expression (No|Yes|Connecting)(?=.*:\1=(\d)) \2


      Comment

      • Chassepa
        Junior Member
        • Sep 2016
        • 5

        #4
        Hello sudo092,

        Your solution is absolutely brilliant.

        Comment

        • fjofes
          Junior Member
          • Aug 2020
          • 1

          #5
          Personaly I used Javascript to convert my Zabbix string value to int in a preprocessing step : parseInt(value)

          Comment

          • MoT
            Junior Member
            • Feb 2020
            • 8

            #6
            Originally posted by sudo092
            Name Parameters Output
            Regular expression (.*) \1:No=0:Yes=1:Connecting=2
            Regular expression (No|Yes|Connecting)(?=.*:\1=(\d)) \2
            We do not see the split between value, let me correct
            Name Parameters Output
            Regular expression (.*) \1:No=0:Yes=1:Connecting=2
            Regular expression (No|Yes|Connecting)(?=.*:\1=(\d)) \2

            Someone explained all of this here:
            This document represents the following zabbix features/techniques: UserParameter which will discover all services. JSON format containing 2...


            Apart from that, I think that you can also use Custom on fail option to set a default value for unrecognised strings

            as described here:



            Comment

            • zarkgnok
              Junior Member
              • Jun 2021
              • 2

              #7
              On Zabbix 5.4 here.
              I got it working by adding a single pre-processing step:
              select 'Simple change' from the dropdown.
              If you test it with the [test] button, you should see
              your value succeeding the test, and
              a footnote by Zabbix: "Result converted to Numeric (unsigned)"

              HTH!

              Michael




              Comment

              • zarkgnok
                Junior Member
                • Jun 2021
                • 2

                #8
                Sorry, forget my earlier answer, it didn't output any data.

                Notes: working on Zabbix 5.4 here.

                I've got TWO preprocessing steps, and can confirm it's working now.
                First preprocessing step:
                (dropdown):'regular expression' left field: (.*) right field: \1

                Second preprocessing step:
                (dropdown) 'simple change' <no parameters possible>


                It even seems to work just with the first preprocessing step.

                HTH,
                Michael

                Comment

                • DeeZ
                  Member
                  • Aug 2015
                  • 82

                  #9
                  I do it with processing (Zabbix 6.0)

                  On item - processing - javascript

                  "return parseInt(value)"

                  Comment

                  Working...