--- frontend-node2/api/classes/class.chost.php	2013-07-26 10:50:53.000000000 +0200
+++ frontend/api/classes/class.chost.php	2013-09-30 14:07:14.000000000 +0200
@@ -1063,6 +1063,7 @@
  * @param int $hosts['ipmi_privilege'] IPMI privilege. OPTIONAL
  * @param string $hosts['ipmi_username'] IPMI username. OPTIONAL
  * @param string $hosts['ipmi_password'] IPMI password. OPTIONAL
+ * @param int $hosts['nodeids'] Node ID. OPTIONAL
  * @return boolean
  */
 	public static function create($hosts){
@@ -1096,8 +1097,14 @@
 
 			foreach($hosts as $host){
 				self::validate($host);
+				
+				if(isset($host['nodeids'])) {
+					$hostid = get_dbid('hosts', 'hostid', $host['nodeids']);
+				}
+				else{
+					$hostid = get_dbid('hosts', 'hostid');
+				}
 
-				$hostid = get_dbid('hosts', 'hostid');
 				$hostids[] = $hostid;
 				$result = DBexecute('INSERT INTO hosts (hostid, proxy_hostid, host, port, status, useip, dns, ip, disable_until, available,'.
 					'useipmi,ipmi_port,ipmi_authtype,ipmi_privilege,ipmi_username,ipmi_password,ipmi_ip) VALUES ('.
@@ -1814,11 +1821,12 @@
 			if (CTemplate::exists(array('host' => $host['host']))) {
 				self::exception(ZBX_API_ERROR_PARAMETERS, S_TEMPLATE.' [ '.$host['host'].' ] '.S_ALREADY_EXISTS_SMALL);
 			}
-			// check if a different host with the same name exists
+			// check if a different host with the same name exists on the same node
 			$options = array(
 				'filter' => array(
 					'host' => $host['host']),
 				'output' => API_OUTPUT_SHORTEN,
+				'nodeids' => $host['nodeids'],
 				'nopermissions' => true
 			);
 			$host_exists = self::get($options);
--- frontend-node2/api/classes/class.chost.php	2013-07-26 10:50:53.000000000 +0200
+++ frontend/api/classes/class.chost.php	2013-09-30 14:08:38.000000000 +0200
@@ -1063,6 +1063,7 @@
  * @param int $hosts['ipmi_privilege'] IPMI privilege. OPTIONAL
  * @param string $hosts['ipmi_username'] IPMI username. OPTIONAL
  * @param string $hosts['ipmi_password'] IPMI password. OPTIONAL
+ * @param int $hosts['nodeids'] Node ID. OPTIONAL
  * @return boolean
  */
 	public static function create($hosts){
@@ -1096,8 +1097,13 @@
 
 			foreach($hosts as $host){
 				self::validate($host);
-
-				$hostid = get_dbid('hosts', 'hostid');
+				
+				if(isset($host['nodeids'])) {
+					$hostid = get_dbid('hosts', 'hostid', $host['nodeids']);
+				}
+				else{
+					$hostid = get_dbid('hosts', 'hostid');
+				}
 				$hostids[] = $hostid;
 				$result = DBexecute('INSERT INTO hosts (hostid, proxy_hostid, host, port, status, useip, dns, ip, disable_until, available,'.
 					'useipmi,ipmi_port,ipmi_authtype,ipmi_privilege,ipmi_username,ipmi_password,ipmi_ip) VALUES ('.
@@ -1814,11 +1820,12 @@
 			if (CTemplate::exists(array('host' => $host['host']))) {
 				self::exception(ZBX_API_ERROR_PARAMETERS, S_TEMPLATE.' [ '.$host['host'].' ] '.S_ALREADY_EXISTS_SMALL);
 			}
-			// check if a different host with the same name exists
+			// check if a different host with the same name exists on the same node
 			$options = array(
 				'filter' => array(
 					'host' => $host['host']),
 				'output' => API_OUTPUT_SHORTEN,
+				'nodeids' => $host['nodeids'],
 				'nopermissions' => true
 			);
 			$host_exists = self::get($options);
--- frontend-node2/include/db.inc.php	2013-07-26 10:50:52.000000000 +0200
+++ frontend/include/db.inc.php	2013-09-30 13:19:31.000000000 +0200
@@ -826,7 +826,7 @@
 
 		$sql = '';
 		foreach($nodes as $nnum => $nodeid){
-			$sql.= '('.$id_name.'  BETWEEN '.$nodeid.'00000000000000 AND '.$nodeid.'99999999999999)';
+			$sql.= '('.$id_name.'  BETWEEN '.$nodeid.'00000000000000 AND '.$nodeid.'999999999999999)';
 			$sql.= ' OR ';
 		}
 
@@ -857,12 +857,17 @@
 	return uint_in_array(id2nodeid($id_var), $nodes);
 	}
 
-	function get_dbid($table,$field){
+	function get_dbid($table,$field,$node=NULL){
 // PGSQL on transaction failure on all queries returns false..
 		global $DB, $ZBX_LOCALNODEID;
 		if(($DB['TYPE'] == 'POSTGRESQL') && $DB['TRANSACTIONS'] && !$DB['TRANSACTION_STATE']) return 0;
 //------
-		$nodeid = get_current_nodeid(false);
+		if($node!==NULL){
+			$nodeid=$node;
+		}
+		else{
+			$nodeid = get_current_nodeid(false);
+		}
 
 		$found = false;
 
