Patch to duplicate data sources with more than one output

Templates, scripts for templates, scripts and requests for templates.

Moderators: Developers, Moderators

Post Reply
met
Posts: 12
Joined: Thu Aug 01, 2002 7:32 am

Patch to duplicate data sources with more than one output

Post by met »

I have modified cacti 0.6.8 in order to allow duplication of multi output
data sources.
To this end I also had to change the behaviour of the editing function for data sources: if you change the name of a data source with multi output, its children will be renamed as if a new data source were created.
I also modified the SQL query which retrieves the list of data sources in order to get the right sorting in spite of different names between a parent data source and its children.
This pacth also fixes a minor bug when copying a graph.

Code: Select all

--- cacti/include/utility_functions.php.org	Tue Jul 30 18:23:19 2002
+++ cacti/include/utility_functions.php	Thu Aug  1 17:09:44 2002
@@ -31,7 +31,8 @@
 	
 	/* duplicate graph defs */
 	mysql_query("insert into rrd_graph (id,imageformatid,title,height,width,upperlimit,
-	lowerlimit,verticallabel,autoscale,autopadding,autoscaleopts,rigid,basevalue,grouping,export) 
+	lowerlimit,verticallabel,autoscale,autopadding,autoscaleopts,rigid,basevalue,grouping,
+	export,unitvalue,unitexponentvalue,autoscalelog) 
 	values (0,
 		" . mysql_result($sql_id, 0, "imageformatid") . ",\"$name\""
 		. "," . mysql_result($sql_id, 0, "height") 
@@ -45,7 +46,10 @@
 		. ",\"" . mysql_result($sql_id, 0, "rigid") . "\""
 		. ",\"" . mysql_result($sql_id, 0, "basevalue") . "\""
 		. ",\"" . mysql_result($sql_id, 0, "grouping") . "\""
-		. ",\"" . mysql_result($sql_id, 0, "export") . "\")", $cnn_id);
+		. ",\"" . mysql_result($sql_id, 0, "export") . "\""
+		. ",\"" . mysql_result($sql_id, 0, "unitvalue") . "\""
+		. ",\"" . mysql_result($sql_id, 0, "unitexponentvalue") . "\""
+		. ",\"" . mysql_result($sql_id, 0, "autoscalelog") . "\")", $cnn_id);
 	
 	$graph_grouping = mysql_result($sql_id, 0, "grouping");
 	
@@ -58,7 +62,8 @@
 	
 	while ($i < $rows) {
 		mysql_query("insert into rrd_graph_item (id,dsid,colorid,textformat,value,sequence,
-			graphid,graphtypeid,consolidationfunction,hardreturn,cdefid,sequenceparent,parent) 
+			graphid,graphtypeid,consolidationfunction,hardreturn,cdefid,sequenceparent,
+			parent,gprintopts,gprintcustom) 
 			values (0" 
 			. ",\"" . mysql_result($sql_id, $i, "dsid") . "\""
 			. ",\"" . mysql_result($sql_id, $i, "colorid") . "\""
@@ -71,7 +76,9 @@
 			. ",\"" . mysql_result($sql_id, $i, "hardreturn") . "\""
 			. ",\"" . mysql_result($sql_id, $i, "cdefid") . "\""
 			. ",\"" . mysql_result($sql_id, $i, "sequenceparent") . "\""
-			. ",\"" . mysql_result($sql_id, $i, "parent") . "\")", $cnn_id);
+			. ",\"" . mysql_result($sql_id, $i, "parent") . "\""
+			. ",\"" . mysql_result($sql_id, $i, "gprintopts") . "\""
+			. ",\"" . mysql_result($sql_id, $i, "gprintcustom") . "\")", $cnn_id);
 		$i++;
 	}
 	
@@ -91,8 +98,10 @@
 	
 	$name = mysql_result($sql_id, 0, "name") . "_copy";
 	/* duplicate data source defs */
