Ad Widget

Collapse

Calculated Item sum for lifetime

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hectorsaratoga
    Junior Member
    • Oct 2018
    • 14

    #1

    Calculated Item sum for lifetime

    Hello

    I'm trying to create an item that stores the total number of hours the computers are on.

    I have created a calculated item

    key= total.hours
    Fomula = last("total.hours")+diff("system.uptime")

    Click image for larger version

Name:	1.jpg
Views:	1916
Size:	35.0 KB
ID:	415561

    But if it's the first time or it has no total value.hours gives an error.

    "Cannot evaluate expression: "Cannot evaluate function "last()": item "pd2008:total.hours" not supported."



    How can I store and add up all the hours that the item is active?

    The idea is to add them to the inventory as too.


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

    #2
    Your expression does not work because there is no initial value for this item.
    And if it is not, then the last() function will not work and item will not work again.

    Change the formula for example to 0+0, wait for the expression to trigger and write the value to the database, and then change the formula to your own.

    Try searching the forum - this topic has already been discussed.

    Comment

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

      #3
      Probably it would be more correct to use change()

      Comment

      • hectorsaratoga
        Junior Member
        • Oct 2018
        • 14

        #4
        Thanks to all of you

        Isn't there an option to set an initial value that can be automatic? With a macro you could?

        modifying the formula manually every time a new host enters does not seem feasible to me.

        I've been looking through the forum, but I didn't find anything that was automatic.

        Thank you.

        Comment

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

          #5
          Use preprocessing to write the initial value when an item error occurs

          Comment

          • hectorsaratoga
            Junior Member
            • Oct 2018
            • 14

            #6
            I think I'm doing it wrong, I'm still failing. :-(

            Click image for larger version

Name:	3.jpg
Views:	1773
Size:	13.8 KB
ID:	415615

            Comment

            • hectorsaratoga
              Junior Member
              • Oct 2018
              • 14

              #7
              I'm really going crazy, I've tried a thousand things and I don't get it

              I don't understand what I have to do :-(


              Click image for larger version

Name:	5.jpg
Views:	1785
Size:	51.9 KB
ID:	415629

              Expression
              Click image for larger version

Name:	4.jpg
Views:	1788
Size:	24.0 KB
ID:	415630

              Click image for larger version

Name:	6.jpg
Views:	1786
Size:	27.2 KB
ID:	415631

              Comment

              • Semiadmin
                Senior Member
                • Oct 2014
                • 1625

                #8
                Originally posted by cyber
                Let that regex return whatever there is, but set "Custom on fail". That will set value to something you like, if there is no value at all and calculation fails...
                It's a clever trick, but "Custom on fail" won't work. But maybe a new option "Check for not supported value" in version 5.2 will help.
                Last edited by Semiadmin; 22-12-2020, 17:16.

                Comment


                • Hamardaban
                  Hamardaban commented
                  Editing a comment
                  That's what I was talking about.

                • cyber
                  cyber commented
                  Editing a comment
                  Yep, I should not write things, while on vacation.. Of course it won't help, if there is no value present...
              • hectorsaratoga
                Junior Member
                • Oct 2018
                • 14

                #9
                Thanks .

                I'm in 5.0 :-(

                So there's no way to do a sum a = a +b without failing the first time, no?

                Comment

                • hectorsaratoga
                  Junior Member
                  • Oct 2018
                  • 14

                  #10
                  Thank you all but it doesn't work for me either.


                  I don't know, after Christmas I'll come back to give it a thought but I think I'll have to do it with a local script. :-(

                  Comment

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

                    #11
                    And diff() just tells you that there is a difference, not how big it is...
                    diff
                    Checking if last and previous values differ. Supported value types: float, int, str, text, log

                    Returns:
                    1 - last and previous values differ
                    0 - otherwise

                    Comment

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

                      #12
                      Let that regex return whatever there is, but set "Custom on fail". That will set value to something you like, if there is no value at all and calculation fails...

                      Comment

                      • Semiadmin
                        Senior Member
                        • Oct 2014
                        • 1625

                        #13
                        It works in 5.2.6 via "Check for not supported value" preprocessing.
                        But be careful: in early 5.2 minors, this trick leads to zabbix server restart.

                        Comment

                        Working...