diff options
| author | osmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2006-07-18 13:20:33 +0000 |
|---|---|---|
| committer | osmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2006-07-18 13:20:33 +0000 |
| commit | def2e0a7def21050b352556ceb7c31cea4ebbb1c (patch) | |
| tree | 16e811bda782fde81debd4199f2015fcdb103836 /frontends/php/include | |
| parent | 125d97877ec6846cd8be946eb786621e3debec81 (diff) | |
- developed template unlinking feature (Eugene)
git-svn-id: svn://svn.zabbix.com/trunk@3057 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php/include')
| -rw-r--r-- | frontends/php/include/classes/cbutton.inc.php | 17 | ||||
| -rw-r--r-- | frontends/php/include/forms.inc.php | 37 | ||||
| -rw-r--r-- | frontends/php/include/graphs.inc.php | 48 | ||||
| -rw-r--r-- | frontends/php/include/hosts.inc.php | 94 | ||||
| -rw-r--r-- | frontends/php/include/items.inc.php | 29 | ||||
| -rw-r--r-- | frontends/php/include/locales/en_gb.inc.php | 2 | ||||
| -rw-r--r-- | frontends/php/include/triggers.inc.php | 52 |
7 files changed, 214 insertions, 65 deletions
diff --git a/frontends/php/include/classes/cbutton.inc.php b/frontends/php/include/classes/cbutton.inc.php index fd060619..22104147 100644 --- a/frontends/php/include/classes/cbutton.inc.php +++ b/frontends/php/include/classes/cbutton.inc.php @@ -70,13 +70,22 @@ } } - class CButtonDelete extends CButton + class CButtonDelete extends CButtonQMessage + { + function CButtonDelete($msg=NULL, $vars=NULL){ + parent::CButtonQMessage("delete",S_DELETE,$msg,$vars); + } + } + + class CButtonQMessage extends CButton { var $vars; var $msg; + var $name; - function CButtonDelete($msg=NULL, $vars=NULL){ - parent::CButton("delete",S_DELETE); + function CButtonQMessage($name, $caption, $msg=NULL, $vars=NULL){ + $this->name = $name; + parent::CButton($name,$caption); $this->SetMessage($msg); $this->SetVars($vars); } @@ -104,7 +113,7 @@ global $page; $confirmation = "Confirm('".$this->msg."')"; - $redirect = "Redirect('".$page["file"]."?delete=1".$this->vars."')"; + $redirect = "Redirect('".$page["file"]."?".$this->name."=1".$this->vars."')"; return parent::SetAction("if(".$confirmation.") return ".$redirect."; else return false;"); } diff --git a/frontends/php/include/forms.inc.php b/frontends/php/include/forms.inc.php index ab210be8..870e016f 100644 --- a/frontends/php/include/forms.inc.php +++ b/frontends/php/include/forms.inc.php @@ -2019,10 +2019,12 @@ $location = get_request("location",""); $notes = get_request("notes",""); - $templateid= get_request("templateid",0); + $templateid = get_request("templateid",0); $frm_title = $show_only_tmp ? S_TEMPLATE : S_HOST; - if(isset($_REQUEST["hostid"])){ + + if(isset($_REQUEST["hostid"])) + { $db_host=get_host_by_hostid($_REQUEST["hostid"]); $frm_title .= SPACE."\"".$db_host["host"]."\""; } @@ -2066,6 +2068,12 @@ $notes = $db_profile["notes"]; } } + $real_templateid = 0; + if(isset($db_host) && $db_host["templateid"] > 0) + { + $real_templateid = $templateid = $db_host["templateid"]; + } + if($show_only_tmp){ $useip = "no"; } @@ -2138,6 +2146,16 @@ } $cmbHosts = new CComboBox("templateid",$templateid); + $btnUnlink = null; + $btnUnlinkAndClear = null; + if($real_templateid > 0) + { + $cmbHosts->SetEnabled(false); + $frmHost->AddVar("templateid",$templateid); + $btnUnlink = new CButton("unlink",S_UNLINK); + $btnUnlinkAndClear = new CButton("unlink_and_clear",S_UNLINK_AND_CLEAR); + } + $cmbHosts->AddItem(0,"..."); $hosts=DBselect("select host,hostid from hosts where status in (".HOST_STATUS_TEMPLATE.")". " order by host"); @@ -2145,7 +2163,7 @@ { $cmbHosts->AddItem($host["hostid"],$host["host"]); } - $frmHost->AddRow(S_LINK_WITH_TEMPLATE,$cmbHosts); + $frmHost->AddRow(S_LINK_WITH_TEMPLATE, array($cmbHosts,SPACE, $btnUnlink, $btnUnlinkAndClear)); if($show_only_tmp) { @@ -2197,6 +2215,19 @@ url_param("groupid") ) ); + + if($show_only_tmp) + { + $frmHost->AddItemToBottomRow(SPACE); + $frmHost->AddItemToBottomRow( + new CButtonQMessage('delete_and_clear', + 'Delete and clear', + S_DELETE_SELECTED_HOSTS_Q, + url_param("form").url_param("config").url_param("hostid"). + url_param("groupid") + ) + ); + } } $frmHost->AddItemToBottomRow(SPACE); $frmHost->AddItemToBottomRow(new CButtonCancel(url_param("config").url_param("groupid"))); diff --git a/frontends/php/include/graphs.inc.php b/frontends/php/include/graphs.inc.php index 5c0f09fa..6f5c00f6 100644 --- a/frontends/php/include/graphs.inc.php +++ b/frontends/php/include/graphs.inc.php @@ -439,32 +439,58 @@ return $result; } - function delete_template_graphs_by_hostid($hostid) + function delete_template_graphs($hostid, $templateid = null, $unlink_mode = false) { $db_graphs = get_graphs_by_hostid($hostid); while($db_graph = DBfetch($db_graphs)) { - if($db_graph["templateid"] == 0) continue; - delete_graph($db_graph["graphid"]); + if($db_graph["templateid"] == 0) + continue; + + if($templateid != null) + { + $tmp_graph = get_graph_by_graphid($db_graph["templateid"]); + if($tmp_graph["hostid"] != $templateid) + continue; + } + + if($unlink_mode) + { + if(DBexecute("update graphs set templateid=0 where graphid=".$db_graph["graphid"])) + { + info("Graph '".$db_graph["name"]."' unlinked"); + } + } + else + { + delete_graph($db_graph["graphid"]); + } } } - function sync_graphs_with_templates($hostid) + function copy_template_graphs($hostid, $templateid = null, $copy_mode = false) { - $host = get_host_by_hostid($hostid); - $db_graphs = get_graphs_by_hostid($host["templateid"]); + if($templateid == null) + { + $host = get_host_by_hostid($hostid); + $templateid = $host["templateid"]; + } + + $db_graphs = get_graphs_by_hostid($templateid); + while($db_graph = DBfetch($db_graphs)) { - copy_graph_to_host($db_graph["graphid"], $hostid); + copy_graph_to_host($db_graph["graphid"], $hostid, $copy_mode); } } - function copy_graph_to_host($graphid, $hostid) + function copy_graph_to_host($graphid, $hostid, $copy_mode = false) { $db_graph = get_graph_by_graphid($graphid); - $new_graphid = add_graph($db_graph["name"],$db_graph["width"],$db_graph["height"], - $db_graph["yaxistype"],$db_graph["yaxismin"],$db_graph["yaxismax"],$db_graph["show_work_period"], - $db_graph["show_triggers"],$graphid); + $new_graphid = add_graph($db_graph["name"],$db_graph["width"],$db_graph["height"],$db_graph["yaxistype"], + $db_graph["yaxismin"],$db_graph["yaxismax"],$db_graph["show_work_period"],$db_graph["show_triggers"], + $copy_mode ? 0 : $graphid + ); if(!$new_graphid) return $new_graphid; diff --git a/frontends/php/include/hosts.inc.php b/frontends/php/include/hosts.inc.php index 2a3f9838..afb23fbd 100644 --- a/frontends/php/include/hosts.inc.php +++ b/frontends/php/include/hosts.inc.php @@ -233,23 +233,33 @@ return $result; } + function unlink_template($hostid, $templateid = null, $unlink_mode = true) + { + delete_template_elements($hostid, $templateid = null, $unlink_mode); + DBexecute("update hosts set templateid=0 where hostid=".$hostid); + } + + function delete_template_elements($hostid, $templateid = null, $unlink_mode = false) + { + delete_template_graphs($hostid, $templateid, $unlink_mode); + delete_template_triggers($hostid, $templateid, $unlink_mode); + delete_template_items($hostid, $templateid, $unlink_mode); + delete_template_applications($hostid, $templateid, $unlink_mode); + } + + function copy_template_elements($hostid, $templateid = null, $copy_mode = false) + { + copy_template_applications($hostid, $templateid, $copy_mode); + copy_template_items($hostid, $templateid, $copy_mode); + copy_template_triggers($hostid, $templateid, $copy_mode); + copy_template_graphs($hostid, $templateid, $copy_mode); + } + # Sync host with linked template - function sync_host_with_templates($hostid) + function sync_host_with_templates($hostid, $templateid = null) { - $host = get_host_by_hostid($hostid); - delete_template_graphs_by_hostid($hostid); - delete_template_triggers_by_hostid($hostid); - delete_template_items_by_hostid($hostid); - - if($host["templateid"] > 0) - { -// start host syncing - sync_applications_with_template($hostid); - sync_items_with_template($hostid); - sync_triggers_with_template($hostid); - sync_graphs_with_templates($hostid); -// end host syncing - } + delete_template_elements($hostid, $templateid); + copy_template_elements($hostid, $templateid); } function delete_groups_by_hostid($hostid) @@ -273,12 +283,19 @@ # Delete Host - function delete_host($hostid) + function delete_host($hostid, $unlink_mode = false) { global $DB_TYPE; $ret = FALSE; + // unlink child hosts + $db_childs = get_hosts_by_templateid($hostid); + while($db_child = DBfetch($db_childs)) + { + unlink_template($db_child["hostid"], NULL, $unlink_mode); + } + // delete items -> triggers -> graphs $db_items = get_items_by_hostid($hostid); while($db_item = DBfetch($db_items)) @@ -292,14 +309,6 @@ // delete host from group DBexecute("delete from hosts_groups where hostid=$hostid"); - // unlink child hosts - $db_childs = get_hosts_by_templateid($hostid); - while($db_child = DBfetch($db_childs)) - { - DBexecute("update hosts set templateid=0 where hostid=".$db_child["hostid"]); - sync_host_with_templates($hostid); - } - // delete host profile delete_host_profile($hostid); @@ -718,20 +727,47 @@ return DBselect("select * from applications where hostid=$hostid"); } - function sync_applications_with_template($hostid) + function delete_template_applications($hostid, $templateid = null, $unlink_mode = false) { - $host = get_host_by_hostid($hostid); + $db_apps = get_applications_by_hostid($hostid); + while($db_app = DBfetch($db_apps)) + { + if($db_app["templateid"] == 0) + continue; -//SDI("sync host: ".$host['host']); + if($templateid != null && $templateid != $db_app["templateid"]) + continue; + + if($unlink_mode) + { + if(DBexecute("update applications set templateid=0 where applicationid=".$db_app["applicationid"])) + { + info("Application '".$db_app["name"]."' unlinked"); + } + } + else + { + delete_application($db_app["applicationid"]); + } + } + } + + function copy_template_applications($hostid, $templateid = null, $copy_mode = false) + { + if(null == $templateid) + { + $host = get_host_by_hostid($hostid); + $templateid = $host["templateid"]; + } - $db_tmp_applications = get_applications_by_hostid($host["templateid"]); + $db_tmp_applications = get_applications_by_hostid($templateid); while($db_tmp_app = DBfetch($db_tmp_applications)) { add_application( $db_tmp_app["name"], $hostid, - $db_tmp_app["applicationid"]); + $copy_mode ? 0 : $db_tmp_app["applicationid"]); } } ?> diff --git a/frontends/php/include/items.inc.php b/frontends/php/include/items.inc.php index 202e2b3d..328074e8 100644 --- a/frontends/php/include/items.inc.php +++ b/frontends/php/include/items.inc.php @@ -343,17 +343,36 @@ return $result; } - function delete_template_items_by_hostid($hostid) + function delete_template_items($hostid, $templateid = null, $unlink_mode = false) { $db_items = get_items_by_hostid($hostid); while($db_item = DBfetch($db_items)) { - if($db_item["templateid"] == 0) continue; - delete_item($db_item["itemid"]); + if($db_item["templateid"] == 0) + continue; + + if($templateid != null) + { + $db_tmp_item = get_item_by_itemid($db_item["templateid"]); + if($db_tmp_item["hostid"] != $templateid) + continue; + } + + if($unlink_mode) + { + if(DBexecute("update items set templateid=0 where itemid=".$db_item["itemid"])) + { + info("Item '".$db_item["key_"]."' unlinked"); + } + } + else + { + delete_item($db_item["itemid"]); + } } } - function sync_items_with_template($hostid) + function copy_template_items($hostid, $templateid = null, $copy_mode = false) { $host = get_host_by_hostid($hostid); @@ -395,7 +414,7 @@ $db_tmp_item["logtimefmt"], $db_tmp_item["valuemapid"], $applications, - $db_tmp_item["itemid"]); + $copy_mode ? 0 : $db_tmp_item["itemid"]); } } diff --git a/frontends/php/include/locales/en_gb.inc.php b/frontends/php/include/locales/en_gb.inc.php index 0902f1e3..ae0e8fc2 100644 --- a/frontends/php/include/locales/en_gb.inc.php +++ b/frontends/php/include/locales/en_gb.inc.php @@ -456,6 +456,8 @@ "S_TEMPLATES"=> "Templates", "S_TEMPLATES_BIG"=> "TEMPLATES", "S_HOSTS"=> "Hosts", + "S_UNLINK"=> "Unlink", + "S_UNLINK_AND_CLEAR"=> "Unlink and clear", // items.php "S_NO_ITEMS_DEFINED"=> "No items defined", diff --git a/frontends/php/include/triggers.inc.php b/frontends/php/include/triggers.inc.php index 75770c59..a1345428 100644 --- a/frontends/php/include/triggers.inc.php +++ b/frontends/php/include/triggers.inc.php @@ -33,7 +33,7 @@ function get_realhosts_by_triggerid($triggerid) { $trigger = get_trigger_by_triggerid($triggerid); - if($trigger["templateid"] <> 0) + if($trigger["templateid"] > 0) return get_realhosts_by_triggerid($trigger["templateid"]); return get_hosts_by_triggerid($triggerid); @@ -348,7 +348,7 @@ return $triggerid; } - function copy_trigger_to_host($triggerid, $hostid) + function copy_trigger_to_host($triggerid, $hostid, $copy_mode = false) { $trigger = get_trigger_by_triggerid($triggerid); @@ -373,14 +373,15 @@ $trigger["comments"], $trigger["url"], $deps, - $triggerid); + $copy_mode ? 0 : $triggerid); } $result = DBexecute("insert into triggers". " (description,priority,status,comments,url,value,expression,templateid)". - " values (".zbx_dbstr($trigger["description"]).",".$trigger["priority"]."," - .$trigger["status"].",".zbx_dbstr($trigger["comments"]).",". - zbx_dbstr($trigger["url"]).",2,'{???:???}', $triggerid)"); + " values (".zbx_dbstr($trigger["description"]).",".$trigger["priority"].",". + $trigger["status"].",".zbx_dbstr($trigger["comments"]).",". + zbx_dbstr($trigger["url"]).",2,'{???:???}',". + ($copy_mode ? 0 : $triggerid).")"); if(!$result) return $result; @@ -430,10 +431,11 @@ info("Added trigger '".$trigger["description"]."' to host '".$host["host"]."'"); +// Copy triggers to the child hosts $child_hosts = get_hosts_by_templateid($hostid); while($child_host = DBfetch($child_hosts)) {// recursion - $result = copy_trigger_to_host($triggerid, $child_host["hostid"]); + $result = copy_trigger_to_host($newtriggerid, $child_host["hostid"]); if(!$result){ return result; } @@ -1011,25 +1013,49 @@ return strcmp($expr1,$trig2["expression"]); } - function delete_template_triggers_by_hostid($hostid) + function delete_template_triggers($hostid, $templateid = null, $unlink_mode = false) { $triggers = get_triggers_by_hostid($hostid); while($trigger = DBfetch($triggers)) { if($trigger["templateid"]==0) continue; - delete_trigger($trigger["triggerid"]); + + if($templateid != null) + { + $db_tmp_hosts = get_hostis_by_triggerid($trigger["templateid"]); + $tmp_host = DBfetch($db_tmp_hosts); + if($tmp_host["hostid"] != $templateid) + continue; + } + + if($unlink_mode) + { + if(DBexecute("update triggers set templateid=0 where triggerid=".$trigger["triggerid"])) + { + info("Trigger '".$trigger["description"]."' unlinked"); + } + } + else + { + delete_trigger($trigger["triggerid"]); + } } return TRUE; } - function sync_triggers_with_template($hostid) + function copy_template_triggers($hostid, $templateid = null, $copy_mode = false) { - $host = get_host_by_hostid($hostid); - $triggers = get_triggers_by_hostid($host["templateid"]); + if(null == $templateid) + { + $host = get_host_by_hostid($hostid); + $templateid = $host["templateid"]; + } + + $triggers = get_triggers_by_hostid($templateid); while($trigger = DBfetch($triggers)) { - copy_trigger_to_host($trigger["triggerid"], $hostid); + copy_trigger_to_host($trigger["triggerid"], $hostid, $copy_mode); } } |
