Ad Widget

Collapse

Inventory macro in trigger expression

Collapse
This topic has been answered.
X
X
 
  • Time
  • Show
Clear All
new posts
  • neoflamez
    Junior Member
    • Mar 2022
    • 5

    #1

    Inventory macro in trigger expression

    Hey all,

    Got a situation whereby I want to:

    1. Get the output of a check and populate inventory (done)
    2. Create a trigger using a calculated expression based on the output of the above (struggling)

    It seems you can't use inventory macros in expressions (I don't know why). It also seems you can't set a user macro to be the value of an inventory macro.

    Any ideas gratefully received.
  • Answer selected by neoflamez at 17-03-2022, 17:36.
    LenR
    Senior Member
    • Sep 2009
    • 1005

    Here is a trigger that tests the last observation against the avg(7d)*6; or 6x the running average.

    {Elastic Index Watch Counters for ES:watch_counter["filebeat-*",5].avg(7d)}*6<{Elastic Index Watch Counters for ES:watch_counter["filebeat-**",5].last()}

    Comment

    • LenR
      Senior Member
      • Sep 2009
      • 1005

      #2
      So you used item -> to inventory? Then trying to use inventory in a trigger? Can't you just use the original item?

      Comment

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

        #3

        Can you see here anywhere a note, that you can use inventory macros in trigger expressions? You can use user macros there as constants or function parameters. And that's all.
        Assigning one macro to another (ie {$USERMACRO} = {INVENTORY.MACRO} ) does not work also. It will be taken literally, not resolved (again).

        Question remains, why aren't you using item value directly as LenR already pointed out?

        Comment

        • neoflamez
          Junior Member
          • Mar 2022
          • 5

          #4
          Originally posted by LenR
          So you used item -> to inventory? Then trying to use inventory in a trigger? Can't you just use the original item?
          Probably should've clarified - Item1 -> inventory. Want a trigger on Item2 to use the value from the inventory (or from item1) in a calculation. Can I refer to Item1.value in Item2.trigger? I wasn't aware this could happen?

          Comment

          • neoflamez
            Junior Member
            • Mar 2022
            • 5

            #5
            Originally posted by cyber
            https://www.zabbix.com/documentation...ed_by_location
            Can you see here anywhere a note, that you can use inventory macros in trigger expressions? You can use user macros there as constants or function parameters. And that's all.
            Assigning one macro to another (ie {$USERMACRO} = {INVENTORY.MACRO} ) does not work also. It will be taken literally, not resolved (again).

            Question remains, why aren't you using item value directly as LenR already pointed out?
            Hey cyber,

            Nope - I didn't see it anywhere - I read the docs and thought I'd give it a go... sometimes these are 'undocumented features'. It clearly didn't work (as the docs point out and as you've pointed out again) so I came to the forum for an answer.... I've answered LenR above, let me know your thoughts.

            Comment

            • LenR
              Senior Member
              • Sep 2009
              • 1005

              #6
              Here is a trigger that tests the last observation against the avg(7d)*6; or 6x the running average.

              {Elastic Index Watch Counters for ES:watch_counter["filebeat-*",5].avg(7d)}*6<{Elastic Index Watch Counters for ES:watch_counter["filebeat-**",5].last()}

              Comment

              • neoflamez
                Junior Member
                • Mar 2022
                • 5

                #7
                Originally posted by LenR
                Here is a trigger that tests the last observation against the avg(7d)*6; or 6x the running average.

                {Elastic Index Watch Counters for ES:watch_counter["filebeat-*",5].avg(7d)}*6<{Elastic Index Watch Counters for ES:watch_counter["filebeat-**",5].last()}
                Thanks Len, I can't believe I didn't see it before but of course I can just multiply by the key of the other Item.... you're a star!

                Comment

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

                  #8
                  Trigger expressions are not limited to one single item. You can compare multiple item values or use them in math operations. Even if LenR shows usage of same item twice (last vs avg over time plus some multiplication), you can compare 2 separate items with each other. item1.last() >item2.last() or item1*item2 > X etc...

                  Comment

                  • neoflamez
                    Junior Member
                    • Mar 2022
                    • 5

                    #9
                    Originally posted by cyber
                    Trigger expressions are not limited to one single item. You can compare multiple item values or use them in math operations. Even if LenR shows usage of same item twice (last vs avg over time plus some multiplication), you can compare 2 separate items with each other. item1.last() >item2.last() etc....
                    Yep - just clocked that... appreciate the input.

                    Comment

                    • highpeak
                      Member
                      • Nov 2019
                      • 30

                      #10
                      I have the same requirement. I have an inventory field populated via the API (serial number A), and an item that gets the actual device's actual serial number via SNMP and populates serial number B - I want to trigger if serial A is different from serial B (or if last(item) <> inventory.serial.a).

                      Is this not possible?

                      Comment

                      Working...