Cacti: Write value of GPRINT text bold/bigger

Linux howto's, compile information, information on whatever we learned on working with linux, MACOs and - of course - Products of the big evil....
Post Reply
User avatar
^rooker
Site Admin
Posts: 1483
Joined: Fri Aug 29, 2003 8:39 pm

Cacti: Write value of GPRINT text bold/bigger

Post by ^rooker »

[PROBLEM]
I'm using Cacti to generate RRDTool graphs from SNMP values.
RRDTool is very powerful, and Cacti does a good job at providing a comfortable GUI for configuring these graphs.
Unfortunately, this means that some features RRDTool is able to handle, can't be used/configured using Cacti.

I wanted to have the currently measured value displayed within the graph.
In Cacti's "Graph Template" you can use the field "Text Format" for this, with the following settings:

Code: Select all

Data Source: None
Color: None
Graph Item Type: GPRINT
Consolidation Function: LAST
CDEF Function: None
GPRINT Type: Normal
For "Text Format" just enter the string to be used as label for the current (=LAST) value.
Unfortunately, there's no way of using RRDTool's advanced text formatting options (as listed in RRDTool's documentation)
Some common ones listed in the docs are:
b Bold
big Makes font relatively larger, equivalent to <span size="larger">
i Italic
s Strikethrough
sub Subscript
sup Superscript
small Makes font relatively smaller, equivalent to <span size="smaller">
tt Monospace font
u Underline
And that's exactly what I wanted to use.

[SOLUTION]
Unfortunately, in the current version of Cacti, this requires a patch to "lib/rrd.php"

Code: Select all

867d866
<         "--pango-markup" . RRD_NL .
1364c1363
<           $txt_graph_items .= $graph_item_types{$graph_item["graph_type_id"]} . ":" . $data_source_name . ":" . $consolidation_functions{$graph_item["consolidation_function_id"]} . ":\"$text_padding" . $graph_variables["text_format"][$graph_item_id] ."<big>". $graph_item["gprint_text"] ."</big>". $hardreturn[$graph_item_id] . "\" ";
---
>           $txt_graph_items .= $graph_item_types{$graph_item["graph_type_id"]} . ":" . $data_source_name . ":" . $consolidation_functions{$graph_item["consolidation_function_id"]} . ":\"$text_padding" . $graph_variables["text_format"][$graph_item_id] . $graph_item["gprint_text"] . $hardreturn[$graph_item_id] . "\" ";
All I've done was to wrap (=hardcoded! yikes) the html tags "<big>" around the variable called $graph_item["gprint_text"]. Now all values displayed using the "GPRINT+Text Format" fields in Cacti will be formatted like this.

I know it's an ugly hack and I apologize for it.
However, in my case it saved the day ;)
Jumping out of an airplane is not a basic instinct. Neither is breathing underwater. But put the two together and you're traveling through space!
Post Reply