Cacti (home)ForumsRepositoryDocumentation
Cacti: offical forums and support  

 FAQFAQ   SearchSearch   MemberlistMemberlist    RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in    


[SOLVED] More variable support for graph templates

 
Post new topic   Reply to topic    Cacti Forum Index -> Feature Requests
Author Message
cricalix



Joined: 22 Jan 2007
Posts: 9

PostPosted: Tue Feb 13, 2007 7:19 am    Post subject: [SOLVED] More variable support for graph templates Reply with quote

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
Back to top
TheWitness
Developer


Joined: 14 May 2002
Posts: 9723
Location: MI, USA

PostPosted: Tue Feb 13, 2007 8:25 am    Post subject: Reply with quote

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
Back to top
cricalix



Joined: 22 Jan 2007
Posts: 9

PostPosted: Wed Feb 14, 2007 5:46 am    Post subject: Solved :) Reply with quote

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:
include_once($config["base_path"] . "/lib/rrd.php");


2) Added to the -new- line 799 of lib/rrd.php:
Code:
$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?



graph_image.php.png
 Description:
Using host_hostname in the legend.
 Filesize:  8.05 KB
 Viewed:  2960 Time(s)

graph_image.php.png


Back to top
TheWitness
Developer


Joined: 14 May 2002
Posts: 9723
Location: MI, USA

PostPosted: Sat Feb 17, 2007 9:57 pm    Post subject: Reply with quote

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.
Back to top
cricalix



Joined: 22 Jan 2007
Posts: 9

PostPosted: Sun Feb 18, 2007 4:55 am    Post subject: Reply with quote

Ticket 925 has been created
Back to top
disirk



Joined: 11 Sep 2006
Posts: 12
Location: Atlanta, GA

PostPosted: Tue Feb 20, 2007 1:40 pm    Post subject: Include more data... Reply with quote

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:
$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:
$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:
include_once($config["base_path"] . "/lib/rrd.php");
was not needed for me *shrug*
Back to top
cricalix



Joined: 22 Jan 2007
Posts: 9

PostPosted: Tue Feb 20, 2007 3:00 pm    Post subject: Reply with quote

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...
Back to top
TheWitness
Developer


Joined: 14 May 2002
Posts: 9723
Location: MI, USA

PostPosted: Sun Feb 25, 2007 4:44 pm    Post subject: Reply with quote

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



rrd.zip
 Description:
With Plugin Architecture (v1.1)

Download
 Filename:  rrd.zip
 Filesize:  11.54 KB
 Downloaded:  196 Time(s)


rrd.zip
 Description:
W/O Plugin Architecture

Download
 Filename:  rrd.zip
 Filesize:  11.38 KB
 Downloaded:  192 Time(s)

Back to top
gandalf
Developer


Joined: 02 Dec 2004
Posts: 12295
Location: Muenster, Germany

PostPosted: Mon Feb 04, 2008 10:38 am    Post subject: Reply with quote

Now available for upper/lower limit. At least in SVN
Reinhard
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Cacti Forum Index -> Feature Requests All times are GMT - 5 Hours
Page 1 of 1

 



Powered by phpBB © 2001, 2005 phpBB Group