diff options
| author | osmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2006-10-27 13:38:50 +0000 |
|---|---|---|
| committer | osmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2006-10-27 13:38:50 +0000 |
| commit | ef76479c1aeefa6f7920473f8be38292dfdbc837 (patch) | |
| tree | ea973e1f148d051ba0260099464d48efe7a37e1a /frontends/php/include | |
| parent | edf199a4f93b92945ef8a0f0a92730e4ec4f378e (diff) | |
- developed multitemplate system (Eugene)
git-svn-id: svn://svn.zabbix.com/trunk@3388 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php/include')
| -rw-r--r-- | frontends/php/include/actions.inc.php | 150 | ||||
| -rw-r--r-- | frontends/php/include/classes/ccheckbox.inc.php | 7 | ||||
| -rw-r--r-- | frontends/php/include/forms.inc.php | 62 | ||||
| -rw-r--r-- | frontends/php/include/graphs.inc.php | 21 | ||||
| -rw-r--r-- | frontends/php/include/hosts.inc.php | 225 | ||||
| -rw-r--r-- | frontends/php/include/html.inc.php | 7 | ||||
| -rw-r--r-- | frontends/php/include/items.inc.php | 31 | ||||
| -rw-r--r-- | frontends/php/include/locales/en_gb.inc.php | 1 | ||||
| -rw-r--r-- | frontends/php/include/triggers.inc.php | 23 |
9 files changed, 252 insertions, 275 deletions
diff --git a/frontends/php/include/actions.inc.php b/frontends/php/include/actions.inc.php index 47a771de..c0833e01 100644 --- a/frontends/php/include/actions.inc.php +++ b/frontends/php/include/actions.inc.php @@ -147,160 +147,16 @@ return $result; } - # Add action to hardlinked hosts - - function add_action_to_linked_hosts($actionid,$hostid=0) - { - if($actionid<=0) - { - return; - } - - $action=get_action_by_actionid($actionid); - $trigger=get_trigger_by_triggerid($action["triggerid"]); - - $sql="select distinct h.hostid from hosts h,functions f, items i where i.itemid=f.itemid and h.hostid=i.hostid and f.triggerid=".$action["triggerid"]; - $result=DBselect($sql); - $row=DBfetch($result); - if(!$row) - { - return; - } - - $host_template=get_host_by_hostid($row["hostid"]); - - if($hostid==0) - { - $sql="select hostid,templateid,actions from hosts_templates where templateid=".$row["hostid"]; - } - else - { - $sql="select hostid,templateid,actions from hosts_templates where hostid=$hostid and templateid=".$row["hostid"]; - } - $result=DBselect($sql); - while($row=DBfetch($result)) - { - if($row["actions"]&1 == 0) continue; - - $sql="select distinct f.triggerid from functions f,items i,triggers t where t.description=".zbx_dbstr($trigger["description"])." and t.triggerid=f.triggerid and i.itemid=f.itemid and i.hostid=".$row["hostid"]; - $result2=DBselect($sql); - while($row2=DBfetch($result2)) - { - $host=get_host_by_hostid($row["hostid"]); - $message=str_replace("{".$host_template["host"].":", "{".$host["host"].":", - $action["message"]); - - add_action($action["actiontype"],$row2["triggerid"], $action["userid"], $action["good"], - $action["subject"], $message, $action["scope"], - $action["severity"], $action["recipient"], $action["maxrepeats"], - $action["repeatdelay"],$action["scripts"]); - } - } - } - - # Delete action from hardlinked hosts - - function delete_action_from_templates($actionid) - { - if($actionid<=0) - { - return; - } - - $action=get_action_by_actionid($actionid); - $trigger=get_trigger_by_triggerid($action["triggerid"]); - - $sql="select distinct h.hostid from hosts h,functions f, items i where i.itemid=f.itemid and h.hostid=i.hostid and f.triggerid=".$action["triggerid"]; - $result=dbselect($sql); - - $row=dbfetch($result); - if(!$row) return; - - $hostid=$row["hostid"]; - - $sql="select hostid,templateid,actions from hosts_templates where templateid=$hostid"; - $result=dbselect($sql); - #enumerate hosts - while($row=dbfetch($result)) - { - if($row["actions"]&4 == 0) continue; - - $sql="select distinct f.triggerid from functions f,items i,triggers t where t.description=".zbx_dbstr($trigger["description"])." and t.triggerid=f.triggerid and i.itemid=f.itemid and i.hostid=".$row["hostid"]; - $result2=dbselect($sql); - #enumerate triggers - while($row2=dbfetch($result2)) - { - $sql="select actionid from actions where triggerid=".$row2["triggerid"]." and subject=".zbx_dbstr($action["subject"])." and userid=".$action["userid"]." and good=".$action["good"]." and scope=".$action["scope"]." and recipient=".$action["recipient"]." and severity=".$action["severity"]; - $result3=dbselect($sql); - #enumerate actions - while($row3=dbfetch($result3)) - { - delete_action($row3["actionid"]); - } - } - } - } - - # Update action from hardlinked hosts - - function update_action_from_linked_hosts($actionid) - { - if($actionid<=0) - { - return; - } - - $action=get_action_by_actionid($actionid); - $trigger=get_trigger_by_triggerid($action["triggerid"]); - - $sql="select distinct h.hostid from hosts h,functions f, items i where i.itemid=f.itemid and h.hostid=i.hostid and f.triggerid=".$action["triggerid"]; - $result=dbselect($sql); - if(dbnum_rows($result)!=1) - { - return; - } - - $row=dbfetch($result); - - $hostid=$row["hostid"]; - $host_template=get_host_by_hostid($hostid); - - $sql="select hostid,templateid,actions from hosts_templates where templateid=$hostid"; - $result=dbselect($sql); - #enumerate hosts - while($row=dbfetch($result)) - { - if($row["actions"]&2 == 0) continue; - - $sql="select distinct f.triggerid from functions f,items i,triggers t where t.description=".zbx_dbstr($trigger["description"])." and t.triggerid=f.triggerid and i.itemid=f.itemid and i.hostid=".$row["hostid"]; - $result2=dbselect($sql); - #enumerate triggers - while($row2=dbfetch($result2)) - { - $sql="select actionid from actions where triggerid=".$row2["triggerid"]." and subject=".zbx_dbstr($action["subject"]); - $result3=dbselect($sql); - #enumerate actions - while($row3=dbfetch($result3)) - { - $host=get_host_by_hostid($row["hostid"]); - $message=str_replace("{".$host_template["host"].":", "{".$host["host"].":", $action["message"]); - update_action($row3["actionid"], $action["actiontype"],$row2["triggerid"], $action["userid"], $action["good"], $action["subject"], $message, $action["scope"], $action["severity"], $action["recipient"], $action["maxrepeats"],$action["repeatdelay"],$action["scripts"]); - - } - } - } - } - function get_source_description($source) { - $desc="Unknown"; + $desc = S_UNKNOWN; if($source==1) { - $desc="IT Service"; + $desc=S_IT_SERVICE; } elseif($source==0) { - $desc="Trigger"; + $desc=S_TRIGGER; } return $desc; } diff --git a/frontends/php/include/classes/ccheckbox.inc.php b/frontends/php/include/classes/ccheckbox.inc.php index 83ac51a6..d8b21ac4 100644 --- a/frontends/php/include/classes/ccheckbox.inc.php +++ b/frontends/php/include/classes/ccheckbox.inc.php @@ -32,6 +32,13 @@ $this->options['onClick'] = $action; $this->SetChecked($checked); } + function SetEnabled($value='yes') + { + if($value=='yes' || $value == true || $value === 1) + return $this->DelOption('disabled'); + + return $this->options['disabled'] = 'yes'; + } function SetChecked($value="yes") { if((is_string($value)&& ($value=="yes" || $value=="checked" || $value=="on") || $value=="1") diff --git a/frontends/php/include/forms.inc.php b/frontends/php/include/forms.inc.php index 3dbfd1f5..c5879469 100644 --- a/frontends/php/include/forms.inc.php +++ b/frontends/php/include/forms.inc.php @@ -2557,7 +2557,8 @@ $location = get_request("location",""); $notes = get_request("notes",""); - $templateid = get_request("templateid",0); + $templates = get_request("templates",array()); + $clear_templates = get_request('clear_templates',array()); $frm_title = $show_only_tmp ? S_TEMPLATE : S_HOST; @@ -2565,6 +2566,12 @@ { $db_host=get_host_by_hostid($_REQUEST["hostid"]); $frm_title .= SPACE."\"".$db_host["host"]."\""; + + $original_templates = get_templates_by_hostid($_REQUEST["hostid"]); + } + else + { + $original_templates = array(); } if(isset($_REQUEST["hostid"]) && !isset($_REQUEST["form_refresh"])) @@ -2576,7 +2583,6 @@ $useip = $db_host["useip"]==1 ? 'yes' : 'no'; $ip = $db_host["ip"]; - $templateid = $db_host["templateid"]; // add groups $db_groups=DBselect("select distinct groupid from hosts_groups where hostid=".$_REQUEST["hostid"]. " and groupid in (". @@ -2608,12 +2614,12 @@ $location = $db_profile["location"]; $notes = $db_profile["notes"]; } + $templates = $original_templates; } - $real_templateid = 0; - if(isset($db_host) && $db_host["templateid"] > 0) - { - $real_templateid = $templateid = $db_host["templateid"]; - } + + $clear_templates = array_intersect($clear_templates, array_keys($original_templates)); + $clear_templates = array_diff($clear_templates,array_keys($templates)); + asort($templates); if($show_only_tmp){ $useip = "no"; @@ -2623,6 +2629,8 @@ $frmHost->SetHelp("web.hosts.host.php"); $frmHost->AddVar("config",get_request("config",0)); + $frmHost->AddVar('clear_templates',$clear_templates); + if(isset($_REQUEST["hostid"])) $frmHost->AddVar("hostid",$_REQUEST["hostid"]); if(isset($_REQUEST["groupid"])) $frmHost->AddVar("groupid",$_REQUEST["groupid"]); @@ -2690,26 +2698,29 @@ $frmHost->AddRow(S_STATUS,$cmbStatus); } - $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); - } + $template_table = new CTable(); + $template_table->SetCellPadding(0); + $template_table->SetCellSpacing(0); - $cmbHosts->AddItem(0,"..."); - $hosts=DBselect("select host,hostid from hosts where status in (".HOST_STATUS_TEMPLATE.")". - " and hostid in (".get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_LIST,null,null,$ZBX_CURNODEID).") ". - " order by host"); - while($host=DBfetch($hosts)) + foreach($templates as $id => $name) { - $cmbHosts->AddItem($host["hostid"],$host["host"]); + $frmHost->AddVar('templates['.$id.']',$name); + $template_table->AddRow(array( + $name, + new CButton('unlink['.$id.']',S_UNLINK), + isset($original_templates[$id]) ? new CButton('unlink_and_clear['.$id.']',S_UNLINK_AND_CLEAR) : SPACE + ) + ); } - $frmHost->AddRow(S_LINK_WITH_TEMPLATE, array($cmbHosts,SPACE, $btnUnlink, $btnUnlinkAndClear)); + + $frmHost->AddRow(S_LINK_WITH_TEMPLATE, array($template_table, + new CButton('add_template',S_ADD, + "return PopUp('popup.php?dstfrm=".$frmHost->GetName(). + "&dstfld1=new_template&srctbl=templates&srcfld1=hostid&srcfld2=host". + url_param($templates,false,'existed_templates')."','new_win',". + "'width=450,height=450,resizable=1,scrollbars=1');", + 'T') + )); if($show_only_tmp) { @@ -2785,6 +2796,7 @@ { global $_REQUEST; global $USER_DETAILS; + global $ZBX_CURNODEID; $hosts = get_request("hosts",array()); $frm_title = S_HOST_GROUP; @@ -2824,7 +2836,7 @@ $cmbHosts = new CListBox("hosts[]",$hosts,10); $db_hosts=DBselect("select distinct hostid,host from hosts". " where status<>".HOST_STATUS_DELETED. - " and hostid not in (".get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_WRITE,PERM_MODE_LT).")". + " and hostid in (".get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY,null,null,$ZBX_CURNODEID).")". " order by host"); while($db_host=DBfetch($db_hosts)) { diff --git a/frontends/php/include/graphs.inc.php b/frontends/php/include/graphs.inc.php index 20219ee9..7f41d831 100644 --- a/frontends/php/include/graphs.inc.php +++ b/frontends/php/include/graphs.inc.php @@ -422,7 +422,7 @@ return $result; } - function delete_template_graphs($hostid, $templateid = null, $unlink_mode = false) + function delete_template_graphs($hostid, $templateid = null /* array format 'arr[id]=name' */, $unlink_mode = false) { $db_graphs = get_graphs_by_hostid($hostid); while($db_graph = DBfetch($db_graphs)) @@ -433,7 +433,12 @@ if($templateid != null) { $tmp_graph = get_graph_by_graphid($db_graph["templateid"]); - if($tmp_graph["hostid"] != $templateid) + if(is_array($templateid)) + { + if(!isset($templateid[$tmp_graph["hostid"]])) + continue; + } + elseif($tmp_graph["hostid"] != $templateid) continue; } @@ -451,12 +456,18 @@ } } - function copy_template_graphs($hostid, $templateid = null, $copy_mode = false) + function copy_template_graphs($hostid, $templateid = null /* array format 'arr[id]=name' */, $copy_mode = false) { if($templateid == null) { - $host = get_host_by_hostid($hostid); - $templateid = $host["templateid"]; + $templateid = get_templates_by_hostid($hostid); + } + + if(is_array($templateid)) + { + foreach($templateid as $id => $name) + copy_template_graphs($hostid, $id, $copy_mode); // attention recursion + return; } $db_graphs = get_graphs_by_hostid($templateid); diff --git a/frontends/php/include/hosts.inc.php b/frontends/php/include/hosts.inc.php index 25a05dc3..834035cc 100644 --- a/frontends/php/include/hosts.inc.php +++ b/frontends/php/include/hosts.inc.php @@ -29,7 +29,7 @@ require_once "include/items.inc.php"; { if(!is_numeric($hostid) || !is_numeric($groupid)){ error("incorrect parameters for 'add_host_to_group'"); - return FALSE; + return false; } $hostgroupid=get_dbid("hosts_groups","hostgroupid"); $result=DBexecute("insert into hosts_groups (hostgroupid,hostid,groupid) values ($hostgroupid,$hostid,$groupid)"); @@ -38,14 +38,14 @@ require_once "include/items.inc.php"; return $hostgroupid; } - function db_save_group($name,$groupid=NULL) + function db_save_group($name,$groupid=null) { if(!is_string($name)){ error("incorrect parameters for 'db_save_group'"); - return FALSE; + return false; } - if($groupid==NULL) + if($groupid==null) $result = DBexecute("select * from groups where name=".zbx_dbstr($name)); else $result = DBexecute("select * from groups where name=".zbx_dbstr($name). @@ -54,13 +54,13 @@ require_once "include/items.inc.php"; if(DBfetch($result)) { error("Group '$name' already exists"); - return FALSE; + return false; } - if($groupid==NULL) + if($groupid==null) { $groupid=get_dbid("groups","groupid"); if(!DBexecute("insert into groups (groupid,name) values (".$groupid.",".zbx_dbstr($name).")")) - return FALSE; + return false; return $groupid; } @@ -70,8 +70,8 @@ require_once "include/items.inc.php"; function add_group_to_host($hostid,$newgroup="") { - if($newgroup == "" || $newgroup == NULL) - return TRUE; + if($newgroup == "" || $newgroup == null) + return true; $groupid = db_save_group($newgroup); if(!$groupid) @@ -123,70 +123,79 @@ require_once "include/items.inc.php"; } /* HOST finction */ - function check_circle_host_link($hostid, $templateid) + function check_circle_host_link($hostid, $templates) { - if($templateid <= 0) return FALSE; - if($hostid == $templateid) return TRUE; - $template = get_host_by_hostid($templateid); - if($template["templateid"] > 0) - return check_circle_host_link($hostid, $template["templateid"]); - - return FALSE; + if(count($templates) == 0) return false; + if(isset($templates[$hostid])) return true; + foreach($templates as $id => $name) + if(check_circle_host_link($hostid, get_templates_by_hostid($id))) + return true; + + return false; } - function db_save_host($host,$port,$status,$useip,$ip,$templateid,$hostid=NULL) + function db_save_host($host,$port,$status,$useip,$ip,$templates,$hostid=null) { + global $ZBX_CURNODEID; + if (!eregi('^([0-9a-zA-Z\_\.-]+)$', $host)) { error("Hostname should contain 0-9a-zA-Z_.- characters only"); - return FALSE; + return false; } - if($hostid==NULL) - $result=DBexecute("select * from hosts where host=".zbx_dbstr($host)); - else - $result=DBexecute("select * from hosts where host=".zbx_dbstr($host). - " and hostid<>$hostid"); - if(DBfetch($result)) + if(DBfetch(DBselect( + "select * from hosts where host=".zbx_dbstr($host). + ' and '.DBid2nodeid('hostid').'='.$ZBX_CURNODEID. + (isset($hostid) ? ' and hostid<>'.$hostid : '') + ))) { error("Host '$host' already exists"); - return FALSE; + return false; } if($useip=="on" || $useip=="yes" || $useip==1) $useip=1; else $useip=0; - if($hostid==NULL) + if($hostid==null) { $hostid = get_dbid("hosts","hostid"); $result = DBexecute("insert into hosts". - " (hostid,host,port,status,useip,ip,disable_until,available,templateid)". + " (hostid,host,port,status,useip,ip,disable_until,available)". " values ($hostid,".zbx_dbstr($host).",$port,$status,$useip,".zbx_dbstr($ip).",0," - .HOST_AVAILABLE_UNKNOWN.",$templateid)"); - if($result) $result = $hostid; + .HOST_AVAILABLE_UNKNOWN.")"); } else { - if(check_circle_host_link($hostid, $templateid)) + if(check_circle_host_link($hostid, $templates)) { error("Circle link can't be created"); - return FALSE; + return false; } $result = DBexecute("update hosts set host=".zbx_dbstr($host).",". - "port=$port,useip=$useip,ip=".zbx_dbstr($ip).",templateid=$templateid". - " where hostid=$hostid"); + "port=$port,useip=$useip,ip=".zbx_dbstr($ip)." where hostid=$hostid"); update_host_status($hostid, $status); } + + foreach($templates as $id => $name) + { + $hosttemplateid = get_dbid('hosts_templates', 'hosttemplateid'); + if(!($result = DBexecute('insert into hosts_templates values ('.$hosttemplateid.','.$hostid.','.$id.')'))) + break; + } + + if($result) $result = $hostid; + return $result; } - function add_host($host,$port,$status,$useip,$ip,$templateid,$newgroup,$groups) + function add_host($host,$port,$status,$useip,$ip,$templates,$newgroup,$groups) { - $hostid = db_save_host($host,$port,$status,$useip,$ip,$templateid); + $hostid = db_save_host($host,$port,$status,$useip,$ip,$templates); if(!$hostid) return $hostid; @@ -201,11 +210,18 @@ require_once "include/items.inc.php"; return $hostid; } - function update_host($hostid,$host,$port,$status,$useip,$ip,$templateid,$newgroup,$groups) + function update_host($hostid,$host,$port,$status,$useip,$ip,$templates,$newgroup,$groups) { + $old_templates = get_templates_by_hostid($hostid); + $unlinked_templates = array_diff($old_templates, $templates); + foreach($unlinked_templates as $id => $name) + { + unlink_template($hostid, $id); + } + $old_host = get_host_by_hostid($hostid); - $result = db_save_host($host,$port,$status,$useip,$ip,$templateid,$hostid); + $result = db_save_host($host,$port,$status,$useip,$ip,$templates,$hostid); if(!$result) return $result; @@ -213,16 +229,21 @@ require_once "include/items.inc.php"; add_group_to_host($hostid,$newgroup); - if($old_host["templateid"] != $templateid) - sync_host_with_templates($hostid); + $new_templates = array_diff($templates, $old_templates); + if(count($new_templates) > 0) + { + sync_host_with_templates($hostid,$new_templates); + } return $result; } - function unlink_template($hostid, $templateid = null, $unlink_mode = true) + function unlink_template($hostid, $templateid, $unlink_mode = true) { - delete_template_elements($hostid, $templateid = null, $unlink_mode); - DBexecute("update hosts set templateid=0 where hostid=".$hostid); + if(is_array($templateid)) fatal_error('array not supported for [unlink_template]'); + + delete_template_elements($hostid, $templateid, $unlink_mode); + DBexecute("delete from hosts_templates where hostid=".$hostid.' and templateid='.$templateid); } function delete_template_elements($hostid, $templateid = null, $unlink_mode = false) @@ -273,13 +294,13 @@ require_once "include/items.inc.php"; { global $DB_TYPE; - $ret = FALSE; + $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); + unlink_template($db_child["hostid"], $hostid, $unlink_mode); } // delete items -> triggers -> graphs @@ -295,6 +316,9 @@ require_once "include/items.inc.php"; // delete host from group DBexecute("delete from hosts_groups where hostid=$hostid"); + // delete host from template linkages + DBexecute("delete from hosts_templates where hostid=$hostid"); + // delete host profile delete_host_profile($hostid); @@ -305,7 +329,7 @@ require_once "include/items.inc.php"; function delete_host_group($groupid) { if(!DBexecute("delete from hosts_groups where groupid=$groupid")) - return FALSE; + return false; return DBexecute("delete from groups where groupid=$groupid"); } @@ -319,7 +343,7 @@ require_once "include/items.inc.php"; return $row; } error("No host groups with groupid=[$groupid]"); - return FALSE; + return false; } function get_host_by_itemid($itemid) @@ -332,7 +356,7 @@ require_once "include/items.inc.php"; return $row; } error("No host with itemid=[$itemid]"); - return FALSE; + return false; } function get_host_by_hostid($hostid,$no_error_message=0) @@ -346,7 +370,7 @@ require_once "include/items.inc.php"; } if($no_error_message == 0) error("No host with hostid=[$hostid]"); - return FALSE; + return false; } function get_hosts_by_templateid($templateid) @@ -358,9 +382,7 @@ require_once "include/items.inc.php"; function update_host_status($hostid,$status) { - $sql="select status,host from hosts where hostid=$hostid"; - $result=DBselect($sql); - $row=DBfetch($result); + $row=DBfetch(DBselect("select status,host from hosts where hostid=$hostid")); $old_status=$row["status"]; if($status != $old_status) { @@ -375,18 +397,20 @@ require_once "include/items.inc.php"; } } - function get_template_path($hostid) + function get_templates_by_hostid($hostid) { - $host = get_host_by_hostid($hostid); - - if ($host["templateid"]==0) - return "/"; - - $tmp_host = get_host_by_hostid($host["templateid"]); - return get_template_path($tmp_host["hostid"]).$tmp_host["host"]."/"; + $resuilt = array(); + $db_templates = DBselect('select distinct h.hostid,h.host from hosts_templates ht '. + ' left join hosts h on h.hostid=ht.templateid '. + ' where ht.hostid='.$hostid); + while($template_data = DBfetch($db_templates)) + { + $resuilt[$template_data['hostid']] = $template_data['host']; + } + return $resuilt; } - function get_correct_group_and_host($a_groupid=NULL, $a_hostid=NULL, $perm=PERM_READ_WRITE, $options = array()) + function get_correct_group_and_host($a_groupid=null, $a_hostid=null, $perm=PERM_READ_WRITE, $options = array()) { if(!is_array($options)) { @@ -507,7 +531,7 @@ require_once "include/items.inc.php"; ); } - function validate_group_with_host($perm, $options = array(),$group_var=NULL,$host_var=NULL) + function validate_group_with_host($perm, $options = array(),$group_var=null,$host_var=null) { if(is_null($group_var)) $group_var = "web.latest.groupid"; if(is_null($host_var)) $host_var = "web.latest.hostid"; @@ -541,13 +565,13 @@ require_once "include/items.inc.php"; update_profile($group_var,$_REQUEST["groupid"]); } - function validate_group($perm, $options = array(),$group_var=NULL) + function validate_group($perm, $options = array(),$group_var=null) { if(is_null($group_var)) $group_var = "web.latest.groupid"; $_REQUEST["groupid"] = get_request("groupid",get_profile($group_var,0)); - $result = get_correct_group_and_host($_REQUEST["groupid"],NULL,$perm,$options); + $result = get_correct_group_and_host($_REQUEST["groupid"],null,$perm,$options); $_REQUEST["groupid"] = $result["groupid"]; @@ -556,14 +580,14 @@ require_once "include/items.inc.php"; /* APPLICATIONS */ - function db_save_application($name,$hostid,$applicationid=NULL,$templateid=0) + function db_save_application($name,$hostid,$applicationid=null,$templateid=0) { if(!is_string($name)){ error("incorrect parameters for 'db_save_application'"); - return FALSE; + return false; } - if($applicationid==NULL) + if($applicationid==null) $result = DBexecute("select * from applications where name=".zbx_dbstr($name)." and hostid=".$hostid); else $result = DBexecute("select * from applications where name=".zbx_dbstr($name)." and hostid=".$hostid. @@ -573,21 +597,21 @@ require_once "include/items.inc.php"; if($db_app && $templateid==0) { error("Application '$name' already exists"); - return FALSE; + return false; } - if($db_app && $applicationid!=NULL) + if($db_app && $applicationid!=null) { // delete old item with same name delete_application($db_app["applicationid"]); } - if($db_app && $applicationid==NULL) + if($db_app && $applicationid==null) { // if found application with same name update them, adding not needed $applicationid = $db_app["applicationid"]; } $host = get_host_by_hostid($hostid); - if($applicationid==NULL) + if($applicationid==null) { $applicationid_new = get_dbid("applications","applicationid"); if($result = DBexecute("insert into applications (applicationid,name,hostid,templateid)". @@ -604,7 +628,7 @@ require_once "include/items.inc.php"; if(!$result) return $result; - if($applicationid==NULL) + if($applicationid==null) { $applicationid = $applicationid_new; @@ -635,7 +659,7 @@ require_once "include/items.inc.php"; } function add_application($name,$hostid,$templateid=0) { - return db_save_application($name,$hostid,NULL,$templateid); + return db_save_application($name,$hostid,null,$templateid); } function update_application($applicationid,$name,$hostid,$templateid=0) @@ -676,7 +700,7 @@ require_once "include/items.inc.php"; } if($no_error_message == 0) error("No application with id=[$applicationid]"); - return FALSE; + return false; } @@ -704,7 +728,7 @@ require_once "include/items.inc.php"; return $row; } error("No host with applicationid=[$applicationid]"); - return FALSE; + return false; } function get_items_by_applicationid($applicationid) @@ -717,7 +741,7 @@ require_once "include/items.inc.php"; return DBselect("select * from applications where hostid=$hostid"); } - function delete_template_applications($hostid, $templateid = null, $unlink_mode = false) + function delete_template_applications($hostid, $templateid = null /* array format 'arr[id]=name' */, $unlink_mode = false) { $db_apps = get_applications_by_hostid($hostid); while($db_app = DBfetch($db_apps)) @@ -725,8 +749,17 @@ require_once "include/items.inc.php"; if($db_app["templateid"] == 0) continue; - if($templateid != null && $templateid != $db_app["templateid"]) - continue; + if($templateid != null) + { + $db_tmp_apps = get_applications_by_hostid($db_app["templateid"]); + if(is_array($templateid)) + { + if(!isset($templateid[$db_tmp_app["hostid"]])) + continue; + } + elseif($templateid != $db_tmp_app["hostid"]) + continue; + } if($unlink_mode) { @@ -742,12 +775,18 @@ require_once "include/items.inc.php"; } } - function copy_template_applications($hostid, $templateid = null, $copy_mode = false) + function copy_template_applications($hostid, $templateid = null /* array format 'arr[id]=name' */, $copy_mode = false) { if(null == $templateid) { - $host = get_host_by_hostid($hostid); - $templateid = $host["templateid"]; + $templateid = get_templates_by_hostid($hostid); + } + + if(is_array($templateid)) + { + foreach($templateid as $id => $name) + copy_template_applications($hostid, $id, $copy_mode); // attention recursion + return; } $db_tmp_applications = get_applications_by_hostid($templateid); @@ -760,4 +799,28 @@ require_once "include/items.inc.php"; $copy_mode ? 0 : $db_tmp_app["applicationid"]); } } + + function validate_templates($templateid_list) + { + if(is_numeric($templateid_list))return true; + if(!is_array($templateid_list)) return false; + if(count($templateid_list)<2) return true; + + $result = true; + $db_cnt = DBfetch(DBselect('select key_,type,count(*) as cnt from items '. + ' where hostid in ('.implode(',',$templateid_list).') '. + ' group by key_,type order by cnt desc' + )); + + $result &= $db_cnt['cnt'] > 1 ? false : true; + + $db_cnt = DBfetch(DBselect('select name,count(*) as cnt from applications '. + ' where hostid in ('.implode(',',$templateid_list).') '. + ' group by name order by cnt desc' + )); + + $result &= $db_cnt['cnt'] > 1 ? false : true; + + return $result; + } ?> diff --git a/frontends/php/include/html.inc.php b/frontends/php/include/html.inc.php index 385675f1..2a57bb43 100644 --- a/frontends/php/include/html.inc.php +++ b/frontends/php/include/html.inc.php @@ -103,7 +103,8 @@ function url_param($parameter,$request=true,$name=null) { - + if(!$request && !isset($name)) fatal_error('not request variable require url name [url_param]'); + $result = ""; if(!isset($name)) $name = $parameter; @@ -116,9 +117,7 @@ } else { - global $$parameter; - - $var =& $$parameter; + $var =& $parameter; } if(isset($var)) diff --git a/frontends/php/include/items.inc.php b/frontends/php/include/items.inc.php index 6875c831..271061f5 100644 --- a/frontends/php/include/items.inc.php +++ b/frontends/php/include/items.inc.php @@ -387,7 +387,7 @@ return $result; } - function delete_template_items($hostid, $templateid = null, $unlink_mode = false) + function delete_template_items($hostid, $templateid = null /* array format 'arr[id]=name' */, $unlink_mode = false) { $db_items = get_items_by_hostid($hostid); while($db_item = DBfetch($db_items)) @@ -398,8 +398,15 @@ if($templateid != null) { $db_tmp_item = get_item_by_itemid($db_item["templateid"]); - if($db_tmp_item["hostid"] != $templateid) + if(is_array($templateid)) + { + if(!isset($templateid[$db_tmp_item["hostid"]])) + continue; + } + elseif($db_tmp_item["hostid"] != $templateid) + { continue; + } } if($unlink_mode) @@ -454,11 +461,21 @@ $copy_mode ? 0 : $db_tmp_item["itemid"]); } - function copy_template_items($hostid, $templateid = null, $copy_mode = false) + function copy_template_items($hostid, $templateid = null /* array format 'arr[id]=name' */, $copy_mode = false) { - $host = get_host_by_hostid($hostid); + if($templateid == null) + { + $templateid = get_templates_by_hostid($hostid); + } + + if(is_array($templateid)) + { + foreach($templateid as $id => $name) + copy_template_items($hostid, $id, $copy_mode); // attention recursion + return; + } - $db_tmp_items = get_items_by_hostid($host["templateid"]); + $db_tmp_items = get_items_by_hostid($templateid); while($db_tmp_item = DBfetch($db_tmp_items)) { @@ -724,7 +741,7 @@ COpt::profiling_stop('prepare table'); function delete_history_by_itemid($itemid, $use_housekeeper=0) { - SDI('TODO: Correct housekeeper scheduling!'); /* TODO */ /* think about housekeeper scheduling, must be housekeeperid - unneeded */ + SDI('TODO: Correct housekeeper scheduling [new elementid problem]!'); /* TODO */ /* think about housekeeper scheduling, must be housekeeperid - unneeded */ $result = delete_trends_by_itemid($itemid,$use_housekeeper); if(!$result) return $result; @@ -757,7 +774,7 @@ COpt::profiling_stop('prepare table'); function delete_trends_by_itemid($itemid, $use_housekeeper=0) { - SDI('TODO: Correct housekeeper scheduling!'); /* TODO */ /* think about housekeeper scheduling, must be housekeeperid - unneeded */ + SDI('TODO: Correct housekeeper scheduling [new elementid problem]!'); /* TODO */ /* think about housekeeper scheduling, must be housekeeperid - unneeded */ if($use_housekeeper) { diff --git a/frontends/php/include/locales/en_gb.inc.php b/frontends/php/include/locales/en_gb.inc.php index 7459a223..127dbb85 100644 --- a/frontends/php/include/locales/en_gb.inc.php +++ b/frontends/php/include/locales/en_gb.inc.php @@ -419,6 +419,7 @@ "S_NO_HOST_GROUPS_DEFINED"=> "No host groups defined", "S_NO_LINKAGES_DEFINED"=> "No linkages defined", "S_NO_HOSTS_DEFINED"=> "No hosts defined", + "S_NO_TEMPLATES_DEFINED"=> "No templates defined", "S_HOSTS_BIG"=> "HOSTS", "S_HOST"=> "Host", "S_IP"=> "IP", diff --git a/frontends/php/include/triggers.inc.php b/frontends/php/include/triggers.inc.php index 7f079310..26a9edac 100644 --- a/frontends/php/include/triggers.inc.php +++ b/frontends/php/include/triggers.inc.php @@ -1014,7 +1014,7 @@ return strcmp($expr1,$trig2["expression"]); } - function delete_template_triggers($hostid, $templateid = null, $unlink_mode = false) + function delete_template_triggers($hostid, $templateid = null /* array format 'arr[id]=name' */, $unlink_mode = false) { $triggers = get_triggers_by_hostid($hostid); while($trigger = DBfetch($triggers)) @@ -1023,9 +1023,14 @@ if($templateid != null) { - $db_tmp_hosts = get_hostis_by_triggerid($trigger["templateid"]); + $db_tmp_hosts = get_hosts_by_triggerid($trigger["templateid"]); $tmp_host = DBfetch($db_tmp_hosts); - if($tmp_host["hostid"] != $templateid) + if(is_array($templateid)) + { + if(!isset($templateid[$tmp_host["hostid"]])) + continue; + } + elseif($tmp_host["hostid"] != $templateid) continue; } @@ -1045,12 +1050,18 @@ return TRUE; } - function copy_template_triggers($hostid, $templateid = null, $copy_mode = false) + function copy_template_triggers($hostid, $templateid = null /* array format 'arr[id]=name' */, $copy_mode = false) { if(null == $templateid) { - $host = get_host_by_hostid($hostid); - $templateid = $host["templateid"]; + $templateid = get_templates_by_hostid($hostid);; + } + + if(is_array($templateid)) + { + foreach($templateid as $id => $name) + copy_template_triggers($hostid, $id, $copy_mode); // attention recursion + return; } $triggers = get_triggers_by_hostid($templateid); |
