Cycle plugin - legend not working correctly

General discussion about Plugins for Cacti

Moderators: Developers, Moderators

Post Reply
jhorne
Posts: 26
Joined: Mon Dec 05, 2011 11:45 am

Cycle plugin - legend not working correctly

Post by jhorne »

Hello,

Using the cycle (v2.0) plugin, the settings have a 'Display Legend' checkbox. However, despite ticking this and saving the settings, the graphs are not showing the legend by default. The 'Display Legend' checkbox on the graphs page is unchecked.

I suspect that either the value is not being checked or that it is not being saved correctly. If I check the checkbox on the graph page, then the one on the settings page is cleared!
jhorne
Posts: 26
Joined: Mon Dec 05, 2011 11:45 am

Re: Cycle plugin - legend not working correctly

Post by jhorne »

As far as I can see the problem is in 'cycle.php'. It says:

foreach($defaults as $name => $value) {
$current = db_fetch_cell("SELECT value FROM settings WHERE name='$name'");
if ($current !== false) {
db_execute("REPLACE INTO settings (name,value) VALUES ('$name', '$value')");
}
}

However, this runs whenever the graph page is to be 'recycled', and seems to be overwriting the 'settings' set in the cacti 'settings/cycle' page
(because the values are 'not equal to false'). So, the 'Display legend' checkbox gets set back to its default of null (i.e. don't display the legend).

I've done a quick test by changing this to:

if ($current == false) {

and setting the 'Display Legend' and 'Graph Timespan' values, and they are now displayed as defaults whenever the graph page is visited.
Checking the DB, the values are not changed even if the values on the graph page are.

Not sure if this is the full or correct fix, but it seems to make more sense and seems to work.
User avatar
TheWitness
Developer
Posts: 17007
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

Re: Cycle plugin - legend not working correctly

Post by TheWitness »

Fixed. Version 2.2
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?
jhorne
Posts: 26
Joined: Mon Dec 05, 2011 11:45 am

Re: Cycle plugin - legend not working correctly

Post by jhorne »

Thanks for that (version 2.2), but it does not fix the whole problem.

To demonstrate the problem (the legend checkbox not being maintained correctly), do this:

1) Open a browser and log in to cacti.
2) Go to 'Console->Settings->Cycle'.
3) Check the 'Display Legend' checkbox, and set the 'Graph Timespan' to 'Last Half Hour'.
4) Save the settings.
5) Click on the 'cycle' tab at the top to go to the graphs. The 'Display Legend' checkbox should be checked, and the timespan showing as 'Last Half Hour'.
6) Go back to 'Console->Settings->Cycle', and just click on 'Save' to save the settings again.(Note the 'Display Legend' checkbox should still be checked, you haven't changed that.)
7) Click on the 'cycle' tab at the top to go to the graphs. The 'Display Legend' checkbox is now unchecked!


It's a little convoluted, but demonstrates the point :)

Following the code to see what was going on was a bit difficult, but I think the problem stems from 'cycle.js'. In there it states:

url=... "&legend="+$('#legend:checked').length+"

Now this is going to set '&legend' to either 0 ('Display Legend' is not checked), or 1 (it is checked).

But in 'cycle.php' we have:

<input type="checkbox" id='legend' name='legend' <?php ($legend=="on" ? print
' checked=yes' : "" ); ?> title='Display Graph Legend'>

I have changed this to:

... <?php ($legend=="on" || $legend==1 ? print

and this seems to work (I admit I'm not totally sure why!). The 'Display Legend' checkbox is now correctly checked or unchecked depending on the users session setting, and regardless of whether they change other cycle settings or just re-save the current ones.
jhorne
Posts: 26
Joined: Mon Dec 05, 2011 11:45 am

Re: Cycle plugin - legend not working correctly

Post by jhorne »

As far as I can tell this (and some other things) are now fully fixed in the patched cycle plugin. Patches are in the cacti plugin bug/mantis database.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests