Ad Widget

Collapse

Comparing multi segment version number

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • high-t
    Member
    • Dec 2014
    • 68

    #1

    Comparing multi segment version number

    Hi.

    I'm looking to compare version number against minimum version number.
    The problem is that the version number has multiple segment. So, for example, the version number is 8.4.4 and I need to make sure it is not lower than 8.3.9 .

    The current version number is easily retrievable, and the minimum version number is set as a template macro. Naturally, both values are stored as a string.

    So I was thinking of the following approach: Convert the x.y.z string structure to x.yz number, and then compare it.
    For example: Current version 8.4.4 will be converted to 8.44 , minimum version 8.3.9 will be converted to 8.39 , and I can then see that 8.44 is higher than 8.39 .

    Can the above approach be implemented at the preprocessing ? How?
    Any different ideas will be highly appreciated.

    Thank you in advance!
    Amit.
  • Hamardaban
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • May 2019
    • 2713

    #2
    Create a dependent data element in which you can use JS in preprocessing to parse and compare parts of the version with a custom macro.
    The idea is that this element will not return the version itself, but a logical 0/1, depending on the comparison.

    Comment

    • high-t
      Member
      • Dec 2014
      • 68

      #3
      Originally posted by Hamardaban
      Create a dependent data element in which you can use JS in preprocessing to parse and compare parts of the version with a custom macro.
      The idea is that this element will not return the version itself, but a logical 0/1, depending on the comparison.
      Thank you Hamardaban for the reply. This is exactly the approach I eventually took, with just a slight change: Instead or returning 0/1, I return either "UPDATED" or the version number. This way, I'm able to create trigger when the value is not "UPDATED", and then use the value returned as an information for the notification.

      The real challenge, really, was to check if "a.b.c" is lower than "x.y.z" ; none of which are comparable values, and this is where the JScript preprocessing came into play

      This is the final result when checking Zabbix agent version:

      Click image for larger version  Name:	Untitled.png Views:	0 Size:	15.1 KB ID:	401542
      Attached Files

      Comment

      • Hamardaban
        Senior Member
        Zabbix Certified SpecialistZabbix Certified Professional
        • May 2019
        • 2713

        #4
        For zabbix agent version control I use this data element with preprocessing

        Step1 JS
        Code:
        var c= [];
        var m= [];
        c=value.split('.');
        m='{$ZABBIXVERSION}'.split('.');
        if (c[0]== m[0] && c[1]== m[1]) return c[2]<m[2];
        if (c[0]== m[0]) return c[1]<m[1];
        return c[0]<m[0] ;
        Step2 Logical to decimal


        0- all ok / 1 - need update
        Last edited by Hamardaban; 20-05-2020, 19:56.

        Comment

        • high-t
          Member
          • Dec 2014
          • 68

          #5
          But with this logic, version 5.1.1 will be considered lower than 4.2.2 .
          So I divided this to Two checks:
          Start be checking the major version value[0]. If this is OK, then check the minor version by joining value[1] and value [2] into a decimal value, rendering it comparable.

          Comment


          • Hamardaban
            Hamardaban commented
            Editing a comment
            My mistake.
            Updated.
            Last edited by Hamardaban; 20-05-2020, 19:57.
        Working...