From: Florian G. <re...@us...> - 2007-09-03 22:56:25
|
Update of /cvsroot/perfparse/_perfparse-phpgui In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7522/phpgui Modified Files: Makefile.am Makefile.in perfparse.php utils.php Log Message: again changed db schema slightly and start work on del policies settings ui pages. Index: utils.php =================================================================== RCS file: /cvsroot/perfparse/_perfparse-phpgui/utils.php,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** utils.php 12 Aug 2007 00:11:45 -0000 1.40 --- utils.php 3 Sep 2007 22:56:25 -0000 1.41 *************** *** 521,524 **** --- 521,544 ---- } + function get_delete_policy_parsed(&$db,$id) { + $policyinfo=get_delete_policy($db,$id); + $s=$policyinfo['delete_policy_seconds']; + if($s<0) { // infinity + $policyinfo['policy_seconds']=-1; + $policyinfo['policy_minutes']=0; + $policyinfo['policy_hours']=0; + $policyinfo['policy_days']=0; + return($policyinfo); + } + $policyinfo['policy_seconds']=$s%60; + $s=floor($s/60); + $policyinfo['policy_minutes']=$s%60; + $s=floor($s/60); + $policyinfo['policy_hours']=$s%24; + $policyinfo['policy_days']=floor($s/24); + return($policyinfo); + } + + function create_delete_policy(&$db,$policy,$seconds,$comment='') { *************** *** 529,532 **** --- 549,559 ---- } + function set_delete_policy_seconds(&$db,$id,$seconds) { + $query='update perfdata_delete_policy set + delete_policy_seconds=? where policy_id=?'; + $db->Execute($query,array($seconds,$id)); + return($db->ErrorNo()); + } + function edit_delete_policy(&$db,$id,$policy,$seconds,$comment='') { $query='update perfdata_delete_policy set *************** *** 543,546 **** --- 570,639 ---- } + function get_policy_time_from_request($d,$h,$m,$s) { + // in cases where policy is changed in ui + get_request_var($d,'int',0); + get_request_var($h,'int',0); + get_request_var($m,'int',0); + get_request_var($s,'int',0); + global $$d; + global $$h; + global $$m; + global $$s; + return($$s + 60*$$m + 3600*$$h + 86400*$$d); + } + + function get_effective_bin_del_policy(&$db,$metric_id) { + // todo: cache information + + // if policy set in metric + $query='select bin_delete_policy_individual,policy_name,delete_policy_seconds from perfdata_service_metric + left join perfdata_delete_policy on bin_delete_policy_id=policy_id where metric_id=?'; + if(!$res=$db->GetRow($query,array($metric_id))) { + return(FALSE); + } + if($res['bin_delete_policy_individual']!==NULL) { + return(array('source'=>'Individual','policy_seconds'=>$res['bin_delete_policy_individual'])); + } + if($res['policy_name']!==NULL) { + return(array('source'=>'Metric Policy','policy_name'=>$res['policy_name'],'policy_seconds'=>$res['delete_policy_seconds'])); + } + + // if policy set in host + $query='select h.host_id,h.bin_delete_policy_individual,d.policy_name,d.delete_policy_seconds from + perfdata_service_metric m, perfdata_service s, perfdata_host h left join + perfdata_delete_policy d on h.bin_delete_policy_id=d.policy_id where m.metric_id=? + and s.service_id=m.service_id + and s.host_id=h.host_id'; + if(!$res=$db->GetRow($query,array($metric_id))) { + return(FALSE); + } + if($res['bin_delete_policy_individual']!==NULL) { + return(array('source'=>'Host Individual','policy_seconds'=>$res['bin_delete_policy_individual'])); + } + if($res['policy_name']!==NULL) { + return(array('source'=>'Host Policy','policy_name'=>$res['policy_name'],'policy_seconds'=>$res['delete_policy_seconds'])); + } + $tmp_hostid=$res['host_id']; + + // if policy is set in group. If more than one group match, then the group with the longest policy matches. + // Individual settings match first. + $query='select g.bin_delete_policy_individual,d.policy_name,d.delete_policy_seconds + from perfdata_host h, perfdata_host_groups gh, + perfdata_groups g left join perfdata_delete_policy d on + g.bin_delete_policy_id=d.policy_id + where h.host_id=? and h.host_id=hg.host_id and hg.group_id=g.group_id'; + if(!$res=$db->GetAll($query,array($tmp_hostid))) { + return(FALSE); + } + + print_r($res); + + + + } + + + /* graph functions */ + function get_graph_details(&$db,$id) { $query='SELECT * from perfdata_graphs where id=?'; Index: Makefile.in =================================================================== RCS file: /cvsroot/perfparse/_perfparse-phpgui/Makefile.in,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** Makefile.in 2 Aug 2007 22:20:22 -0000 1.11 --- Makefile.in 3 Sep 2007 22:56:25 -0000 1.12 *************** *** 282,285 **** --- 282,286 ---- templates/select_host.tpl.html \ templates/edit_delete_policies.tpl.html \ + templates/edit_default_delete_policies.tpl.html \ templates/edit_host_list.tpl.html \ templates/select_metric.tpl.html \ Index: Makefile.am =================================================================== RCS file: /cvsroot/perfparse/_perfparse-phpgui/Makefile.am,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Makefile.am 29 Dec 2006 00:27:06 -0000 1.5 --- Makefile.am 3 Sep 2007 22:56:25 -0000 1.6 *************** *** 34,37 **** --- 34,38 ---- templates/select_host.tpl.html \ templates/edit_delete_policies.tpl.html \ + templates/edit_default_delete_policies.tpl.html \ templates/edit_host_list.tpl.html \ templates/select_metric.tpl.html \ Index: perfparse.php =================================================================== RCS file: /cvsroot/perfparse/_perfparse-phpgui/perfparse.php,v retrieving revision 1.52 retrieving revision 1.53 diff -C2 -d -r1.52 -r1.53 *** perfparse.php 12 Aug 2007 00:11:45 -0000 1.52 --- perfparse.php 3 Sep 2007 22:56:25 -0000 1.53 *************** *** 140,143 **** --- 140,145 ---- // this switch - case does page specific tasks and loads the template. switch ($page) { + + case 'select_host': // get_hosts is defined in utils.php *************** *** 150,153 **** --- 152,156 ---- break; + case 'select_metric': // get host array *************** *** 203,206 **** --- 206,211 ---- break; + + case 'graph': // for the uri *************** *** 367,370 **** --- 372,377 ---- } break; + + case 'all_bin': case 'all_raw': *************** *** 392,395 **** --- 399,404 ---- $smarty->display($config['PHP_Style'].$page.'.tpl.html'); break; + + case 'raw_history': case 'raw_history_summary': *************** *** 427,430 **** --- 436,441 ---- $smarty->display($config['PHP_Style'].$page.'.tpl.html'); break; + + case 'add_amend_host_group': if(isset($_REQUEST['delete'])) { *************** *** 447,450 **** --- 458,463 ---- $smarty->display($config['PHP_Style'].$_REQUEST['page'].'.tpl.html'); break; + + case 'edit_host_list': get_request_var('group_id','int',''); *************** *** 482,485 **** --- 495,500 ---- $smarty->display($config['PHP_Style'].$_REQUEST['page'].'.tpl.html'); break; + + case 'saved_graphs': // group selection first (newer cgi version) *************** *** 516,519 **** --- 531,536 ---- $smarty->display($config['PHP_Style'].$_REQUEST['page'].'.tpl.html'); break; + + case 'edit_delete_policies': // handle create or edit policy template: *************** *** 521,545 **** get_request_var('create_policy','string',''); if(empty($create_policy) && $edit_policy != false) { ! $epolicy=get_delete_policy($db,$edit_policy); ! $s=$epolicy['delete_policy_seconds']; ! $epolicy['policy_seconds']=$s%60; ! $s=floor($s/60); ! $epolicy['policy_minutes']=$s%60; ! $s=floor($s/60); ! $epolicy['policy_hours']=$s%24; ! $epolicy['policy_days']=floor($s/24); $smarty->assign_by_ref('epolicy',$epolicy); // echo "epolicy:<pre>";print_r($epolicy);echo "</pre>"; $smarty->assign('edit_policy',$edit_policy); } elseif(!empty($create_policy)) { get_request_var('create_policy_comment','string',''); - get_request_var('create_policy_days','int',0); - get_request_var('create_policy_hours','int',0); - get_request_var('create_policy_minutes','int',0); - get_request_var('create_policy_seconds','int',0); - $create_policy_seconds=$create_policy_seconds+ - 60*$create_policy_minutes+ - 3600*$create_policy_hours+ - 86400*$create_policy_days; if($edit_policy != false) { // policy was edited --- 538,548 ---- get_request_var('create_policy','string',''); if(empty($create_policy) && $edit_policy != false) { ! $epolicy=get_delete_policy_parsed($db,$edit_policy); $smarty->assign_by_ref('epolicy',$epolicy); // echo "epolicy:<pre>";print_r($epolicy);echo "</pre>"; $smarty->assign('edit_policy',$edit_policy); } elseif(!empty($create_policy)) { + $create_policy_seconds=get_policy_time_from_request('create_policy_days','create_policy_hours','create_policy_minutes','create_policy_seconds'); get_request_var('create_policy_comment','string',''); if($edit_policy != false) { // policy was edited *************** *** 572,575 **** --- 575,643 ---- $smarty->display($config['PHP_Style'].$_REQUEST['page'].'.tpl.html'); break; + + + case 'edit_default_delete_policies': + $def_bin_policy_seconds=get_policy_time_from_request('def_bin_policy_days','def_bin_policy_hours', + 'def_bin_policy_minutes','def_bin_policy_seconds'); + $def_raw_policy_seconds=get_policy_time_from_request('def_raw_policy_days','def_raw_policy_hours', + 'def_raw_policy_minutes','def_raw_policy_seconds'); + $bin_policy=get_delete_policy_parsed($db,0); + $smarty->assign_by_ref('bin_policy',$bin_policy); + $raw_policy=get_delete_policy_parsed($db,1); + $smarty->assign_by_ref('raw_policy',$raw_policy); + + // print_r($bin_policy); + // echo "<br />$def_bin_policy_seconds<br />"; + + get_request_var('edited','int',FALSE); + echo "edited=$edited"; + if($edited) { + if($def_bin_policy_seconds != $bin_policy['delete_policy_seconds']) { + if(!set_delete_policy_seconds($db,0,$def_bin_policy_seconds)) { + $smarty->assign('sql_error',$db->ErrorMsg()); + } + $bin_policy=get_delete_policy_parsed($db,0); //refetch for display + } + if($def_raw_policy_seconds != $raw_policy['delete_policy_seconds']) { + if(!set_delete_policy_seconds($db,1,$def_raw_policy_seconds)) { + $smarty->assign('sql_error',$db->ErrorMsg()); + } + $raw_policy=get_delete_policy_parsed($db,1); //refetch for display + } + } + $smarty->display($config['PHP_Style'].$_REQUEST['page'].'.tpl.html'); + break; + + + case 'show_effective_del_policies': + // get all needed object names and ids + $groupinfos=get_groups($db); + get_request_var('group_id','int',FALSE); + if($group_id != FALSE) { + $hostinfos=get_groupId_hostinfos($db,$group_id); + } + + get_request_var('host_id','int',FALSE); + if($host_id != FALSE) { + $metricsinfos=get_metrics_from_hostid($db,$host_id); + } + + echo "<pre>groupinfos:\n"; print_r($groupinfos); echo "\n</pre>"; + echo "<pre>hostinfos:\n"; print_r($hostinfos); echo "\n</pre>"; + echo "<pre>metricsinfos:\n"; print_r($metricsinfos); echo "\n</pre>"; + + if($effectivepolicy=get_effective_bin_del_policy($db,1/* testing */)==FALSE) { + $smarty->assign('sql_error',$db->ErrorMsg); + //debug: + echo $db->ErrorMsg; + } + + echo "<pre>effectivepolicy:\n"; print_r($effectivepolicy); echo "\n</pre>"; + + + $smarty->display($config['PHP_Style'].$_REQUEST['page'].'.tpl.html'); + break; + + case 'read_nag_config': // load modified naupy class |