Ad Widget

Collapse

Display an items previous value

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

    #1

    Display an items previous value

    I would like to display the previous value of an item whenever an event is fired.

    Let's say I have an item that triggers with a value of 0.
    Code:
    last(/hostname/item.key)=0
    Whenever that trigger is true, the operational data should display the latest and previous values.
    I hoped the syntax was something like this:
    Code:
    Last value: {ITEM.LASTVALUE} - Previous value: last(/{HOST.HOST}/{ITEM.KEY},#2)
    For that, I tried to use the last() function, but it won't resolve within "operational data".

    I searched for a macro that would display such a previous value, but could not find it.

    Example:
    Trigger
    Click image for larger version

Name:	testmacro_trigger.png
Views:	4419
Size:	34.5 KB
ID:	445812

    Event
    Click image for larger version  Name:	testmacro_example.png Views:	0 Size:	10.6 KB ID:	445809

    Any idea?
    Last edited by markfree; 08-06-2022, 16:49.
  • cyber
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Dec 2006
    • 4807

    #2
    This does not work... Operational data supports macros,
    Operational data allow to define arbitrary strings along with macros.
    but you cannot use trigger functions there to modify macro value or even pull completely different value. Customizing macro values is supported only for couple of macros, like {ITEM.VALUE} and {ITEM.LASTVALUE} (https://www.zabbix.com/documentation...acro_functions)

    To resort to usable macros, you are forced to include needed value in your trigger expression (prev(/host/item).... find some function which is always true and does not affect whole calculation) and refer to it in Operational data as {ITEM.LASTVALUE2}.

    Comment

    • markfree
      Senior Member
      • Apr 2019
      • 868

      #3
      I thought of using {FUNCTION.VALUE} macro as it actually works with event names, but it does not work with operational data or trigger description.
      Something like this:
      Code:
      last(/Single/test.macro)=0 and last(/Single/test.macro,#2)
      Click image for larger version

Name:	function_value_macro.png
Views:	4282
Size:	11.9 KB
ID:	446050

      Maybe {ITEM.VALUE} would work out, but, unless I'm using different items in the trigger expression, I don't see how to do this.

      Comment

      • fpaternot
        Member
        Zabbix Certified Specialist
        • Feb 2013
        • 52

        #4
        Have you guys tried using this?

        find(/template/item,"a")<>2 (yes, it returns 0 or 1, so using "different than 2" works for all possible return values)
        {ITEM.VALUEn} and/or {ITEM.LASTVALUEn} in operational data.

        I've used this hack myself for years.

        I don't see another way to get data there.

        Comment

        • markfree
          Senior Member
          • Apr 2019
          • 868

          #5
          Maybe I misunderstood, but I don't think this would work.

          When I try to include something like "find(/Single/test.123,"a")<>2", I get an error when saving the trigger because the function parameter is invalid.
          Invalid parameter "/1/expression": invalid second parameter in function "find".
          If I include the correct parameters, but matching a string, then the trigger gets "not supported".
          Cannot evaluate function find(/Single/test.123,#2,"like","test"): operator "like" is not supported for counting numeric values.
          Click image for larger version

Name:	image.png
Views:	511
Size:	11.2 KB
ID:	502094

          Unless I know the item value range, I cannot match a number to avoid false positives. However
          ​, with a known value range, I can use the find function to match something other than 0 or 1. This can actually trigger an event.
          Click image for larger version

Name:	image.png
Views:	493
Size:	8.5 KB
ID:	502096

          Still, I can't display the previous value in the operational data field.
          Click image for larger version

Name:	image.png
Views:	495
Size:	7.0 KB
ID:	502097
          Click image for larger version

Name:	image.png
Views:	489
Size:	8.2 KB
ID:	502095
          In this example, the previous value should be "10".
          Click image for larger version

Name:	image.png
Views:	509
Size:	5.9 KB
ID:	502098

          Comment

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

            #6
            ITEM.VALUE2 refers to the last value of the second used item... but you are using one item twice...So you get same value twice...
            Expression macros? Too lazy to test myself..
            Code:
            last - {?last(/Single/test.123)} - previous {?last(/Single/test.123,#2)}

            Comment

            • markfree
              Senior Member
              • Apr 2019
              • 868

              #7
              I tested with expression macros, but they are not supported on the operational data field.

              Comment

              Working...