[SOLVED] More variable support for graph templates

Anything that you think should be in Cacti.

Moderators: Developers, Moderators

Post Reply
cricalix
Posts: 9
Joined: Mon Jan 22, 2007 9:26 am

[SOLVED] More variable support for graph templates

Post by cricalix »

At the moment, the host_* variables can be used in the title of the graphs, which is nice. However, I'd like to be able to fit some of that information in a COMMENT field on the graph, so that the title of the graph doesn't exceed the boundaries of the graph container.

I can do legend values like:
Out 95%: |95:bits:1:max:0|

I'd like to do things like
Host: |host_hostname|

leaving the title with the |host_description| and the graph type. I've tried digging through the source code, but can't determine how to run the substitute_host_data function against the RRD legend stuff. Pointers on where I might find it would be appreciated too :)
User avatar
TheWitness
Developer
Posts: 17047
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

Post by TheWitness »

I think if you goto the top of include/config_constants.php or include/config_arrays.php, you will start to understand. There is an array that includes the viable "special use" ones. Follow that array around and you may start to understand.

TheWitness
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?
cricalix
Posts: 9
Joined: Mon Jan 22, 2007 9:26 am

Solved :)

Post by cricalix »

Well, I don't think this is the cleanest processing method, but maybe it is.

I found that graph titles are stored in SQL as the pipe-variable template string, and the substituted string. However, I didn't see the equivalent storage for the RRD legend stuff. This makes sense, as the legend data is changed on generation.

Tracing the text_format variable from include/config_form.php, I found references in rrd.php, which made sense.

Two changes were made to rrd.php to support the host_* variables:
1) Added to line 29 of lib/rrd.php:

Code: Select all

include_once($config["base_path"] . "/lib/rrd.php");
2) Added to the -new- line 799 of lib/rrd.php:

Code: Select all

$graph_item["text_format"] = substitute_host_data($graph_item["text_format"],  '|','|', $graph["host_id"]);
Really and truly, the second modification should only be run when the legend type is COMMENT, to cut down the processing overhead. A quick test around line 1088 didn't work, and I'm not inclined to poke it any further today.

Oh, the critical part - this was version 0.8.6j. Tried to find that in about.php and it wasn't there :p

Thanks for the hint TheWitness - don't suppose this might make it into .9? :)
Attachments
Using host_hostname in the legend.
Using host_hostname in the legend.
graph_image.php.png (8.05 KiB) Viewed 6810 times
User avatar
TheWitness
Developer
Posts: 17047
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

Post by TheWitness »

Please log this as a feature request at bugs.cacti.net. Include a link to this post in that bug report and then reply here to let me know it's there.

Thanks,

TheWitness

ps. Monday is Cacti day for me this week.
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?
cricalix
Posts: 9
Joined: Mon Jan 22, 2007 9:26 am

Post by cricalix »

Ticket 925 has been created :)
User avatar
disirk
Posts: 12
Joined: Mon Sep 11, 2006 3:26 pm
Location: Atlanta, GA

Include more data...

Post by disirk »

If you use the following in your rrd.php you can add not only the host_* variables, but all snmp_queries as well.

At line 1035ish replace:

Code: Select all

$txt_graph_items .= $graph_item_types{$graph_item["graph_type_id"]} . ":\"" . str_replace(":", "\:", $graph_variables["text_format"][$graph_item_id]) . $hardreturn[$graph_item_id] . "\" ";
With the following:

Code: Select all

$txt_graph_items .= $graph_item_types{$graph_item["graph_type_id"]} . ":\"" . expand_title($graph["host_id"],$graph["snmp_query_id"],$graph["snmp_index"],str_replace(":", "\:", $graph_variables["text_format"][$graph_item_id])) . $hardreturn[$graph_item_id] . "\" ";
This calls the same function that allows you to do the variables in your title...just add the variables in your comments...and bam! The only thing I need to work on now is centering the information and maybe have the font's be a different size.

*NOTE: The line

Code: Select all

include_once($config["base_path"] . "/lib/rrd.php");
was not needed for me *shrug*
cricalix
Posts: 9
Joined: Mon Jan 22, 2007 9:26 am

Post by cricalix »

Yeah, now that I think about it, requiring itself makes no sense. Wonder why I did that, or if I was editing a different file...
User avatar
TheWitness
Developer
Posts: 17047
Joined: Tue May 14, 2002 5:08 pm
Location: MI, USA
Contact:

Post by TheWitness »

If you are not running the Plugin Architecture, please try the attached lib/rrd.php for comparison. This addresses query replacement in CDEF, and COMMENT.

TheWitness
Attachments
rrd.zip
W/O Plugin Architecture
(11.38 KiB) Downloaded 373 times
rrd.zip
With Plugin Architecture (v1.1)
(11.54 KiB) Downloaded 389 times
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?
User avatar
gandalf
Developer
Posts: 22383
Joined: Thu Dec 02, 2004 2:46 am
Location: Muenster, Germany
Contact:

Post by gandalf »

Now available for upper/lower limit. At least in SVN
Reinhard
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests