Thold Consider Unknown Data as Zero setting not working as expected

Support questions about the Threshold plugin

Moderators: Developers, Moderators

Post Reply
TDD
Posts: 10
Joined: Tue Jul 25, 2017 1:55 pm

Thold Consider Unknown Data as Zero setting not working as expected

Post by TDD »

Haven't found this issue in other forum posts or github issues for thold, so sharing my experience:

Recently enabled thold version 1.5.2 on a Cacti server running version 1.2.23. We have graphs for temperature sensors and want to enable both high and low thresholds on these. Some of these sensors occasionally experience connectivity issues, which results in NaNs in the graphs. When the NaNs occur, thold is considering the value to be zero.

I am aware of the thold setting "Consider Unknown Data as Zero", and have verified this option is disabled.

Dove into the code a bit and I believe I've found what is happening. In thold_functions.php, the function thold_get_currentval starting on line 733:

The variable currentval is set to zero on line 750. That variable will be changed within the function based on the logic of the switch statement starting in line 755, however that switch statement is only evaluated when the if statement on line 754 is true.

That if statement checks the value of the item to see whether or not it is a numeric value. If it is, then we proceed to the switch statement. If it isn't, then we skip all of that and simply return currentval. This means that if the current value of the item is non-numeric, we are always returning zero.

In polling.php, we use this function on line 384, and use the result to populate the value of the postvalue variable, which is fed into another "currentval" variable in the next line.

The logic related to considering unknown as zero appears shortly thereafter within the same function, starting lines 417 to 428. However the if statement on line 417 is never true:

if (!is_numeric($currentval))

because per the above explanation, whenever that value is non-numeric, we've already set it to zero.

In my deployment I made a simple change to thold_functions.php on line 750....changed it from this:

$currentval = 0;

To this:

$currentval = '';

With that change, any thresholds where the graph has a NaN as the current value, the threshold shows current value as a dash, instead of a zero, and we no longer get low threshold breach alerts. Hopefully this was the correct change to make, and doesn't create any problems elsewhere that I'm not aware of.
User avatar
TheWitness
Developer
Posts: 17047
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

Re: Thold Consider Unknown Data as Zero setting not working as expected

Post by TheWitness »

See if you can reproduce this on the develop version of thold.
True understanding begins only when we realize how little we truly understand...

Life is an adventure, let yours begin with Cacti!

Author of dozens of Cacti plugins and customization's. Advocate of LAMP, MariaDB, IBM Spectrum LSF and the world of batch. Creator of IBM Spectrum RTM, author of quite a bit of unpublished work and most of Cacti's bugs.
_________________
Official Cacti Documentation
GitHub Repository with Supported Plugins
Percona Device Packages (no support)
Interesting Device Packages


For those wondering, I'm still here, but lost in the shadows. Yearning for less bugs. Who want's a Cacti 1.3/2.0? Streams anyone?
TDD
Posts: 10
Joined: Tue Jul 25, 2017 1:55 pm

Re: Thold Consider Unknown Data as Zero setting not working as expected

Post by TDD »

Thanks, I upgraded my lab to Cacti 1.2.25 and thold 1.8, and I am seeing the same behavior. The code in for the function thold_get_currentval in threshold_functions.php looks largely unchanged between versions. I made the same change and it seems to have resolved the issue with these versions as well.
User avatar
Osiris
Cacti Guru User
Posts: 1424
Joined: Mon Jan 05, 2015 10:10 am

Re: Thold Consider Unknown Data as Zero setting not working as expected

Post by Osiris »

There was a change by xmacan yesterday. Did you pick that up?
Before history, there was a paradise, now dust.
User avatar
Osiris
Cacti Guru User
Posts: 1424
Joined: Mon Jan 05, 2015 10:10 am

Re: Thold Consider Unknown Data as Zero setting not working as expected

Post by Osiris »

There is also a setting for that too.
Before history, there was a paradise, now dust.
TDD
Posts: 10
Joined: Tue Jul 25, 2017 1:55 pm

Re: Thold Consider Unknown Data as Zero setting not working as expected

Post by TDD »

Thanks Osiris. Yes I did grab the latest version which includes the change by xmacan.

If the setting you are referring to is the one shown below, I've got that disabled. My theory is that the code is defaulting the current value to zero before it gets a chance to evaluate that setting.

consideraszero.JPG
consideraszero.JPG (134.56 KiB) Viewed 5929 times
User avatar
Osiris
Cacti Guru User
Posts: 1424
Joined: Mon Jan 05, 2015 10:10 am

Re: Thold Consider Unknown Data as Zero setting not working as expected

Post by Osiris »

You should add some instrumentation in that function that logs to cacti_log() only for the thold_id in question and once you have a good idea what is going on, log a feature or bug report.
Before history, there was a paradise, now dust.
TDD
Posts: 10
Joined: Tue Jul 25, 2017 1:55 pm

Re: Thold Consider Unknown Data as Zero setting not working as expected

Post by TDD »

Sounds good. Before my first post I did add logging as you suggested, which was how I came to the conclusions in my first post. I believe I have a pretty good idea what is happening, just wanted to post it here first in case it was already a known issue, or in case I had made a mistake in my investigation which someone could point out to me. I'll go ahead and submit a bug report.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest