From: Florian G. <re...@us...> - 2007-06-15 23:34:35
|
Update of /cvsroot/perfparse/_perfparse-phpgui In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27476/phpgui Modified Files: perfparse.php utils.php Log Message: saving graphs another way Index: utils.php =================================================================== RCS file: /cvsroot/perfparse/_perfparse-phpgui/utils.php,v retrieving revision 1.37 retrieving revision 1.38 diff -C2 -d -r1.37 -r1.38 *** utils.php 6 Jun 2007 13:08:31 -0000 1.37 --- utils.php 15 Jun 2007 23:34:30 -0000 1.38 *************** *** 576,583 **** } ! function save_graph(&$db,$group_name,$title,$descript,$url) { ! $query='insert into perfdata_graphs (group_name,title,descript,url) '; ! $query.='values (?,?,?,?)'; ! if(!$db->Execute($query,array($group_name,$title,$descript,$url))) { echo "Error saving graph: ".$db->ErrorMsg(); } --- 576,631 ---- } ! function save_graph(&$db,$grapharray) { ! // echo "<pre>in utils: save_graph. grapharray: \n";print_r($grapharray);echo "</pre>"; ! ! $query='insert into perfdata_graphs (title,descript,refresh_time,metric_id,scale,minin,maxin,timerange,'; ! $query.='relativetime,fromtime,totime,output,sizex,sizey,s_val,s_war,s_cri,s_sta,graphtitle,g_sigma) '; ! $query.='values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)'; ! $bindarray=array($grapharray['graph_name'],$grapharray['desc'],$grapharray['refresh_time'],$grapharray['metric_id'], ! $grapharray['scale'],$grapharray['minin'],$grapharray['maxin'],$grapharray['timerange']); ! if($grapharray['timerange'] =='r') { ! list($relhours,$relmins) = split(':',$grapharray['relativetime'],2); ! $bindarray[]=24*3600*(int) $grapharray['relativedays'] + 3600*(int) $relhours +60* (int) $relmins; // time in seconds ! $bindarray[]=0; ! $bindarray[]=0; ! } else { ! $bindarray[]=0; ! $bindarray[]=strtotime($grapharray['from']); ! $bindarray[]=strtotime($grapharray['to']); ! } ! ! switch ($grapharray['output']) { ! case 'Histogram': ! $bindarray[]='h'; ! break; ! case 'Average': ! $bindarray[]='a'; ! break; ! case 'Diff': ! $bindarray[]='d'; ! break; ! case 'Int': ! $bindarray[]='i'; ! break; ! default: ! $bindarray[]=''; ! } ! ! list($sizex,$sizey)=split('x',$grapharray['size'],2); ! $bindarray[]=$sizex; ! $bindarray[]=$sizey; ! ! //s_val,s_war,s_cri,s_sta,graphtitle,g_sigma ! ! $bindarray[]=$grapharray['s_val']; ! $bindarray[]=$grapharray['s_war']; ! $bindarray[]=$grapharray['s_cri']; ! $bindarray[]=$grapharray['s_sta']; ! $bindarray[]=$grapharray['title']; ! $bindarray[]=$grapharray['g_sigma']; ! ! ! // echo "<pre>q:\n$query\n";print_r($bindarray);echo "</pre>"; ! if(!$db->Execute($query,$bindarray)) { echo "Error saving graph: ".$db->ErrorMsg(); } Index: perfparse.php =================================================================== RCS file: /cvsroot/perfparse/_perfparse-phpgui/perfparse.php,v retrieving revision 1.49 retrieving revision 1.50 diff -C2 -d -r1.49 -r1.50 *** perfparse.php 12 Jun 2007 15:11:09 -0000 1.49 --- perfparse.php 15 Jun 2007 23:34:30 -0000 1.50 *************** *** 216,219 **** --- 216,222 ---- $numgraphs=0; + get_request_var('save_graph_metric_id','array'); + + if(get_request_var('graphs','array')) { // echo "<pre>\ngraphs from Request:\n";print_r($graphs); echo "</pre>"; *************** *** 241,248 **** $actgraph['unit']=$tmparr['unit']; // id is for making input fields uniq $id=md5($host_name.$service.$metric); $actgraph['id']=$id; $deftitle='Host \''.$host_name.'\' Service \''.$service.'\' Metric \''.$metric.'\''; ! $actgraph['title']=$deftitle; // get_request_var(variable, type, default value) // check_setdefault(variable, type, default value) --- 244,255 ---- $actgraph['unit']=$tmparr['unit']; // id is for making input fields uniq + // -- not needed any more? use metric_ids? $id=md5($host_name.$service.$metric); $actgraph['id']=$id; + $actgraph['metric_id']=$metric_id; $deftitle='Host \''.$host_name.'\' Service \''.$service.'\' Metric \''.$metric.'\''; ! if(!isset($actgraph['title'])) { ! $actgraph['title']=$deftitle; ! } // get_request_var(variable, type, default value) // check_setdefault(variable, type, default value) *************** *** 329,332 **** --- 336,344 ---- $actgraph['url'].='&title='.urlencode($actgraph['title']); + // handle saving graphs here + if(isset($save_graph_metric_id[$metric_id])) { + save_graph($db,$actgraph); // todo: error handling and feedback to user + } + } else { // if(have_service_metric ... // should we write a error message??? *************** *** 344,351 **** $smarty->assign_by_ref('displaygraphs',$displaygraphs); - // handle saving graph - if(isset($_REQUEST['save_graph'])) { - save_graph($db,NULL /*todo: handle group*/,$graph_name,$title,$url); - } $smarty->display($config['PHP_Style'].'graph.tpl.html'); } else { --- 356,359 ---- |