-	mysql_query("insert into rrd_ds (id,name,datasourcetypeid,heartbeat,
-		minvalue,maxvalue,srcid,active,dsname,dspath,step) values (0"
+	mysql_query("insert into rrd_ds (id,subdsid,subfieldid,name,datasourcetypeid,heartbeat,
+		minvalue,maxvalue,srcid,active,dsname,dspath,step,isparent) values (0"
+		. ",\"" . mysql_result($sql_id, $i, "subdsid") . "\""
+		. ",\"" . mysql_result($sql_id, $i, "subfieldid") . "\""
 		. ",\"" . $name . "\""
 		. ",\"" . mysql_result($sql_id, $i, "datasourcetypeid") . "\""
 		. ",\"" . mysql_result($sql_id, $i, "heartbeat") . "\""
@@ -100,15 +109,43 @@
 		. ",\"" . mysql_result($sql_id, $i, "maxvalue") . "\""
 		. ",\"" . mysql_result($sql_id, $i, "srcid") . "\""
 		. ",\"" . mysql_result($sql_id, $i, "active") . "\""
-		. ",\"" . mysql_result($sql_id, $i, "dsname") . "\""
+	        . ",\"" . mysql_result($sql_id, $i, "dsname") . "\""
 		. ",\"\""
 		. ",\"" . mysql_result($sql_id, $i, "step") . "\""
+		. ",\"" . mysql_result($sql_id, $i, "isparent") . "\""
 		. ")", $cnn_id);
 	
-	/* duplicate data source data */
+	/* Manca: SubDSID, SubFieldID */
+	
+	/* save id of new Data Source */
 	$sql_id = mysql_query("select LAST_INSERT_ID() as id", $cnn_id);
 	$last_id = mysql_result($sql_id, 0, "id");
+
+	/* duplicate sub Data Source for multi output*/
+	$sql_id = mysql_query("select * from rrd_ds where subdsid=$datasource_id", $cnn_id);
+	$rows = mysql_num_rows($sql_id); $i = 0;
 	
+	while ($i < $rows) {
+	    mysql_query("insert into rrd_ds (id,subdsid,subfieldid,name,datasourcetypeid,heartbeat,
+		    minvalue,maxvalue,srcid,active,dsname,dspath,step,isparent) values (0"
+		    . ",\"" . $last_id . "\""
+		    . ",\"" . mysql_result($sql_id, $i, "subfieldid") . "\""
+		    . ",\"" . mysql_result($sql_id, $i, "name") . "_copy" . "\""
+		    . ",\"" . mysql_result($sql_id, $i, "datasourcetypeid") . "\""
+		    . ",\"" . mysql_result($sql_id, $i, "heartbeat") . "\""
+		    . ",\"" . mysql_result($sql_id, $i, "minvalue") . "\""
+		    . ",\"" . mysql_result($sql_id, $i, "maxvalue") . "\""
+		    . ",\"" . mysql_result($sql_id, $i, "srcid") . "\""
+		    . ",\"" . mysql_result($sql_id, $i, "active") . "\""
+		    . ",\"" . mysql_result($sql_id, $i, "dsname") . "\""
+		    . ",\"\""
+		    . ",\"" . mysql_result($sql_id, $i, "step") . "\""
+		    . ",\"" . mysql_result($sql_id, $i, "isparent") . "\""
+		    . ")", $cnn_id);
+		$i++;
+	}
+	
+	/* duplicate data source data */
 	$sql_id = mysql_query("select * from src_data where dsid=$datasource_id", $cnn_id);
 	$rows = mysql_num_rows($sql_id); $i = 0;
 	
--- cacti/ds.php.org	Wed May  8 20:23:36 2002
+++ cacti/ds.php	Fri Aug  2 13:01:01 2002
@@ -152,12 +152,30 @@
 			}
 			
 			mysql_query("update rrd_ds set isparent=$data_source_is_parent where id=$id", $cnn_id);
