summaryrefslogtreecommitdiffstats
path: root/frontends/php
diff options
context:
space:
mode:
Diffstat (limited to 'frontends/php')
-rw-r--r--frontends/php/actions.php2
-rw-r--r--frontends/php/graph.php2
-rw-r--r--frontends/php/hosts.php9
-rw-r--r--frontends/php/include/actions.inc.php18
-rw-r--r--frontends/php/include/config.inc.php160
-rw-r--r--frontends/php/include/graphs.inc.php13
-rw-r--r--frontends/php/include/hosts.inc.php1
-rw-r--r--frontends/php/include/items.inc.php12
-rw-r--r--frontends/php/include/triggers.inc.php14
-rw-r--r--frontends/php/items.php2
-rw-r--r--frontends/php/triggers.php2
11 files changed, 71 insertions, 164 deletions
diff --git a/frontends/php/actions.php b/frontends/php/actions.php
index f4119249..8ae3d9c9 100644
--- a/frontends/php/actions.php
+++ b/frontends/php/actions.php
@@ -41,7 +41,7 @@
if($_GET["register"]=="add")
{
$actionid=add_action( $_GET["triggerid"], $_GET["userid"], $_GET["good"], $_GET["delay"], $_GET["subject"], $_GET["message"],$_GET["scope"],$_GET["severity"],$_GET["recipient"],$_GET["usrgrpid"]);
- add_action_to_templates($actionid);
+ add_action_to_linked_hosts($actionid);
show_messages($actionid,S_ACTION_ADDED,S_CANNOT_ADD_ACTION);
if($actionid)
{
diff --git a/frontends/php/graph.php b/frontends/php/graph.php
index 6c331ceb..3584f112 100644
--- a/frontends/php/graph.php
+++ b/frontends/php/graph.php
@@ -48,7 +48,7 @@
$gitemid=add_item_to_graph($_GET["graphid"],$_GET["itemid"],$_GET["color"],$_GET["drawtype"],$_GET["sortorder"]);
if($gitemid)
{
- add_graph_item_to_templates($gitemid);
+ add_graph_item_to_linked_hosts($gitemid);
$graph=get_graph_by_graphid($_GET["graphid"]);
$item=get_item_by_itemid($_GET["itemid"]);
add_audit(AUDIT_ACTION_ADD,AUDIT_RESOURCE_GRAPH_ELEMENT,"Graph ID [".$_GET["graphid"]."] Name [".$graph["name"]."] Added [".$item["description"]."]");
diff --git a/frontends/php/hosts.php b/frontends/php/hosts.php
index c995b487..1da7a166 100644
--- a/frontends/php/hosts.php
+++ b/frontends/php/hosts.php
@@ -131,12 +131,6 @@
add_audit(AUDIT_ACTION_ADD,AUDIT_RESOURCE_HOST,"Host [".addslashes($_GET["host"])."] IP [".$_GET["ip"]."] Status [".$_GET["status"]."]");
unset($_GET["hostid"]);
}
- if($_GET["register"]=="add items from template")
- {
- $result=add_using_host_template($_GET["hostid"],$_GET["host_templateid"]);
- show_messages($result, S_ITEMS_ADDED, S_CANNOT_ADD_ITEMS);
- unset($_GET["hostid"]);
- }
if($_GET["register"]=="update")
{
$groups=array();
@@ -464,6 +458,7 @@
{
continue;
}
+ $id="<INPUT TYPE=\"CHECKBOX\" class=\"biginput\" NAME=\"".$row["hostid"]."\"> ".$row["hostid"];
$host="<a href=\"items.php?hostid=".$row["hostid"]."\">".$row["host"]."</a>";
if($row["useip"]==1)
@@ -544,7 +539,7 @@
$actions=S_CHANGE;
}
table_row(array(
- $row["hostid"],
+ $id,
$host,
$ip,
$row["port"],
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))
diff --git a/frontends/php/items.php b/frontends/php/items.php
index 1c7b2bda..06437251 100644
--- a/frontends/php/items.php
+++ b/frontends/php/items.php
@@ -97,7 +97,7 @@
if($_GET["register"]=="add")
{
$itemid=add_item($_GET["description"],$_GET["key"],$_GET["hostid"],$_GET["delay"],$_GET["history"],$_GET["status"],$_GET["type"],$_GET["snmp_community"],$_GET["snmp_oid"],$_GET["value_type"],$_GET["trapper_hosts"],$_GET["snmp_port"],$_GET["units"],$_GET["multiplier"],$_GET["delta"],$_GET["snmpv3_securityname"],$_GET["snmpv3_securitylevel"],$_GET["snmpv3_authpassphrase"],$_GET["snmpv3_privpassphrase"],$_GET["formula"],$_GET["trends"]);
- add_item_to_templates($itemid);
+ add_item_to_linked_hosts($itemid);
show_messages($itemid, S_ITEM_ADDED, S_CANNOT_ADD_ITEM);
unset($_GET["itemid"]);
unset($itemid);
diff --git a/frontends/php/triggers.php b/frontends/php/triggers.php
index 3f9b6a5a..d0666e7e 100644
--- a/frontends/php/triggers.php
+++ b/frontends/php/triggers.php
@@ -135,7 +135,7 @@
else { $status=0; }
$triggerid=add_trigger($_GET["expression"],$_GET["description"],$_GET["priority"],$status,$_GET["comments"],$_GET["url"]);
- add_trigger_to_templates($triggerid);
+ add_trigger_to_linked_hosts($triggerid);
show_messages($triggerid, S_TRIGGER_ADDED, S_CANNOT_ADD_TRIGGER);
}
else