summaryrefslogtreecommitdiffstats
path: root/frontends/php
diff options
context:
space:
mode:
authorjames_wells <james_wells@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2005-11-18 15:53:10 +0000
committerjames_wells <james_wells@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2005-11-18 15:53:10 +0000
commit4459b7022bc533e60f236a5d483ac415eac2adf2 (patch)
treec2cda90a70f9c51495a68c9c0ba63d6bfc7bf82a /frontends/php
parentf7c2b61c66cc33bb15842c4db07b145ace7ba7e9 (diff)
downloadzabbix-4459b7022bc533e60f236a5d483ac415eac2adf2.tar.gz
zabbix-4459b7022bc533e60f236a5d483ac415eac2adf2.tar.xz
zabbix-4459b7022bc533e60f236a5d483ac415eac2adf2.zip
Cleaned up the host and user bulk loader a bit.
bulkloader.php include/bulkloader.inc.php include/hosts.inc.php git-svn-id: svn://svn.zabbix.com/trunk@2335 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php')
-rw-r--r--frontends/php/bulkloader.php33
-rw-r--r--frontends/php/include/bulkloader.inc.php22
-rw-r--r--frontends/php/include/hosts.inc.php5
3 files changed, 35 insertions, 25 deletions
diff --git a/frontends/php/bulkloader.php b/frontends/php/bulkloader.php
index bddb58f7..2f14594d 100644
--- a/frontends/php/bulkloader.php
+++ b/frontends/php/bulkloader.php
@@ -109,30 +109,23 @@
$hostServer=1;
}
- // Determine which group(s) this host belongs to, create any group(s) necessary;
- $hostGroups=array();
- $groupnum=0;
- foreach(explode(',',rtrim(rtrim($tmpHostGroups," "),"\n")) as $tmpGroup)
+ // Now that we have all the values we need process them for this host
+ $result=add_host($tmpHost,$hostPort,$hostStat,$hostUseIP,$tmpHostIP,$hostTemplate,'','');
+ show_messages($result,'Host added: '. $tmpHost,'Cannot add host: '. $tmpHost);;
+
+ // Here we update the hosts_groups manually. This will create new groups if needed
+ // And add this host to any group listed.
+ $row=DBfetch(DBselect("select distinct(hostid) from hosts where host='$tmpHost'"));
+ $tmpHostID=$row["hostid"];
+ if($tmpHostID)
{
- $groupnum++;
- $sqlResult=DBselect("select distinct(groupid) from groups where name='$tmpGroup'");
- if(DBnum_rows($sqlResult)==0)
- {
- // Create new group
- $hostGroups=array_merge($hostGroups,array(create_Host_Group($tmpGroup)));
- }
- else
+ foreach(explode(',',rtrim(rtrim($tmpHostGroups," "),"\n")) as $tmpGroup)
{
- // Found Existing Group;
- $row=DBfetch($sqlResult);
- $hostGroups=array_merge($hostGroups,array($row["groupid"]));
+ $tmpGroupID=create_Host_Group($tmpGroup);
+ add_Host_To_Group($tmpGroupID,$tmpHostID);
}
}
-
- // Now that we have all the values we need process them for this host
- $result=add_host($tmpHost,$hostPort,$hostStat,$hostUseIP,$tmpHostIP,$hostTemplate,'',$hostGroups);
- show_messages($result,'Host added: '. $tmpHost,'Cannot add host: '. $tmpHost);;
- DBselect("update hosts set serverid=$hostServer where host='$tmpHost'");
+ DBexecute("update hosts set serverid=$hostServer where hostid='$tmpHostID'");
break;
case "USER":
list($tmpName,$tmpSurname,$tmpAlias,$tmpPasswd,$tmpURL,$tmpAutologout,$tmpLang,$tmpRefresh,$tmpUserGroups) = explode(",",$tmpField,9);
diff --git a/frontends/php/include/bulkloader.inc.php b/frontends/php/include/bulkloader.inc.php
index a8a1a9aa..c03be61b 100644
--- a/frontends/php/include/bulkloader.inc.php
+++ b/frontends/php/include/bulkloader.inc.php
@@ -28,8 +28,7 @@ include_once "include/config.inc.php";
// Returns: 0 if unable to create, otherwise it returns the groupID
function create_Host_Group($group)
{
- $sql="select * from groups where name='$group'";
- $result=DBselect("select distinct(groupid) from groups where name='$name'");
+ $result=DBselect("select distinct(groupid) from groups where name='$group'");
if(DBnum_rows($result)>0)
{
$row=DBfetch($result);
@@ -47,11 +46,26 @@ include_once "include/config.inc.php";
}
}
+ // This function adds host to a host group based on ID numbers.
+ // Returns: 0 on failure, otherwise it returns 1
+ function add_Host_To_Group($groupid=0,$hostid=0)
+ {
+ if($groupid==0||$hostid==0)
+ {
+ return 0;
+ }
+ $result=DBexecute("insert into hosts_groups (groupid,hostid) values ($groupid,$hostid)");
+ if($result)
+ {
+ return 1;
+ }
+ return 0;
+ }
+
// This function takes a user group name and populates the database.
// Returns: 0 if unable to create, otherwise it returns the groupID
function create_User_Group($group)
{
- $sql="select * from groups where name='$group'";
$result=DBselect("select distinct(usrgrpid) from usrgrp where name='$group'");
if(DBnum_rows($result)>0)
{
@@ -66,7 +80,7 @@ include_once "include/config.inc.php";
}
else
{
- return 0;
+ return 0;
}
}
diff --git a/frontends/php/include/hosts.inc.php b/frontends/php/include/hosts.inc.php
index d3ce51a8..87f67db6 100644
--- a/frontends/php/include/hosts.inc.php
+++ b/frontends/php/include/hosts.inc.php
@@ -67,7 +67,10 @@
add_templates_to_host($hostid,$host_templateid);
sync_host_with_templates($hostid);
}
- update_host_groups($hostid,$groups);
+ if($groups != "")
+ {
+ update_host_groups($hostid,$groups);
+ }
if($newgroup != "")
{
add_group_to_host($hostid,$newgroup);