diff options
| author | hugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2005-08-29 10:06:42 +0000 |
|---|---|---|
| committer | hugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2005-08-29 10:06:42 +0000 |
| commit | 450bedfbd08dbb30b3a6fa47abe411e2bc689024 (patch) | |
| tree | b2a57904c928e0d63785109b7d8db93723e8e365 /frontends/php/include | |
| parent | 2ce640571ab5c0db1a26858f96ba804e36f1fb37 (diff) | |
| download | zabbix-450bedfbd08dbb30b3a6fa47abe411e2bc689024.tar.gz zabbix-450bedfbd08dbb30b3a6fa47abe411e2bc689024.tar.xz zabbix-450bedfbd08dbb30b3a6fa47abe411e2bc689024.zip | |
- misc fixes for host-templates linkage (Alexei)
git-svn-id: svn://svn.zabbix.com/trunk@2009 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php/include')
| -rw-r--r-- | frontends/php/include/actions.inc.php | 18 | ||||
| -rw-r--r-- | frontends/php/include/config.inc.php | 160 | ||||
| -rw-r--r-- | frontends/php/include/graphs.inc.php | 13 | ||||
| -rw-r--r-- | frontends/php/include/hosts.inc.php | 1 | ||||
| -rw-r--r-- | frontends/php/include/items.inc.php | 12 | ||||
| -rw-r--r-- | frontends/php/include/triggers.inc.php | 14 |
6 files changed, 65 insertions, 153 deletions
diff --git a/frontends/php/include/actions.inc.php b/frontends/php/include/actions.inc.php index d6e403a1..10a732c2 100644 --- a/frontends/php/include/actions.inc.php +++ b/frontends/php/include/actions.inc.php @@ -101,7 +101,7 @@ # Add action to hardlinked hosts - function add_action_to_templates($actionid) + function add_action_to_linked_hosts($actionid,$hostid=0) { if($actionid<=0) { @@ -117,12 +117,18 @@ { return; } - $row=DBfetch($result); - $hostid=$row["hostid"]; + $host_template=get_host_by_hostid($row["hostid"]); - $sql="select hostid,templateid,actions from hosts_templates where templateid=$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)) { @@ -132,7 +138,9 @@ $result2=DBselect($sql); while($row2=DBfetch($result2)) { - add_action($row2["triggerid"], $action["userid"], $action["good"], $action["delay"], $action["subject"], $action["message"], $action["scope"], $action["severity"], $action["recipient"], $action["userid"]); + $host=get_host_by_hostid($row["hostid"]); + $message=str_replace("{".$host_template["host"].":", "{".$host["host"].":", $action["message"]); + add_action($row2["triggerid"], $action["userid"], $action["good"], $action["delay"], $action["subject"], $message, $action["scope"], $action["severity"], $action["recipient"], $action["userid"]); } } } diff --git a/frontends/php/include/config.inc.php b/frontends/php/include/config.inc.php index 7a297fad..346f4701 100644 --- a/frontends/php/include/config.inc.php +++ b/frontends/php/include/config.inc.php @@ -1586,75 +1586,6 @@ echo "</head>"; return DBexecute($sql); } - # Add everything based on host_templateid - - function add_using_host_template($hostid,$host_templateid) - { - if(!isset($host_templateid)||($host_templateid==0)) - { - error("Select template first"); - return 0; - } - - $host=get_host_by_hostid($hostid); - $sql="select itemid from items where hostid=$host_templateid"; - $result=DBselect($sql); - while($row=DBfetch($result)) - { - $item=get_item_by_itemid($row["itemid"]); - $itemid=add_item($item["description"],$item["key_"],$hostid,$item["delay"],$item["history"],$item["status"],$item["type"],$item["snmp_community"],$item["snmp_oid"],$item["value_type"],"",$item["snmp_port"],$item["units"],$item["multiplier"],$item["delta"],$item["snmpv3_securityname"],$item["snmpv3_securitylevel"],$item["snmpv3_authpassphrase"],$item["snmpv3_privpassphrase"],$item["formula"],$item["trends"]); - - $sql="select distinct t.triggerid from triggers t,functions f where f.itemid=".$row["itemid"]." and f.triggerid=t.triggerid"; - $result2=DBselect($sql); - while($row2=DBfetch($result2)) - { - $trigger=get_trigger_by_triggerid($row2["triggerid"]); -// Cannot use add_trigger here - $description=$trigger["description"]; -# $description=str_replace("%s",$host["host"],$description); - $sql="insert into triggers (description,priority,status,comments,url,value) values ('".addslashes($description)."',".$trigger["priority"].",".$trigger["status"].",'".addslashes($trigger["comments"])."','".addslashes($trigger["url"])."',2)"; - $result4=DBexecute($sql); - $triggerid=DBinsert_id($result4,"triggers","triggerid"); - - $sql="select functionid from functions where triggerid=".$row2["triggerid"]." and itemid=".$row["itemid"]; - $result3=DBselect($sql); - while($row3=DBfetch($result3)) - { - $function=get_function_by_functionid($row3["functionid"]); - $sql="insert into functions (itemid,triggerid,function,parameter) values ($itemid,$triggerid,'".$function["function"]."','".$function["parameter"]."')"; - $result4=DBexecute($sql); - $functionid=DBinsert_id($result4,"functions","functionid"); - $sql="update triggers set expression='".$trigger["expression"]."' where triggerid=$triggerid"; - DBexecute($sql); - $trigger["expression"]=str_replace("{".$row3["functionid"]."}","{".$functionid."}",$trigger["expression"]); - $sql="update triggers set expression='".$trigger["expression"]."' where triggerid=$triggerid"; - DBexecute($sql); - } - # Add actions - $sql="select actionid from actions where scope=0 and triggerid=".$row2["triggerid"]; - $result3=DBselect($sql); - while($row3=DBfetch($result3)) - { - $action=get_action_by_actionid($row3["actionid"]); - $userid=$action["userid"]; - $scope=$action["scope"]; - $severity=$action["severity"]; - $good=$action["good"]; - $delay=$action["delay"]; - $subject=addslashes($action["subject"]); - $message=addslashes($action["message"]); - $recipient=$action["recipient"]; - $sql="insert into actions (triggerid, userid, scope, severity, good, delay, subject, message,recipient) values ($triggerid,$userid,$scope,$severity,$good,$delay,'$subject','$message',$recipient)"; -// echo "$sql<br>"; - $result4=DBexecute($sql); - $actionid=DBinsert_id($result4,"actions","actionid"); - } - } - } - - return TRUE; - } - function add_group_to_host($hostid,$newgroup) { $sql="insert into groups (groupid,name) values (NULL,'$newgroup')"; @@ -1837,83 +1768,36 @@ echo "</head>"; return 0; } - $host=get_host_by_hostid($hostid); + // Sync items $sql="select itemid from items where hostid=$templateid"; $result=DBselect($sql); while($row=DBfetch($result)) - { - $item=get_item_by_itemid($row["itemid"]); - $itemid=add_item($item["description"],$item["key_"],$hostid,$item["delay"],$item["history"],$item["status"],$item["type"],$item["snmp_community"],$item["snmp_oid"],$item["value_type"],"",$item["snmp_port"],$item["units"],$item["multiplier"],$item["delta"],$item["snmpv3_securityname"],$item["snmpv3_securitylevel"],$item["snmpv3_authpassphrase"],$item["snmpv3_privpassphrase"],$item["formula"],$item["trends"]); + { + add_item_to_linked_hosts($row["itemid"],$hostid); + } - $sql="select distinct t.triggerid from triggers t,functions f where f.itemid=".$row["itemid"]." and f.triggerid=t.triggerid"; - $result2=DBselect($sql); - while($row2=DBfetch($result2)) - { - $trigger=get_trigger_by_triggerid($row2["triggerid"]); -// Cannot use add_trigger here - $description=$trigger["description"]; -# $description=str_replace("%s",$host["host"],$description); - $sql="insert into triggers (description,priority,status,comments,url,value) values ('".addslashes($description)."',".$trigger["priority"].",".$trigger["status"].",'".addslashes($trigger["comments"])."','".addslashes($trigger["url"])."',2)"; - $result4=DBexecute($sql); - $triggerid=DBinsert_id($result4,"triggers","triggerid"); - - $sql="select functionid from functions where triggerid=".$row2["triggerid"]." and itemid=".$row["itemid"]; - $result3=DBselect($sql); - while($row3=DBfetch($result3)) - { - $function=get_function_by_functionid($row3["functionid"]); - $sql="insert into functions (itemid,triggerid,function,parameter) values ($itemid,$triggerid,'".$function["function"]."','".$function["parameter"]."')"; - $result4=DBexecute($sql); - $functionid=DBinsert_id($result4,"functions","functionid"); - $sql="update triggers set expression='".$trigger["expression"]."' where triggerid=$triggerid"; - DBexecute($sql); - $trigger["expression"]=str_replace("{".$row3["functionid"]."}","{".$functionid."}",$trigger["expression"]); - $sql="update triggers set expression='".$trigger["expression"]."' where triggerid=$triggerid"; - DBexecute($sql); - } - # Add actions - $sql="select actionid from actions where scope=0 and triggerid=".$row2["triggerid"]; - $result3=DBselect($sql); - while($row3=DBfetch($result3)) - { - $action=get_action_by_actionid($row3["actionid"]); - $userid=$action["userid"]; - $scope=$action["scope"]; - $severity=$action["severity"]; - $good=$action["good"]; - $delay=$action["delay"]; - $subject=addslashes($action["subject"]); - $message=addslashes($action["message"]); - $recipient=$action["recipient"]; - $sql="insert into actions (triggerid, userid, scope, severity, good, delay, subject, message,recipient) values ($triggerid,$userid,$scope,$severity,$good,$delay,'$subject','$message',$recipient)"; -// echo "$sql<br>"; - $result4=DBexecute($sql); - $actionid=DBinsert_id($result4,"actions","actionid"); - } - } + // Sync triggers + $sql="select distinct t.triggerid from hosts h, items i,triggers t,functions f where h.hostid=$templateid and h.hostid=i.hostid and t.triggerid=f.triggerid and i.itemid=f.itemid"; + $result=DBselect($sql); + while($row=DBfetch($result)) + { + add_trigger_to_linked_hosts($row["triggerid"],$hostid); } - # Add graphs - $sql="select distinct g.graphid from graphs g,items i, hosts h,graphs_items gi where h.hostid=$templateid and i.hostid=h.hostid and gi.itemid=i.itemid and g.graphid=gi.graphid"; + // Sync actions + $sql="select distinct a.actionid from actions a,hosts h, items i,triggers t,functions f where h.hostid=$templateid and h.hostid=i.hostid and t.triggerid=f.triggerid and i.itemid=f.itemid"; $result=DBselect($sql); while($row=DBfetch($result)) - { - $graph=get_graph_by_graphid($row["graphid"]); - $graphid=add_graph($graph["name"],$graph["width"],$graph["height"],$graph["yaxistype"],$graph["yaxismin"],$graph["yaxismax"]); - $sql="select distinct gi.gitemid from graphs_items gi,graphs g,items i,hosts h where gi.itemid=i.itemid and h.hostid=$templateid and i.hostid=h.hostid and g.graphid=gi.graphid and gi.itemid=i.itemid and g.graphid=".$graph["graphid"]; - $result2=DBselect($sql); - while($row=DBfetch($result2)) - { - $gitem=get_graphitem_by_gitemid($row["gitemid"]); - $item=get_item_by_itemid($gitem["itemid"]); - $sql="select * from items where key_='".$item["key_"]."' and hostid=$hostid"; - $result3=DBselect($sql); - if(DBnum_rows($result3)==1) - { - $row2=DBfetch($result3); - add_item_to_graph($graphid,$row2["itemid"],$gitem["color"],$gitem["drawtype"],$gitem["sortorder"]); - } - } + { + add_action_to_linked_hosts($row["actionid"],$hostid); + } + + // Sync graphs + $sql="select distinct gi.gitemid from graphs g,graphs_items gi,items i where i.itemid=gi.itemid and i.hostid=$templateid and g.graphid=gi.graphid"; + $result=DBselect($sql); + while($row=DBfetch($result)) + { + add_graph_item_to_linked_hosts($row["gitemid"],$hostid); } return TRUE; diff --git a/frontends/php/include/graphs.inc.php b/frontends/php/include/graphs.inc.php index 7b07bdb3..3589032d 100644 --- a/frontends/php/include/graphs.inc.php +++ b/frontends/php/include/graphs.inc.php @@ -111,7 +111,7 @@ return $result; } - function add_graph_item_to_templates($gitemid) + function add_graph_item_to_linked_hosts($gitemid,$hostid=0) { if($gitemid<=0) { @@ -122,7 +122,14 @@ $graph=get_graph_by_graphid($graph_item["graphid"]); $item=get_item_by_itemid($graph_item["itemid"]); - $sql="select hostid,templateid,graphs from hosts_templates where templateid=".$item["hostid"]; + if($hostid==0) + { + $sql="select hostid,templateid,graphs from hosts_templates where templateid=".$item["hostid"]; + } + else + { + $sql="select hostid,templateid,graphs from hosts_templates where hostid=$hostid and templateid=".$item["hostid"]; + } $result=DBselect($sql); while($row=DBfetch($result)) { @@ -136,7 +143,7 @@ $sql="select distinct g.graphid from graphs g,graphs_items gi,items i where i.itemid=gi.itemid and i.hostid=".$row["hostid"]." and g.graphid=gi.graphid and g.name='".addslashes($graph["name"])."'"; $result2=DBselect($sql); - $host=get_host_by_hostid($result["hostid"]); + $host=get_host_by_hostid($row["hostid"]); while($row2=DBfetch($result2)) { add_item_to_graph($row2["graphid"],$itemid,$graph_item["color"],$graph_item["drawtype"],$graph_item["sortorder"]); diff --git a/frontends/php/include/hosts.inc.php b/frontends/php/include/hosts.inc.php index 854d244b..cbab17ee 100644 --- a/frontends/php/include/hosts.inc.php +++ b/frontends/php/include/hosts.inc.php @@ -65,7 +65,6 @@ if($host_templateid != 0) { add_templates_to_host($hostid,$host_templateid); -// $result=add_using_host_template($hostid,$host_templateid); sync_host_with_templates($hostid); } update_host_groups($hostid,$groups); diff --git a/frontends/php/include/items.inc.php b/frontends/php/include/items.inc.php index b58a4685..7b03f235 100644 --- a/frontends/php/include/items.inc.php +++ b/frontends/php/include/items.inc.php @@ -186,7 +186,7 @@ # Add item to hardlinked hosts - function add_item_to_templates($itemid) + function add_item_to_linked_hosts($itemid,$hostid=0) { if($itemid<=0) { @@ -195,7 +195,15 @@ $item=get_item_by_itemid($itemid); - $sql="select hostid,templateid,items from hosts_templates where templateid=".$item["hostid"]; + // Link with one host only + if($hostid!=0) + { + $sql="select hostid,templateid,items from hosts_templates where hostid=$hostid and templateid=".$item["hostid"]; + } + else + { + $sql="select hostid,templateid,items from hosts_templates where templateid=".$item["hostid"]; + } $result=DBselect($sql); while($row=DBfetch($result)) { diff --git a/frontends/php/include/triggers.inc.php b/frontends/php/include/triggers.inc.php index 59ea982d..a5a88820 100644 --- a/frontends/php/include/triggers.inc.php +++ b/frontends/php/include/triggers.inc.php @@ -329,7 +329,7 @@ where h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=$triggerid"; # Add item to hardlinked hosts - function add_trigger_to_templates($triggerid) + function add_trigger_to_linked_hosts($triggerid,$hostid=0) { if($triggerid<=0) { @@ -347,9 +347,15 @@ where h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=$triggerid"; $row=DBfetch($result); - $hostid=$row["hostid"]; - - $sql="select hostid,templateid,triggers from hosts_templates where templateid=$hostid"; + if($hostid==0) + { + $sql="select hostid,templateid,triggers from hosts_templates where templateid=".$row["hostid"]; + } + // Link to one host only + else + { + $sql="select hostid,templateid,triggers from hosts_templates where hostid=$hostid and templateid=".$row["hostid"]; + } $result=DBselect($sql); // Loop: linked hosts while($row=DBfetch($result)) |
