Ad Widget

Collapse

undefined expression variables?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yurtesen
    Senior Member
    • Aug 2008
    • 130

    #1

    undefined expression variables?

    I tried to search "undefined expression variables" in forum but got release announcements only.
    I was wondering what happens during evaluation when there is an undefined value in an expression?

    For example I am comparing 2 values obtained using SNMP with each other, what happens if one value is missing altogether?

    Also I was revieving iLO template and it seems like PSU warn/crit temperatures are missing yet they are mentioned in the template as described here. What happens in such cases when the variable is missing?

    I am wondering about it because I did not see any errors in the logs. Also is there a way to log such problems?
  • dimir
    Zabbix developer
    • Apr 2011
    • 1080

    #2
    If I understand it correctly you are talking about trigger expressions. Trigger expressions are evaluated every time one of the items it refers to gets new value. Triggers have state, which can be one of NORMAL or UNKNOWN. When trigger is created its state is set to NORMAL. In UNKNOWN state firing is not possible. When one of the items a trigger refers to gets new value the trigger expression gets evaluated. If one of the values of the items it refers to is missing, trigger state changes to UNKNOWN.

    The most common situation is examining the last value. Consider the following example (fire a trigger if item1 or item2 get value higher than 10):

    Code:
    {HOST:item1.last()}>10 or {HOST:item1.last()}>10
    These items are new, they don't have any values yet. Now,
    • item1 gets the first value
    • trigger expression is evaluated, item2 doesn't have values yet, so
    • trigger state changes to UNKNOWN, no firing in any case
    • item2 gets the first value
    • trigger expression is evaluated, all the needed values are available (for item1.last(), the previously tested value is used)
    • trigger state changes to NORMAL and firing depends on the result
    So, don't be afraid of "missing expression variables". It is natural situation for Zabbix and it's handled properly.
    Last edited by dimir; 31-01-2020, 13:17.

    Comment

    • yurtesen
      Senior Member
      • Aug 2008
      • 130

      #3
      dimir thanks for the explanation and it has been very useful. I tried what you explained and managed to get some triggers to turn into UNKNOWN state when I introduced unknown variables.
      I am guessing when you mean "NORMAL" you mean the "ENABLED" state. Triggers seem to have ENABLED, DISABLED and UNKNOWN states as explained in the docs:


      However I also realized that when a trigger is inserted with auto discovery, it has a default state of ENABLED, even if none of the variables are fetched yet. It switches to unknown only after one of the values being fetched but some other is missing. I think this is because no evaluation is done until a variable is received perhaps? So there can be a situation where the trigger shows "ENABLED" if none of the variables ever arrive?

      So is there a way to force trigger expressions to get evaluated without waiting for a variable value to arrive?

      Comment

      • dimir
        Zabbix developer
        • Apr 2011
        • 1080

        #4
        You are mixing _Status_ and _State_ of a trigger. Status can be _enabled_ or _disabled_. This is just what you manually do in the frontend to enable/disable a trigger.
        Then there's _State_ of a trigger. State is handled internally and it may be _normal_ or _unknown_. Usually the state is _normal_ and it gets to _unkown_ when something unexpected happens during trigger evaluation.
        You can actually create an action that would fire on such occasion, when trigger changes state to _unknown_: https://www.zabbix.com/documentation...nternal_events
        More on trigger state changes (although I'm not happy with how complicated this page is): https://www.zabbix.com/documentation...ers/expression
        As to forcing a trigger expression to be evaluated properly when one of the items it refers to has no values yet - no, this is impossible, sorry. In this case a trigger changes state to unknown and, as I mentioned before, you can catch that by having a special action for _Internal events_.
        Last edited by dimir; 03-02-2020, 09:38.

        Comment

        • yurtesen
          Senior Member
          • Aug 2008
          • 130

          #5
          dimir I have seen _Status_ as Unknown also? and documentation says it can become Unknown?. But if it is wrong indicator for figuring out if there are unkown values in a trigger expression, then how/where can I see _State_ that you mentioned?

          That page about internal events is quite interesting and sounds useful. Although I am still not sure how to make triggers for internal events. I will check it out tomorrow. Thanks for the link!

          The expression documentation is even more interesting as in the end it says unknown values may be evaluated... This makes me more confused now as my original intent was to figure out how to find out if there are unknown values in trigger expressions. This seems quite difficult to accomplish if a trigger expression can run happily even with unknown values. As far as I understand it says "True or unknown_value" will return True. hmm?

          Just to be clear, I did not want to force an expression to evaluate with missing items. I want to find expressions with missing items. Perhaps I should make some screenshots to explain myself. I will try to do that tomorrow and post more information.

          Comment

          • yurtesen
            Senior Member
            • Aug 2008
            • 130

            #6
            OK so here is the screenshots. When no data ever arrived, the trigger shows "Enabled"
            Trigger with no valid data
            When one of the variables arrive, "then" it turns as unknown.
            After receiving one variable
            So my question is, how to tell that an "Enabled" trigger has data or not? or how to find that there are triggers with no data ever?

            It seems that trigger won't turn into "Unknown" status unless it is evaluated. But it won't evaluate if it does not receive any of the variables... so if data never arrives, then trigger will look like it is working but it would not be doing anything...

            If I could force the trigger expression to evaluate, zabbix could show me which variables are missing perhaps?
            Last edited by yurtesen; 04-02-2020, 12:16.

            Comment

            • dimir
              Zabbix developer
              • Apr 2011
              • 1080

              #7
              As far as I understand it says "True or unknown_value" will return True. hmm?
              This means if there are 2 conditions in an expression with an "or" and the first condition evaluates to "true" we do not care about the second one. Consider the following examples:
              Example 1.
              • item1 gets value 3
              • item2 has no values yet
              • trigger expression: item1 > 2 or item2 > 2
              Result: trigger expression is evaluated and the result is true
              Since the result of first condition is true we do not care about the second one.

              Example 2.
              • item1 gets value 3
              • item2 has no values yet
              • trigger expression: item1 > 2 and item2 > 2
              Result: trigger expression is not evaluated since we need to but can't evaluate the second condition, thus trigger state is set to UNKNOWN.

              Now, regarding UNKNOWN status in Frontend. You are right, some time ago there was a decision to not confuse users with status/state and so this was combined into just the Status column. Here I have a couple of triggers with Unknown status/state:

              Click image for larger version  Name:	trigger-state-unknown.png Views:	0 Size:	41.0 KB ID:	394777
              Let's see what is in the database, I will use the IDs of those triggers:
              Code:
              > select status,state from triggers where triggerid in (13537,13436);
              +--------+-------+
              | status | state |
              +--------+-------+
              |      0 |     1 |
              |      0 |     1 |
              +--------+-------+
              2 rows in set (0.001 sec)
              Let's translate those numbers:
              Code:
              $ grep TRIGGER_ST include/common.h
              #define TRIGGER_STATUS_ENABLED          0
              #define TRIGGER_STATUS_DISABLED         1
              #define TRIGGER_STATE_NORMAL            0
              #define TRIGGER_STATE_UNKNOWN           1
              As you can see in Frontend we display Status as UNKNOWN, which is not exactly true.
              And again, if you need to catch those UNKNOWNs, the only chance is to set up an action for Internal events.
              Last edited by dimir; 04-02-2020, 13:32.

              Comment

              • yurtesen
                Senior Member
                • Aug 2008
                • 130

                #8
                dimir thanks for your patience. I now tried some strange combinations and the triggers seem to turn into unknown state. So it works pretty good and as you explained... I will let you know if I manage to break zabbix

                Comment

                Working...