1 --- cacti/lib/functions.php 2007/11/16 03:33:22 4350
2 +++ cacti/lib/functions.php 2007/11/19 02:21:59 4351
3 @@ -1077,27 +1077,19 @@
4 @returns - the best cf to use */
5 function generate_graph_best_cf($local_data_id, $requested_cf) {
6 if ($local_data_id > 0) {
7 - $avail_cf_functions = db_fetch_assoc("SELECT DISTINCT
8 - rra_cf.consolidation_function_id AS rra_cf
9 - FROM (data_template_data
10 - INNER JOIN data_template_data_rra ON data_template_data.id=data_template_data_rra.data_template_data_id)
11 - INNER JOIN (rra INNER JOIN rra_cf ON rra.id=rra_cf.rra_id) ON data_template_data_rra.rra_id=rra.id
12 - WHERE data_template_data.local_data_id=$local_data_id
13 - ORDER BY rra_cf ASC");
14 + $avail_cf_functions = get_rrd_cfs($local_data_id);
16 /* workaround until we hae RRA presets in 0.8.8 */
17 - if ($requested_cf != 4) {
18 - if (sizeof($avail_cf_functions)) {
19 - /* check through the cf's and get the best */
20 - foreach($avail_cf_functions as $cf) {
21 - if ($cf["rra_cf"] == $requested_cf) {
22 - return $requested_cf;
24 + if (sizeof($avail_cf_functions)) {
25 + /* check through the cf's and get the best */
26 + foreach($avail_cf_functions as $cf) {
27 + if ($cf["rra_cf"] == $requested_cf) {
28 + return $requested_cf;
31 - /* if none was found, take the first */
32 - return $avail_cf_functions[0]["rra_cf"];
35 + /* if none was found, take the first */
36 + return $avail_cf_functions[0]["rra_cf"];
40 @@ -1105,6 +1097,66 @@
44 +/* get_rrd_cfs - reads the RRDfile and get's the RRA's stored in it.
46 + @returns - array of the CF functions */
47 +function get_rrd_cfs($local_data_id) {
50 + $rrdfile = get_data_source_path($local_data_id, TRUE);
52 + if (!isset($rrd_cfs)) {
54 + }else if (array_key_exists($local_data_id, $rrd_cfs)) {
55 + return $rrd_cfs[$local_data_id];
60 + $output = rrdtool_execute("info $rrdfile", FALSE, RRDTOOL_OUTPUT_STDOUT);
62 + if (strlen($output)) {
63 + $output = explode("\n", $output);
65 + if (sizeof($output)) {
66 + foreach($output as $line) {
67 + if (substr_count($line, ".cf")) {
68 + $values = explode("=",$line);
70 + if (!in_array(trim($values[1]), $cfs)) {
71 + $cfs[] = trim($values[1]);
81 + foreach($cfs as $cf) {
99 + $rrd_cfs[$local_data_id] = $new_cfs;
104 /* generate_graph_def_name - takes a number and turns each digit into its letter-based
105 counterpart for RRDTool DEF names (ex 1 -> a, 2 -> b, etc)
106 @arg $graph_item_id - (int) the ID to generate a letter-based representation of