Ad Widget

Collapse

Unable to get previous value of Template item by trigger

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • reddysk
    Junior Member
    • Jan 2024
    • 8

    #1

    Unable to get previous value of Template item by trigger


    Hello,

    i am fighting with configuration of trigger on item when I need to publish last and previous value.

    Even I went over all possible and impossible Zabbix forum articles even outside this forum I haven't found the right solution.


    At the end I tried all possible options I derivate from all advises and tried:
    Code:
    Last value: {ITEM.LASTVALUE1}; All values: {ITEM.LASTVALUE} - [{?last(/{HOST.HOST}/{ITEM.KEY1},#2)}] - {?last(/{HOST.HOST}/{ITEM.KEY1},#2)} - last(/{HOST.HOST}/{ITEM.KEY1},#2) - {{HOST.HOST}:{ITEM.KEY}.last()} - {ITEM.VALUE1} to {ITEM.VALUE2}
    I got:
    Code:
    Last value: 36; All values: 36 - [{?last(/localhost/{ITEM.KEY1},#2)}] - {?last(/CZCHOWS6831.prg-dc.dhl.com/{ITEM.KEY1},#2)} - last(/localhost/{ITEM.KEY1},#2) - {localhost:{ITEM.KEY}.last()} - 36 to *UNKNOWN*
    Any advise please?

    Running on Zabbix 6.4.10 appliance image.


    Thanks in advance, Cheers, Reddy

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

    #2

    {ITEM.LASTVALUE1} - returns last value, no option to point to second or third... those numbers there point to first item, second item, third item... used in expression...
    {ITEM.KEY1} - returns they key of item, not a value. number as above, point to different keys, not to value...

    {?last(/{HOST.HOST}/{ITEM.KEY},#2)} - close...but add all that to "Event name" field in trigger config, not to "trigger name" ...

    Comment


    • reddysk
      reddysk commented
      Editing a comment
      Cyber, I am trying that in Operational data, not in trigger name.

      Will try this and will see. Pending issue to initiate the trigger.
      Last value: {ITEM.LASTVALUE1}; Previous value: {?last(/{HOST.HOST}/{ITEM.KEY},#2)}

    • reddysk
      reddysk commented
      Editing a comment
      So it doesn't work:

      Last value: 40; Previous value: {?last(/localhost/{ITEM.KEY},#2)}
  • PeterZielony
    Senior Member
    • Nov 2022
    • 146

    #3
    where does it need to be published: email/webhook?


    Hiring in the UK? Drop a message

    Comment


    • reddysk
      reddysk commented
      Editing a comment
      Peter, in both. But As mentioned above, I wanted to have the information in Operational data of trigger.
  • GarrettCO
    Member
    • Jan 2024
    • 44

    #4
    I am having very similar issue where no trigger is firing from "OK" to "Problem". Regardless of the documentation example this expression sample doesn't trigger and action when sending an SNMPTRAP

    Click image for larger version  Name:	Screenshot 2024-01-30 at 9.23.44 AM.jpg Views:	0 Size:	30.9 KB ID:	478017

    Using the following to send test trap
    # snmptrap -v 2c -c public localhost 0 0 linkUp.0 s 0
    Last edited by GarrettCO; 30-01-2024, 18:30.

    Comment

    • PeterZielony
      Senior Member
      • Nov 2022
      • 146

      #5
      With Webhook it would be doable (email a bit harder - but you would have to do some scripting outside from frontend for emails)- you can write javascript to obtain previous value based on triggerID.

      https://www.zabbix.com/documentation...ce/trigger/get

      then get expandExpression and choose what you need to query. Use the second API function to obtain #2 value for this item
      https://www.zabbix.com/documentation...ce/history/get

      and at the end - send msg via webhook as normal with both values.

      this sounds a bit tricky but doable - specially for webhooks. There is also a possibility that last #2 by the time you get it - it won't be #2 anymore so you would have to figure out how to get the previous one.

      in nutshell - query zabbix itself for the previous value but you need to build logic to make sure #2 is the right one.

      Don't have solution in hand - but worth looking at querying via api using webhook before sending it further
      Last edited by PeterZielony; 31-01-2024, 06:15.

      Hiring in the UK? Drop a message

      Comment

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

        #6
        TBH, I have not done much with expression macros, so I did some testing now...
        Using very simple testitem
        Click image for larger version  Name:	image.png Views:	0 Size:	5.9 KB ID:	478060

        and very simple trigger
        Code:
        last(/host/testitem)>0
        What seems to be working, is setting trigger event name to
        Code:
        testitem trigger, item value {ITEM.LASTVALUE} - Prev value: {?last(//testitem,#2)}
        using {ITEM.KEY} in expression macro gives error, even if https://www.zabbix.com/documentation...ed_by_location says
        {?EXPRESSION} → Trigger event names
        ​and https://www.zabbix.com/documentation...ression_macros says

        {HOST.HOST<1-9>} and {ITEM.KEY<1-9>} macros are supported inside expression macros
        using {ITEM.KEY} directly in event name field leaves it unresoved as docs say, its not usable there...
        Last edited by cyber; 31-01-2024, 10:00.

        Comment


        • reddysk
          reddysk commented
          Editing a comment
          Cyber, thank you, I will try it.
          But please note that I am not trying to get it to name, but to Operational data
      • cyber
        Senior Member
        Zabbix Certified SpecialistZabbix Certified Professional
        • Dec 2006
        • 4807

        #7
        Originally posted by GarrettCO
        I am having very similar issue where no trigger is firing from "OK" to "Problem". Regardless of the documentation example this expression sample doesn't trigger and action when sending an SNMPTRAP

        Click image for larger version Name:	Screenshot 2024-01-30 at 9.23.44 AM.jpg Views:	0 Size:	30.9 KB ID:	478017

        Using the following to send test trap
        # snmptrap -v 2c -c public localhost 0 0 linkUp.0 s 0
        Of course it does not work... if you go a nd look on your latest data, your item value for snmptrap[linkUp] item is not just "0".
        it probably something like
        Code:
        20240131.093244 UDP: [source]:52463->[destination]:162
        DISMAN-EVENT-MIB::sysUpTimeInstance = 0:0:00:00.00
        SNMPv2-MIB::snmpTrapOID.0 = IF-MIB::linkUp.0


        But this is completely offtopic, you should have started your own...

        Comment

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

          #8
          • reddysk
            #6.1
            reddysk commented
            Today, 10:10
            Cyber, thank you, I will try it.
            But please note that I am not trying to get it to name, but to Operational data
          aaragh.,. it is impossible to quote properly those "comments"... stupid feature..

          I was about to edit my post... For opdata all that will not work.. only if you construct your trigger based messages properly (message templates for media)... There you can use much more macros than in trigger config...

          Comment

          Working...