[ZBX-13500] fractional triggers are misinterpred without a leading 0 (.1 <> 0.1) Created: 2018 Feb 19  Updated: 2024 Apr 10  Resolved: 2018 Apr 11

Status: Closed
Project: ZABBIX BUGS AND ISSUES
Component/s: Frontend (F)
Affects Version/s: 3.0.14
Fix Version/s: 3.0.17rc1, 3.4.9rc1, 4.0.0alpha6, 4.0 (plan)

Type: Problem report Priority: Trivial
Reporter: David Gessel Assignee: Andrejs Griščenko
Resolution: Fixed Votes: 0
Labels: graphs, thresholds, triggers
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Linux


Issue Links:
Sub-task
depends on ZBX-12292 Trigger line is not displayed on grap... Closed
Team: Team B
Sprint: Sprint 30, Sprint 31
Story Points: 0.5

 Description   

Set a trigger based on a floating point value to ".5" and it gets set to "5" Set it to "-.5" it also gets set to "5" - if you set to "-0.5" the results are as expected.

The leading zero is required or the evaluation of the value is incorrect.



 Comments   
Comment by Glebs Ivanovskis (Inactive) [ 2018 Feb 19 ]

Could you provide an example of trigger expression and some details of item configuration?

Comment by David Gessel [ 2018 Feb 20 ]

"{Template_BRT TPDIN Web Monitor:tyconDINBattery_Amperage.avg(2m)}<-0.5" works as expected and the trigger line in the latest data graph is correctly displayed at -0.5A. "{Template_BRT TPDIN Web Monitor:tyconDINBattery_Amperage.avg(2m)}<-.5" displays the trigger line at (+)5.0A, ignoring both the decimal point and the negative sign. "{Template_BRT TPDIN Web Monitor:tyconDINBattery_Amperage.avg(2m)}<.5" also displays the trigger line at +5A. (not 0.5A, but 10x that, ignoring the decimal point).

This is used to detect power failures as we can't directly monitor AC input (no sensors).

The average function doesn't seem to be needed as the sensors aren't particularly noisy.

Comment by Glebs Ivanovskis (Inactive) [ 2018 Feb 20 ]

So the issue is about frontend displaying wrong thresholds in graphs?

Comment by David Gessel [ 2018 Feb 20 ]

and - it seems, actually triggering on the wrong value (but that's a bit harder to be sure of since almost every power failure results in a charge cycle which puts 10A into the batteries and would trip the +5A trigger as well.

Comment by Glebs Ivanovskis (Inactive) [ 2018 Feb 20 ]

I think it was fixed in 3.4 and higher versions as a part of ZBX-11470.

If it annoys you too much, here are the changes that were made to frontend:

Index: trunk/frontends/php/include/classes/macros/CMacrosResolverGeneral.php
===================================================================
--- trunk/frontends/php/include/classes/macros/CMacrosResolverGeneral.php       (revision 65319)
+++ trunk/frontends/php/include/classes/macros/CMacrosResolverGeneral.php       (revision 65320)
@@ -63,8 +63,12 @@
                // Replace functionids with string 'function' to make values search easier.
                $expression = preg_replace('/\{[0-9]+\}/', 'function', $expression);
 
+               // Replace whitespace with emptyness to make value search easier.
+               $expression = str_replace(" \r\n\t", '', $expression);
+
                // Search for numeric values in expression.
-               preg_match_all('/'.ZBX_PREG_NUMBER.'/', $expression, $values);
+               preg_match_all('/((?<![\)\.0-9]|[\.0-9]['.ZBX_BYTE_SUFFIXES.ZBX_TIME_SUFFIXES.']|function)\-?'.
+                               '([.][0-9]+|[0-9]+[.]?[0-9]*)['.ZBX_BYTE_SUFFIXES.ZBX_TIME_SUFFIXES.']?)/', $expression, $values);
 
                $macro_values = [];
 
Comment by David Gessel [ 2018 Feb 20 ]

Ah OK - I'm on 3.2.11. I'll check after update.

Comment by David Gessel [ 2018 Feb 20 ]

Updated to 3.4.7 - I still see the issue.

If I change the trigger from value from "-0.5" to "-.5 just by deleting the "0" the trigger line moves from negative one half A to positive five A. Adding the leading zero restores the correct position.

it is easy enough to work around, but could be a bit confusing to others, as it was to me initially.

Comment by Glebs Ivanovskis (Inactive) [ 2018 Feb 20 ]

Indeed, just checked it in trunk. A correct value is extracted from trigger expression, but for some reason the threshold is drawn incorrectly.

Comment by Glebs Ivanovskis (Inactive) [ 2018 Feb 20 ]

In frontends/php/include/classes/graphdraw/CLineGraphDraw.php selectTriggers() does

preg_match('/^\{([0-9]+)\}\s*?([\<\>\=]{1})\s*?([\-0-9\.]+)([TGMKsmhdw]?)$/', $trigger['expression'], $arr)

and then

convert($constant)

while convert() (in frontends/php/include/triggers.inc.php) does

preg_match('/(?P<value>[\-+]?[0-9]+[.]?[0-9]*)(?P<mult>['.ZBX_BYTE_SUFFIXES.ZBX_TIME_SUFFIXES.']?)/', $value, $arr)

The last one should be:

preg_match('/(?P<value>[\-+]?[0-9]*[.]?[0-9]*)(?P<mult>['.ZBX_BYTE_SUFFIXES.ZBX_TIME_SUFFIXES.']?)/', $value, $arr)
//                                ^

to allow numbers starting with ".", but unfortunately it will also match empty string. So a more sophisticated regular expression is needed.

Comment by Andrejs Griščenko [ 2018 Mar 28 ]

(1) [F] No translation strings changes.

iivs CLOSED

Comment by Andrejs Griščenko [ 2018 Mar 28 ]

Fixed in development branch svn://svn.zabbix.com/branches/dev/ZBX-13500

Comment by Andrejs Griščenko [ 2018 Apr 06 ]

Fixed in:

  • 3.0.17rc1 r79427
  • 3.4.9rc1 r79429
  • 4.0.0alpha6 (trunk) r79430
Generated at Fri Apr 26 12:18:05 EEST 2024 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.