-		}
+		}
 elseif ($name != $name_old) {
+			/* Update name for children if necessary */
+
+			$sql_id = mysql_query("select d.id, f.dataname
+				from rrd_ds d inner join src_fields f on (d.subfieldid=f.id)
+				where d.subdsid=$id", $cnn_id);
+			$rows = mysql_num_rows($sql_id); $i = 0;
+
+			if ($rows > 1) {
+				/* Loop through each output and create a sub-data source for the data 
+				source that has just been created */
+				while ($i < $rows) {
+					mysql_query("update rrd_ds 
+						set name=" . "\"$name" . 
"_" . mysql_result($sql_id, $i, "dataname") . "\"
+						where id=" . mysql_result($sql_id, $i, "id"),$cnn_id);
+					$i++;
+				}
+			}
+		}
 		
 		/* this will do any of the cleanup that is required on the data source name to make
 		sure rrdtool is ok with it. */
 		SyncDataSourceName($id, $dsname, $dspath);
-		
+
 		header ("Location: ds.php");
 		break;
 	case 'remove':
@@ -192,6 +210,7 @@
 		if ($id != "") {
 			$sql_id = mysql_query("select * from rrd_ds where id=$id", $cnn_id);
 			
+			$name_old = mysql_result($sql_id, 0, "name");
 			$srcid_old = mysql_result($sql_id, 0, "srcid");
 			$sub_data_source_id = mysql_result($sql_id, 0, "subdsid");
 		}
@@ -234,7 +253,7 @@
 			DrawFormItem("(Optional) Data Source Path","Used only if the data source lies in a different directory; you must include_once the full path to the RRA file.");
 			DrawFormItemTextBox("dspath",$sql_id,"","");
 		}else{
-			DrawFormItemHiddenTextBox("dspath","","");
+			DrawFormItemHiddenTextBox("dspath",$sql_id,"");
 		}
 		
 		if ($sub_data_source_id == 0) {
@@ -300,6 +319,7 @@
 		}
 		
 		DrawFormSaveButton();
+		DrawFormItemHiddenTextBox("name_old",$name_old,"");
 		DrawFormItemHiddenTextBox("srcid_old",$srcid_old,"0");
 		DrawFormItemHiddenTextBox("subdsid_old",$sub_data_source_id,"0");
 		DrawFormItemHiddenIDField("isparent",$sql_id);
@@ -328,10 +348,10 @@
 		
 		$sql_id = mysql_query("select 
 			d.id,d.name,d.datasourcetypeid,d.srcid,d.active,d.subdsid,d.isparent,
-			(d.id=d.subdsid) as sortstr,
-			s.id as sid,s.name as sname 
-			from rrd_ds d left join src s on (d.srcid=s.id)
-			order by sortstr,name", $cnn_id);
+			if(x.id=d.subdsid, concat(x.name,' ',d.name), d.name) as sortstr,
+			s.id as sid,s.name as sname
+			from rrd_ds d left join rrd_ds x on (x.id=d.subdsid) left join src s on (d.srcid=s.id)
+			order by sortstr", $cnn_id);
 		$rows = mysql_num_rows($sql_id); $i = 0;
 		
 		while ($i < $rows) { 
@@ -365,11 +385,7 @@
 				if (mysql_result($sql_id, $i, "subdsid") != 0) {
 					$matrix_url = "";
 				}else{
-					if (mysql_result($sql_id, $i, "isparent") != 0) {
-						$matrix_url = "";
-					}else{
-						$matrix_url = "ds.php?id=" . mysql_result($sql_id, $i, "id") . "&action=duplicate";
-					}
+					$matrix_url = "ds.php?id=" . mysql_result($sql_id, $i, "id") . "&action=duplicate";
 				}
 				
 				DrawMatrixLoopItem("Duplicate","",$i,false,$matrix_url);

fmedico

how to apply this patch (running AIX)

Post by fmedico »

Thanks to describe how to patch cacti using your patch ...
I am not familliar with patch command and I am running AIX.

you could maybe send me the files directly.

Thanks in advance.

fmedico@yahoo.com
oclashing
Posts: 1
Joined: Thu Dec 12, 2002 7:20 pm
Location: Jamaica

Need help with patch also

Post by oclashing »

Would it be possible for you to send the patch also?

Owen

oclashing@hotmail.com
Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests