diff options
Diffstat (limited to 'frontends')
44 files changed, 320 insertions, 144 deletions
diff --git a/frontends/php/actionconf.php b/frontends/php/actionconf.php index afc9a1a6..d28bcbd6 100644 --- a/frontends/php/actionconf.php +++ b/frontends/php/actionconf.php @@ -179,7 +179,8 @@ /* GROUP ACTIONS */ elseif(isset($_REQUEST["group_enable"])&&isset($_REQUEST["g_actionid"])) { - $result=DBselect("select distinct actionid from actions"); + $result=DBselect("select distinct actionid from actions". + " where mod(actionid,100)=".$ZBX_CURNODEID); while($row=DBfetch($result)) { if(!in_array($row["actionid"], $_REQUEST["g_actionid"])) continue; @@ -190,7 +191,8 @@ } elseif(isset($_REQUEST["group_disable"])&&isset($_REQUEST["g_actionid"])) { - $result=DBselect("select distinct actionid from actions"); + $result=DBselect("select distinct actionid from actions". + " where mod(actionid,100)=".$ZBX_CURNODEID); while($row=DBfetch($result)) { if(!in_array($row["actionid"], $_REQUEST["g_actionid"])) continue; @@ -201,7 +203,8 @@ } elseif(isset($_REQUEST["group_delete"])&&isset($_REQUEST["g_actionid"])) { - $result=DBselect("select distinct actionid from actions"); + $result=DBselect("select distinct actionid from actions". + " where mod(actionid,100)=".$ZBX_CURNODEID); while($row=DBfetch($result)) { if(!in_array($row["actionid"], $_REQUEST["g_actionid"])) continue; @@ -250,7 +253,9 @@ S_REPEATS, S_STATUS)); - $result=DBselect("select * from actions where actiontype=".$_REQUEST["actiontype"]." order by actiontype, source"); + $result=DBselect("select * from actions where actiontype=".$_REQUEST["actiontype"]. + " and mod(actionid,100)=".$ZBX_CURNODEID. + " order by actiontype, source"); while($row=DBfetch($result)) { $conditions=""; diff --git a/frontends/php/audit.php b/frontends/php/audit.php index d38f4153..c89f62c1 100644 --- a/frontends/php/audit.php +++ b/frontends/php/audit.php @@ -75,13 +75,15 @@ if(!isset($_REQUEST["start"])) { $sql="select u.alias,a.clock,a.action,a.resourcetype,a.details from auditlog a, users u". - " where u.userid=a.userid and a.auditid>$maxauditid-200 order by clock desc"; + " where u.userid=a.userid and a.auditid>$maxauditid-200 order by clock desc". + " and mod(u.userid,100)=".$ZBX_CURNODEID; $limit = 200; } else { $sql="select u.alias,a.clock,a.action,a.resourcetype,a.details from auditlog a, users u". " where u.userid=a.userid and a.auditid>$maxauditid-".($_REQUEST["start"]+200). + " and mod(u.userid,100)=".$ZBX_CURNODEID. " order by clock desc"; $limit = $_REQUEST["start"]+200; diff --git a/frontends/php/bulkloader.php b/frontends/php/bulkloader.php index 07bd1be3..de5b2edc 100644 --- a/frontends/php/bulkloader.php +++ b/frontends/php/bulkloader.php @@ -87,7 +87,8 @@ // Determine which template, if any this host is linked to $sqlResult=DBselect("select distinct(hostid) from hosts where status=". HOST_STATUS_TEMPLATE . - " and host=".zbx_dbstr($tmpHostTemplate)); + " and host=".zbx_dbstr($tmpHostTemplate). + " and mod(hostid,100)=".$ZBX_CURNODEID; $row=DBfetch($sqlResult); if($row) { @@ -103,7 +104,8 @@ foreach(explode(',',rtrim(rtrim($tmpHostGroups," "),"\n")) as $group_name) { add_host_group($group_name); - $groupid = DBfetch(DBselect("select groupid from groups where name=".zbx_dbstr($group_name))); + $groupid = DBfetch(DBselect("select groupid from groups where name=".zbx_dbstr($group_name). + " and mod(groupid,100)=".$ZBX_CURNODEID; if(!$groupid) continue; array_push($groups,$groupid["groupid"]); } diff --git a/frontends/php/charts.php b/frontends/php/charts.php index 2b665b1d..6a1fcadd 100644 --- a/frontends/php/charts.php +++ b/frontends/php/charts.php @@ -108,7 +108,7 @@ $h2=S_GROUP.SPACE; $h2=$h2."<select class=\"biginput\" name=\"groupid\" onChange=\"submit()\">"; $h2=$h2.form_select("groupid",0,S_ALL_SMALL); - $result=DBselect("select groupid,name from groups order by name"); + $result=DBselect("select groupid,name from groups where mod(groupid,100)=$ZBX_CURNODEID order by name"); while($row=DBfetch($result)) { // Check if at least one host with read permission exists for this group @@ -140,7 +140,7 @@ { $h2=$h2.form_select("hostid",0,S_ALL_SMALL); - $sql="select h.hostid,h.host from hosts h,items i where h.status=".HOST_STATUS_MONITORED." and h.hostid=i.hostid group by h.hostid,h.host order by h.host"; + $sql="select h.hostid,h.host from hosts h,items i where h.status=".HOST_STATUS_MONITORED." and h.hostid=i.hostid and mod(h.hostid,100)=$ZBX_CURNODEID group by h.hostid,h.host order by h.host"; } $result=DBselect($sql); @@ -180,6 +180,7 @@ $sql = "select distinct g.graphid,g.name from graphs g,graphs_items gi,items i,hosts h". " where i.itemid=gi.itemid and g.graphid=gi.graphid ". " and i.hostid=h.hostid and h.status=".HOST_STATUS_MONITORED. + " and mod(h.hostid,100)=".$ZBX_CURNODEID. " order by g.name"; } diff --git a/frontends/php/config.php b/frontends/php/config.php index 9b9af34d..53e3e1f1 100644 --- a/frontends/php/config.php +++ b/frontends/php/config.php @@ -405,7 +405,9 @@ $table->setHeader(array(S_DESCRIPTION,S_TYPE)); $result=DBselect("select mt.mediatypeid,mt.type,mt.description,mt.smtp_server,". - "mt.smtp_helo,mt.smtp_email,mt.exec_path from media_type mt order by mt.type"); + "mt.smtp_helo,mt.smtp_email,mt.exec_path from media_type mt". + " where mod(mt.mediatypeid,100)=".$ZBX_CURNODEID. + " order by mt.type"); while($row=DBfetch($result)) { $description=new CLink($row["description"],"config.php?&form=update". @@ -437,7 +439,9 @@ $table=new CTableInfo(S_NO_IMAGES_DEFINED); $table->setHeader(array(S_ID,S_NAME,S_TYPE,S_IMAGE)); - $result=DBselect("select imageid,imagetype,name from images order by name"); + $result=DBselect("select imageid,imagetype,name from images". + " where mod(imageid,100)=".$ZBX_CURNODEID. + " order by name"); while($row=DBfetch($result)) { if($row["imagetype"]==1) $imagetype=S_ICON; @@ -472,7 +476,9 @@ $table=new CTableInfo(S_NO_AUTOREGISTRATION_RULES_DEFINED); $table->setHeader(array(S_ID,S_PRIORITY,S_PATTERN,S_HOST)); - $result=DBselect("select * from autoreg order by priority"); + $result=DBselect("select * from autoreg". + " where mod(id,100)=".$ZBX_CURNODEID. + " order by priority"); while($row=DBfetch($result)) { if($row["hostid"]==0) @@ -514,7 +520,8 @@ { $mappings_row = array(); $db_maps = DBselect("select * from mappings". - " where valuemapid=".$db_valuemap["valuemapid"]); + " where valuemapid=".$db_valuemap["valuemapid"]. + " and mod(valuemapid,100)=".$ZBX_CURNODEID); while($db_map = DBfetch($db_maps)) { array_push($mappings_row, diff --git a/frontends/php/events.php b/frontends/php/events.php index 808fa693..8cdce0e4 100644 --- a/frontends/php/events.php +++ b/frontends/php/events.php @@ -69,7 +69,7 @@ $h2=S_GROUP.SPACE; $h2=$h2."<select class=\"biginput\" name=\"groupid\" onChange=\"submit()\">"; $h2=$h2.form_select("groupid",0,S_ALL_SMALL); - $result=DBselect("select groupid,name from groups order by name"); + $result=DBselect("select groupid,name from groups where mod(groupid,100)=$ZBX_CURNODEID order by name"); while($row=DBfetch($result)) { // Check if at least one host with read permission exists for this group @@ -102,7 +102,7 @@ } else { - $sql="select h.hostid,h.host from hosts h,items i where h.status=".HOST_STATUS_MONITORED." and h.hostid=i.hostid group by h.hostid,h.host order by h.host"; + $sql="select h.hostid,h.host from hosts h,items i where h.status=".HOST_STATUS_MONITORED." and h.hostid=i.hostid and mod(h.hostid,100)=$ZBX_CURNODEID group by h.hostid,h.host order by h.host"; } $result=DBselect($sql); diff --git a/frontends/php/graphs.php b/frontends/php/graphs.php index 50dde233..3ae5c9ac 100644 --- a/frontends/php/graphs.php +++ b/frontends/php/graphs.php @@ -202,7 +202,7 @@ $form->AddItem(S_GROUP.SPACE); $cmbGroup = new CComboBox("groupid",$_REQUEST["groupid"],"submit()"); $cmbGroup->AddItem(0,S_ALL_SMALL); - $result=DBselect("select groupid,name from groups order by name"); + $result=DBselect("select groupid,name from groups where mod(groupid,100)=$ZBX_CURNODEID order by name"); while($row=DBfetch($result)) { // Check if at least one host with read permission exists for this group @@ -237,6 +237,7 @@ { $sql="select h.hostid,h.host from hosts h,items i where h.hostid=i.hostid". " and h.status=".HOST_STATUS_MONITORED." group by h.hostid,h.host". + " and mod(h.hostid,100)=".$ZBX_CURNODEID. " order by h.host"; } @@ -276,7 +277,7 @@ } else { - $result=DBselect("select * from graphs g order by g.name"); + $result=DBselect("select * from graphs g where mod(graphid,100)=$ZBX_CURNODEID order by g.name"); } while($row=DBfetch($result)) { diff --git a/frontends/php/hostprofiles.php b/frontends/php/hostprofiles.php index 47537692..01701e3a 100644 --- a/frontends/php/hostprofiles.php +++ b/frontends/php/hostprofiles.php @@ -57,7 +57,7 @@ $cmbGroup = new CComboBox("groupid",get_request("groupid",0),"submit()"); $cmbGroup->AddItem(0,S_ALL_SMALL); - $result=DBselect("select groupid,name from groups order by name"); + $result=DBselect("select groupid,name from groups where mod(groupid,100)=$ZBX_CURNODEID order by name"); while($row=DBfetch($result)) { // Check if at least one host with read permission exists for this group @@ -89,7 +89,9 @@ { $cmbHost->AddItem(0,S_ALL_SMALL); $sql="select h.hostid,h.host from hosts h,items i where h.status=".HOST_STATUS_MONITORED. - " and h.hostid=i.hostid group by h.hostid,h.host order by h.host"; + " and h.hostid=i.hostid". + " and mod(h.hostid,100)=".$ZBX_CURNODEID. + " group by h.hostid,h.host order by h.host"; } $result=DBselect($sql); @@ -124,7 +126,8 @@ else { $sql="select h.hostid,h.host,p.name,p.os,p.serialno,p.tag,p.macaddress". - " from hosts h,hosts_profiles p where h.hostid=p.hostid order by h.host"; + " from hosts h,hosts_profiles p where h.hostid=p.hostid". + " and mod(h.hostid,100)=$ZBX_CURNODEID order by h.host"; } $result=DBselect($sql); diff --git a/frontends/php/hosts.php b/frontends/php/hosts.php index 2c2c87b6..2e2bc451 100644 --- a/frontends/php/hosts.php +++ b/frontends/php/hosts.php @@ -202,7 +202,7 @@ /* group operations */ $result = 0; $hosts = get_request("hosts",array()); - $db_hosts=DBselect("select hostid from hosts"); + $db_hosts=DBselect("select hostid from hosts where mod(hostid,100)=".$ZBX_CURNODEID); while($db_host=DBfetch($db_hosts)) { $host=get_host_by_hostid($db_host["hostid"]); @@ -226,7 +226,7 @@ $status = isset($_REQUEST["activate"]) ? HOST_STATUS_MONITORED : HOST_STATUS_NOT_MONITORED; $hosts = get_request("hosts",array()); - $db_hosts=DBselect("select hostid from hosts"); + $db_hosts=DBselect("select hostid from hosts where mod(hostid,100)=".$ZBX_CURNODEID); while($db_host=DBfetch($db_hosts)) { if(!in_array($db_host["hostid"],$hosts)) continue; @@ -296,7 +296,7 @@ $result = 0; $groups = get_request("groups",array()); - $db_groups=DBselect("select groupid, name from groups"); + $db_groups=DBselect("select groupid, name from groups where mod(groupid,100)=".$ZBX_CURNODEID); while($db_group=DBfetch($db_groups)) { if(!in_array($db_group["groupid"],$groups)) continue; @@ -319,7 +319,8 @@ $groups = get_request("groups",array()); $db_hosts=DBselect("select h.hostid, hg.groupid from hosts_groups hg, hosts h". - " where h.hostid=hg.hostid and h.status<>".HOST_STATUS_DELETED); + " where h.hostid=hg.hostid and h.status<>".HOST_STATUS_DELETED. + " and mod(h.hostid,100)=".$ZBX_CURNODEID); while($db_host=DBfetch($db_hosts)) { if(!in_array($db_host["groupid"],$groups)) continue; @@ -375,7 +376,7 @@ $result = 0; $applications = get_request("applications",array()); - $db_applications = DBselect("select applicationid from applications"); + $db_applications = DBselect("select applicationid from applications where mod(applicationid,100)=".$ZBX_CURNODEID); while($db_app = DBfetch($db_applications)) { if(!in_array($db_app["applicationid"],$applications)) continue; @@ -451,7 +452,9 @@ $cmbGroups = new CComboBox("groupid",get_request("groupid",0),"submit()"); $cmbGroups->AddItem(0,S_ALL_SMALL); - $result=DBselect("select groupid,name from groups order by name"); + $result=DBselect("select groupid,name from groups". + " where mod(groupid,100)=".$ZBX_CURNODEID. + " order by name"); while($row=DBfetch($result)) { // Check if at least one host with read permission exists for this group @@ -506,7 +509,7 @@ $sql .= " hosts h,hosts_groups hg where"; $sql .= " hg.groupid=".$_REQUEST["groupid"]." and hg.hostid=h.hostid and"; } else $sql .= " hosts h where"; - $sql .= " $status_filter order by h.host"; + $sql .= " $status_filter and mod(h.hostid,100)=$ZBX_CURNODEID order by h.host"; $result=DBselect($sql); @@ -636,7 +639,9 @@ S_NAME), S_MEMBERS)); - $db_groups=DBselect("select groupid,name from groups order by name"); + $db_groups=DBselect("select groupid,name from groups". + " where mod(groupid,100)=".$ZBX_CURNODEID. + " order by name"); while($db_group=DBfetch($db_groups)) { $db_hosts = DBselect("select distinct h.host, h.status". @@ -695,6 +700,7 @@ $table->SetHeader(array(S_TEMPLATES,S_HOSTS)); $templates = DBSelect("select * from hosts where status=".HOST_STATUS_TEMPLATE. + " and mod(hostid,100)=".$ZBX_CURNODEID. " order by host"); while($template = DBfetch($templates)) { @@ -742,7 +748,9 @@ $_REQUEST["groupid"] = get_request("groupid",0); $cmbGroup = new CComboBox("groupid",$_REQUEST["groupid"],"submit();"); $cmbGroup->AddItem(0,S_ALL_SMALL); - $result=DBselect("select groupid,name from groups order by name"); + $result=DBselect("select groupid,name from groups". + " where mod(groupid,100)=".$ZBX_CURNODEID. + " order by name"); while($row=DBfetch($result)) { // Check if at least one host with read permission exists for this group @@ -768,6 +776,7 @@ else { $sql="select h.hostid,h.host from hosts h where h.status<>".HOST_STATUS_DELETED. + " and mod(h.hostid,100)=".$ZBX_CURNODEID. " group by h.hostid,h.host order by h.host"; } diff --git a/frontends/php/include/acknow.inc.php b/frontends/php/include/acknow.inc.php index 3271394e..943d376f 100644 --- a/frontends/php/include/acknow.inc.php +++ b/frontends/php/include/acknow.inc.php @@ -39,8 +39,15 @@ if(!$result) return $result; - return DBexecute("insert into acknowledges (userid,alarmid,clock,message)". - " values ($userid,$alarmid,".time().",".zbx_dbstr($message).")"); + $acknowledgeid = get_dbid("acknowledges","acknowledgeid"); + + $result = DBexecute("insert into acknowledges (acknowledgeid,userid,alarmid,clock,message)". + " values ($acknowledgeid,$userid,$alarmid,".time().",".zbx_dbstr($message).")"); + + if(!$result) + return $result; + + return $acknowledgeid; } function set_alarm_acnowledged($alarmid) diff --git a/frontends/php/include/actions.inc.php b/frontends/php/include/actions.inc.php index f5324558..272235a1 100644 --- a/frontends/php/include/actions.inc.php +++ b/frontends/php/include/actions.inc.php @@ -56,11 +56,14 @@ $recipient = 0; if(!check_commands($scripts)) return FALSE; } - $sql="insert into actions (actiontype,userid,subject,message,recipient,". - "maxrepeats,repeatdelay,status,scripts) values ($actiontype,$userid,".zbx_dbstr($subject).",". + $actionid=get_dbid("actions","actionid"); + $sql="insert into actions (actionid,actiontype,userid,subject,message,recipient,". + "maxrepeats,repeatdelay,status,scripts) values ($actionid,$actiontype,$userid,".zbx_dbstr($subject).",". zbx_dbstr($message).",$recipient,$maxrepeats,$repeatdelay,$status,".zbx_dbstr($scripts).")"; $result=DBexecute($sql); - return DBinsert_id($result,"actions","actionid"); + if(!$result) + return $result; + return $actionid; } # Update Action @@ -358,9 +361,13 @@ function add_action_condition($actionid, $conditiontype, $operator, $value) { - $sql="insert into conditions (actionid,conditiontype,operator,value) values ($actionid,$conditiontype,$operator,".zbx_dbstr($value).")"; + $conditionid=get_dbid("conditions","conditionid"); + $sql="insert into conditions (conditionid,actionid,conditiontype,operator,value)". + " values ($conditionid,$actionid,$conditiontype,$operator,".zbx_dbstr($value).")"; $result=DBexecute($sql); - return DBinsert_id($result,"conditions","conditionid"); + if(!$result) + return $result; + return $conditionid; } function update_action_status($actionid, $status) diff --git a/frontends/php/include/audit.inc.php b/frontends/php/include/audit.inc.php index b23d0fa3..b36b56de 100644 --- a/frontends/php/include/audit.inc.php +++ b/frontends/php/include/audit.inc.php @@ -25,7 +25,11 @@ $userid=$USER_DETAILS["userid"]; $clock=time(); - $sql="insert into auditlog (userid,clock,action,resourcetype,details) values ($userid,$clock,$action,$resourcetype,".zbx_dbstr($details).")"; - return DBexecute($sql); + $auditlogid = get_dbid("auditlog","auditlogid"); + $sql="insert into auditlog (auditlogid,userid,clock,action,resourcetype,details) values ($auditlogid,$userid,$clock,$action,$resourcetype,".zbx_dbstr($details).")"; + $result = DBexecute($sql); + if(!$result) + return $result; + return $auditlogid; } ?> diff --git a/frontends/php/include/autoregistration.inc.php b/frontends/php/include/autoregistration.inc.php index 5e5019b1..1e1b87f0 100644 --- a/frontends/php/include/autoregistration.inc.php +++ b/frontends/php/include/autoregistration.inc.php @@ -28,15 +28,17 @@ error("Insufficient permissions"); return 0; } + $autoregid = get_dbid("autoreg","autoregid"); - $sql="insert into autoreg (pattern,priority,hostid) values (".zbx_dbstr($pattern).",$priority,$hostid)"; + $sql="insert into autoreg (autoregid,pattern,priority,hostid) values ($autoregid,".zbx_dbstr($pattern).",$priority,$hostid)"; $result=DBexecute($sql); if($result) { $host=get_host_by_hostid($hostid); info("Added new autoregistration rule for $pattern"); } - return DBinsert_id($result,"autoreg","id"); + else return $result; + return $autoregid; } # Update Autoregistration rule diff --git a/frontends/php/include/bulkloader.inc.php b/frontends/php/include/bulkloader.inc.php index 0175c167..1ab5abae 100644 --- a/frontends/php/include/bulkloader.inc.php +++ b/frontends/php/include/bulkloader.inc.php @@ -34,11 +34,12 @@ include_once "include/config.inc.php"; { return $row["groupid"]; } + $groupid = get_dbid("groups","groupid"); - $result=DBexecute("insert into groups (name) values (".zbx_dbstr($group).")"); + $result=DBexecute("insert into groups (groupid,name) values ($groupid,".zbx_dbstr($group).")"); if($result) { - return DBinsert_id($result,"groups","name"); + return $groupid; } else { @@ -57,10 +58,11 @@ include_once "include/config.inc.php"; return $row["usrgrpid"]; } - $result=DBexecute("insert into usrgrp (name) values ('$group')"); + $usrgrpid=get_dbid("usrgrp","usrgrpid"); + $result=DBexecute("insert into usrgrp (usrgrpid,name) values ($usrgrpid,'$group')"); if($result) { - return DBinsert_id($result,"usrgrp","name"); + return $usrgrpid; } else { @@ -76,10 +78,11 @@ include_once "include/config.inc.php"; { return 0; } - $result=DBexecute("insert into users_groups (usrgrpid,userid) values ($groupid,$userid)"); + $id=get_dbid("users_groups","id"); + $result=DBexecute("insert into users_groups (id,usrgrpid,userid) values ($id,$groupid,$userid)"); if($result) { - return 1; + return $id; } return 0; } diff --git a/frontends/php/include/config.inc.php b/frontends/php/include/config.inc.php index 12b99f7b..6b4fd6d9 100644 --- a/frontends/php/include/config.inc.php +++ b/frontends/php/include/config.inc.php @@ -395,6 +395,23 @@ document.writeln(snd_tag); return "$priorities,$md5sum"; } + function get_dbid($table,$field) + { + global $ZBX_CURNODEID; + + $sql="select max($field) as id from $table where mod($field,100)=$ZBX_CURNODEID"; + $result=DBselect($sql); + $row=DBfetch($result); + if($row && !is_null($row["id"])) + { + return $row["id"]+100; + } + else + { + return 100+$ZBX_CURNODEID; + } + } + function get_function_by_functionid($functionid) { $sql="select * from functions where functionid=$functionid"; @@ -1234,8 +1251,10 @@ COpt::profiling_start("page"); { $lobimage = OCINewDescriptor($DB, OCI_D_LOB); - $sql = "insert into images (name,imagetype,image)". - " values (".zbx_dbstr($name).",".$imagetype.",EMPTY_BLOB())". + $imageid=get_dbid("images","imageid"); + + $sql = "insert into images (imageid,name,imagetype,image)". + " values ($imageid,".zbx_dbstr($name).",".$imagetype.",EMPTY_BLOB())". " return image into :image"; $stid = OCIParse($DB, $sql); if(!$stid) @@ -1537,8 +1556,10 @@ COpt::profiling_start("page"); } else { - $sql="insert into media_type (type,description,smtp_server,smtp_helo,smtp_email,exec_path,gsm_modem) values ($type,".zbx_dbstr($description).",".zbx_dbstr($smtp_server).",".zbx_dbstr($smtp_helo).",".zbx_dbstr($smtp_email).",".zbx_dbstr($exec_path).",".zbx_dbstr($gsm_modem).")"; + $mediatypeid=get_dbid("media_type","mediatypeid"); + $sql="insert into media_type (mediatypeid,type,description,smtp_server,smtp_helo,smtp_email,exec_path,gsm_modem) values ($mediatypeid,$type,".zbx_dbstr($description).",".zbx_dbstr($smtp_server).",".zbx_dbstr($smtp_helo).",".zbx_dbstr($smtp_email).",".zbx_dbstr($exec_path).",".zbx_dbstr($gsm_modem).")"; $ret = DBexecute($sql); + if($ret) $ret = $mediatypeid; } return $ret; } @@ -1559,8 +1580,11 @@ COpt::profiling_start("page"); { $s=$s|pow(2,(int)$severity[$i]); } - $sql="insert into media (userid,mediatypeid,sendto,active,severity,period) values ($userid,".zbx_dbstr($mediatypeid).",".zbx_dbstr($sendto).",$active,$s,".zbx_dbstr($period).")"; - return DBexecute($sql); + $mediaid=get_dbid("media","mediaid"); + $sql="insert into media (mediaid,userid,mediatypeid,sendto,active,severity,period) values ($mediaid,$userid,".zbx_dbstr($mediatypeid).",".zbx_dbstr($sendto).",$active,$s,".zbx_dbstr($period).")"; + $ret = DBexecute($sql); + if($ret) $ret = $mediaid; + return $ret; } # Update Media definition @@ -2656,13 +2680,13 @@ COpt::profiling_stop("script"); function add_valuemap($name, $mappings) { if(!is_array($mappings)) return FALSE; + + $valuemapid = get_dbid("valuemaps","valuemapid"); - $result = DBexecute("insert into valuemaps (name) values (".zbx_dbstr($name).")"); + $result = DBexecute("insert into valuemaps (valuemapid,name) values ($valuemapid,".zbx_dbstr($name).")"); if(!$result) return $result; - $valuemapid = DBinsert_id($result,"valuemaps","valuemapid"); - $result = add_mapping_to_valuemap($valuemapid, $mappings); if(!$result){ delete_valuemap($valuemapid); diff --git a/frontends/php/include/db.inc.php b/frontends/php/include/db.inc.php index 65f4ef58..bf8c7364 100644 --- a/frontends/php/include/db.inc.php +++ b/frontends/php/include/db.inc.php @@ -26,13 +26,16 @@ // $DB_TYPE ="POSTGRESQL"; $DB_TYPE ="MYSQL"; $DB_SERVER ="localhost"; - $DB_DATABASE ="osmiy"; + $DB_DATABASE ="node4"; $DB_USER ="root"; $DB_PASSWORD =""; // END OF DATABASE CONFIGURATION global $USER_DETAILS; + $ZBX_CURNODEID = 4; // Selected node + $ZBX_LOCALNODEID = 4; // Local node + if($DB_TYPE == "MYSQL") { $DB=mysql_pconnect($DB_SERVER,$DB_USER,$DB_PASSWORD); diff --git a/frontends/php/include/forms.inc.php b/frontends/php/include/forms.inc.php index 441b04ea..a5a82dad 100644 --- a/frontends/php/include/forms.inc.php +++ b/frontends/php/include/forms.inc.php @@ -192,6 +192,7 @@ function insert_usergroups_form($usrgrpid) { global $_REQUEST; + global $ZBX_CURNODEID; $frm_title = S_USER_GROUP; if(isset($usrgrpid)) @@ -229,7 +230,9 @@ $frmUserG->AddRow(S_GROUP_NAME,new CTextBox("gname",$name,30)); $form_row = array(); - $db_users=DBselect("select distinct userid,alias from users order by alias"); + $db_users=DBselect("select distinct userid,alias from users". + " where mod(userid,100)=".$ZBX_CURNODEID. + " order by alias"); while($db_user=DBfetch($db_users)) { array_push($form_row, diff --git a/frontends/php/include/graphs.inc.php b/frontends/php/include/graphs.inc.php index df0ed17e..32803367 100644 --- a/frontends/php/include/graphs.inc.php +++ b/frontends/php/include/graphs.inc.php @@ -105,12 +105,13 @@ return 0; } + $graphid=get_dbid("graphs","graphid"); + $result=DBexecute("insert into graphs". - " (name,width,height,yaxistype,yaxismin,yaxismax,templateid,show_work_period,show_triggers,graphtype,templateid)". - " values (".zbx_dbstr($name).",$width,$height,$yaxistype,$yaxismin,". + " (graphid,name,width,height,yaxistype,yaxismin,yaxismax,templateid,show_work_period,show_triggers,graphtype,templateid)". + " values ($graphid,".zbx_dbstr($name).",$width,$height,$yaxistype,$yaxismin,". " $yaxismax,$templateid,$showworkperiod,$showtriggers,$graphtype,$templateid)"); - $graphid = DBinsert_id($result,"graphs","graphid"); - if($graphid) + if($result) { info("Graph '$name' added"); } @@ -208,11 +209,10 @@ function add_item_to_graph($graphid,$itemid,$color,$drawtype,$sortorder,$yaxisside,$calc_fnc,$type,$periods_cnt) { + $gitemid=get_dbid("graphs_items","gitemid"); $result = DBexecute("insert into graphs_items". - " (graphid,itemid,color,drawtype,sortorder,yaxisside,calc_fnc,type,periods_cnt)". - " values ($graphid,$itemid,".zbx_dbstr($color).",$drawtype,$sortorder,$yaxisside,$calc_fnc,$type,$periods_cnt)"); - - $gitemid = DBinsert_id($result,"graphs_items","gitemid"); + " (gitemid,graphid,itemid,color,drawtype,sortorder,yaxisside,calc_fnc,type,periods_cnt)". + " values ($gitemid,$graphid,$itemid,".zbx_dbstr($color).",$drawtype,$sortorder,$yaxisside,$calc_fnc,$type,$periods_cnt)"); $item = get_item_by_itemid($itemid); $graph = get_graph_by_graphid($graphid); diff --git a/frontends/php/include/hosts.inc.php b/frontends/php/include/hosts.inc.php index afb23fbd..de8de4e4 100644 --- a/frontends/php/include/hosts.inc.php +++ b/frontends/php/include/hosts.inc.php @@ -27,7 +27,11 @@ error("incorrect parameters for 'add_host_to_group'"); return FALSE; } - return DBexecute("insert into hosts_groups (hostid,groupid) values ($hostid,$groupid)"); + $hostgroupid=get_dbid("hosts_groups","hostgroupid"); + $result=DBexecute("insert into hosts_groups (hostgroupid,hostid,groupid) values ($hostgroupid,$hostid,$groupid)"); + if(!$result) + return $result; + return $hostgroupid; } function db_save_group($name,$groupid=NULL) @@ -49,7 +53,13 @@ return FALSE; } if($groupid==NULL) - return DBexecute("insert into groups (name) values (".zbx_dbstr($name).")"); + { + $groupid=get_dbid("groups","groupid"); + if(!DBexecute("insert into groups (name) values (".zbx_dbstr($name).")")) + return FALSE; + return $groupid; + + } else return DBexecute("update groups set name=".zbx_dbstr($name)." where groupid=$groupid"); } @@ -162,10 +172,12 @@ if($hostid==NULL) { + $hostid = get_dbid("hosts","hostid"); $result = DBexecute("insert into hosts". - " (host,port,status,useip,ip,disable_until,available,templateid)". - " values (".zbx_dbstr($host).",$port,$status,$useip,".zbx_dbstr($ip).",0," + " (hostid,host,port,status,useip,ip,disable_until,available,templateid)". + " values ($hostid,".zbx_dbstr($host).",$port,$status,$useip,".zbx_dbstr($ip).",0," .HOST_AVAILABLE_UNKNOWN.",$templateid)"); + if($result) $result = $hostid; } else { @@ -597,8 +609,9 @@ if($applicationid==NULL) { - if($result = DBexecute("insert into applications (name,hostid,templateid)". - " values (".zbx_dbstr($name).",$hostid,$templateid)")) + $applicationid_new = get_dbid("applications","applicationid"); + if($result = DBexecute("insert into applications (applicationid,name,hostid,templateid)". + " values ($applicationid_new,".zbx_dbstr($name).",$hostid,$templateid)")) info("Added new application ".$host["host"].":$name"); } else @@ -613,7 +626,7 @@ if($applicationid==NULL) { - $applicationid = DBinsert_id($result,"applications","applicationid"); + $applicationid = $applicationid_new; $db_childs = get_hosts_by_templateid($hostid); while($db_child = DBfetch($db_childs)) diff --git a/frontends/php/include/items.inc.php b/frontends/php/include/items.inc.php index a62e78c1..9acdeb93 100644 --- a/frontends/php/include/items.inc.php +++ b/frontends/php/include/items.inc.php @@ -168,12 +168,13 @@ } // first add mother item + $itemid=get_dbid("items","itemid"); $result=DBexecute("insert into items". - " (description,key_,hostid,delay,history,nextcheck,status,type,". + " (itemid,description,key_,hostid,delay,history,nextcheck,status,type,". "snmp_community,snmp_oid,value_type,trapper_hosts,snmp_port,units,multiplier,". "delta,snmpv3_securityname,snmpv3_securitylevel,snmpv3_authpassphrase,". "snmpv3_privpassphrase,formula,trends,logtimefmt,valuemapid,templateid)". - " values (".zbx_dbstr($description).",".zbx_dbstr($key).",$hostid,$delay,$history,0, + " values ($itemid,".zbx_dbstr($description).",".zbx_dbstr($key).",$hostid,$delay,$history,0, $status,$type,".zbx_dbstr($snmp_community).",".zbx_dbstr($snmp_oid).",$value_type,". zbx_dbstr($trapper_hosts).",$snmp_port,".zbx_dbstr($units).",$multiplier,$delta,". zbx_dbstr($snmpv3_securityname).",$snmpv3_securitylevel,". @@ -184,11 +185,10 @@ if(!$result) return $result; - $itemid = DBinsert_id($result,"items","itemid"); - foreach($applications as $appid) { - DBexecute("insert into items_applications (itemid,applicationid) values(".$itemid.",".$appid.")"); + $itemappid=get_dbid("items_applications","itemappid"); + DBexecute("insert into items_applications (itemappid,itemid,applicationid) values($itemappid,".$itemid.",".$appid.")"); } info("Added new item ".$host["host"].":$key"); @@ -321,7 +321,10 @@ $result = DBexecute("delete from items_applications where itemid=$itemid"); foreach($applications as $appid) - DBexecute("insert into items_applications (itemid,applicationid) values(".$itemid.",".$appid.")"); + { + $itemappid=get_dbid("items_applications","itemappid"); + DBexecute("insert into items_applications (itemappid,itemid,applicationid) values($itemappid,".$itemid.",".$appid.")"); + } $result=DBexecute( "update items set description=".zbx_dbstr($description).",key_=".zbx_dbstr($key).",". diff --git a/frontends/php/include/maps.inc.php b/frontends/php/include/maps.inc.php index 361824a4..42ffdd24 100644 --- a/frontends/php/include/maps.inc.php +++ b/frontends/php/include/maps.inc.php @@ -92,20 +92,34 @@ return 0; } - return DBexecute("insert into sysmaps (name,width,height,background,label_type,label_location)". - " values (".zbx_dbstr($name).",$width,$height,".zbx_dbstr($background).",$label_type, + $sysmapid=get_dbid("sysmaps","sysmapid"); + + $result=DBexecute("insert into sysmaps (sysmapid,name,width,height,background,label_type,label_location)". + " values ($sysmapid,".zbx_dbstr($name).",$width,$height,".zbx_dbstr($background).",$label_type, $label_location)"); + + if(!$result) + return $result; + + return $sysmapid; } function add_link($sysmapid,$selementid1,$selementid2,$triggerid,$drawtype_off,$color_off,$drawtype_on,$color_on) { if($triggerid == 0) $triggerid = 'NULL'; - return DBexecute("insert into sysmaps_links". - " (sysmapid,selementid1,selementid2,triggerid,drawtype_off,". + $linkid=get_dbid("sysmaps_links","linkid"); + + $result=DBexecute("insert into sysmaps_links". + " (linkid,sysmapid,selementid1,selementid2,triggerid,drawtype_off,". "color_off,drawtype_on,color_on)". - " values ($sysmapid,$selementid1,$selementid2,$triggerid,$drawtype_off,". + " values ($linkid,$sysmapid,$selementid1,$selementid2,$triggerid,$drawtype_off,". zbx_dbstr($color_off).",$drawtype_on,".zbx_dbstr($color_on).")"); + + if(!$result) + return $result; + + return $linkid; } function update_link($linkid,$sysmapid,$selementid1,$selementid2,$triggerid,$drawtype_off,$color_off,$drawtype_on,$color_on) @@ -153,11 +167,18 @@ return FALSE; } - return DBexecute("insert into sysmaps_elements". + $selementid = get_dbid("sysmaps_elements","selementid"); + + $result=DBexecute("insert into sysmaps_elements". " (sysmapid,elementid,elementtype,label,x,y,icon,url,icon_on,label_location)". " values ($sysmapid,$elementid,$elementtype,".zbx_dbstr($label).", $x,$y,".zbx_dbstr($icon).",".zbx_dbstr($url).",".zbx_dbstr($icon_on).",". "$label_location)"); + + if(!$result) + return $result; + + return $selementid; } # Update Element from system map diff --git a/frontends/php/include/perm.inc.php b/frontends/php/include/perm.inc.php index 38106733..0d09f82a 100644 --- a/frontends/php/include/perm.inc.php +++ b/frontends/php/include/perm.inc.php @@ -32,6 +32,7 @@ define("GROUP_RIGHT", 0); global $USER_RIGHTS; global $_COOKIE; global $_REQUEST; + global $ZBX_CURNODEID; $USER_DETAILS = NULL; $USER_RIGHTS = array(); @@ -41,7 +42,8 @@ define("GROUP_RIGHT", 0); $sessionid = $_COOKIE["sessionid"]; $USER_DETAILS = DBfetch(DBselect("select u.*,s.* from sessions s,users u". " where s.sessionid=".zbx_dbstr($sessionid)." and s.userid=u.userid". - " and ((s.lastaccess+u.autologout>".time().") or (u.autologout=0))")); + " and ((s.lastaccess+u.autologout>".time().") or (u.autologout=0))". + " and mod(u.userid,100) = ".$ZBX_CURNODEID)); if(!$USER_DETAILS) { @@ -57,7 +59,7 @@ define("GROUP_RIGHT", 0); exit; } } else { - $USER_DETAILS = DBfetch(DBselect("select u.* from users u where u.alias='guest'")); + $USER_DETAILS = DBfetch(DBselect("select u.* from users u where u.alias='guest' and mod(u.userid,100)=$ZBX_CURNODEID")); } if($USER_DETAILS) diff --git a/frontends/php/include/screens.inc.php b/frontends/php/include/screens.inc.php index fd6a9b30..d3f62644 100644 --- a/frontends/php/include/screens.inc.php +++ b/frontends/php/include/screens.inc.php @@ -27,8 +27,14 @@ return 0; } - $sql="insert into screens (name,hsize,vsize) values (".zbx_dbstr($name).",$hsize,$vsize)"; - return DBexecute($sql); + $screenid=get_dbid("screens","screenid"); + $sql="insert into screens (screenid,name,hsize,vsize) values ($screenid,".zbx_dbstr($name).",$hsize,$vsize)"; + $result=DBexecute($sql); + + if(!$result) + return $result; + + return $screenid; } function update_screen($screenid,$name,$hsize,$vsize) @@ -61,10 +67,16 @@ { $sql="delete from screens_items where screenid=$screenid and x=$x and y=$y"; DBexecute($sql); + $screenitemid=get_dbid("screens_items","screenitemid"); $sql="insert into screens_items (resourcetype,screenid,x,y,resourceid,width,height,colspan,rowspan,elements,valign,halign,style,url)". " values ($resourcetype,$screenid,$x,$y,$resourceid,$width,$height,$colspan,$rowspan,$elements,$valign,$halign,$style,". zbx_dbstr($url).")"; - return DBexecute($sql); + $result=DBexecute($sql); + + if(!$result) + return $result; + + return $screenitemid; } function update_screen_item($screenitemid,$resourcetype,$resourceid,$width,$height,$colspan,$rowspan,$elements,$valign,$halign,$style,$url) diff --git a/frontends/php/include/services.inc.php b/frontends/php/include/services.inc.php index 80dbe883..96f35f2f 100644 --- a/frontends/php/include/services.inc.php +++ b/frontends/php/include/services.inc.php @@ -23,14 +23,16 @@ { if(is_null($triggerid)) $triggerid = 'NULL'; - $sql="insert into services (name,status,triggerid,algorithm,showsla,goodsla,sortorder)". - " values (".zbx_dbstr($name).",0,$triggerid,".zbx_dbstr($algorithm).",$showsla,".zbx_dbstr($goodsla).",$sortorder)"; + $serviceid=get_dbid("services","serviceid"); + + $sql="insert into services (serviceid,name,status,triggerid,algorithm,showsla,goodsla,sortorder)". + " values ($serviceid,".zbx_dbstr($name).",0,$triggerid,".zbx_dbstr($algorithm).",$showsla,".zbx_dbstr($goodsla).",$sortorder)"; $result=DBexecute($sql); if(!$result) { return FALSE; } - return DBinsert_id($result,"services","serviceid"); + return $serviceid; } function update_service($serviceid,$name,$triggerid,$algorithm,$showsla,$goodsla,$sortorder) @@ -156,8 +158,15 @@ return false; } - $sql="insert into services_links (servicedownid,serviceupid,soft) values ($servicedownid,$serviceupid,$softlink)"; - return dbexecute($sql); + $linkid=get_dbid("services_links","linkid"); + + $sql="insert into services_links (linkid,servicedownid,serviceupid,soft) values ($linkid,$servicedownid,$serviceupid,$softlink)"; + $result=DBexecute($sql); + + if(!$result) + return $result; + + return $linkid; } function update_service_link($linkid,$servicedownid,$serviceupid,$softlink) { diff --git a/frontends/php/include/triggers.inc.php b/frontends/php/include/triggers.inc.php index 1fc8154b..7526b851 100644 --- a/frontends/php/include/triggers.inc.php +++ b/frontends/php/include/triggers.inc.php @@ -295,16 +295,17 @@ // } if(!is_null($expression)) if(validate_expression($expression)) return FALSE; + $triggerid=get_dbid("triggers","triggerid"); + $result=DBexecute("insert into triggers". - " (description,priority,status,comments,url,value,error,templateid)". - " values (".zbx_dbstr($description).",$priority,$status,".zbx_dbstr($comments).",". + " (triggerid,description,priority,status,comments,url,value,error,templateid)". + " values ($triggerid,".zbx_dbstr($description).",$priority,$status,".zbx_dbstr($comments).",". "".zbx_dbstr($url).",2,'Trigger just added. No status update so far.',$templateid)"); if(!$result) { return $result; } - $triggerid = DBinsert_id($result,"triggers","triggerid"); add_alarm($triggerid,TRIGGER_VALUE_UNKNOWN); $expression = implode_exp($expression,$triggerid); @@ -377,9 +378,11 @@ $copy_mode ? 0 : $triggerid); } + $newtriggerid=dn_getid("triggers","triggerid"); + $result = DBexecute("insert into triggers". - " (description,priority,status,comments,url,value,expression,templateid)". - " values (".zbx_dbstr($trigger["description"]).",".$trigger["priority"].",". + " (triggerid,description,priority,status,comments,url,value,expression,templateid)". + " values ($newtriggerid,".zbx_dbstr($trigger["description"]).",".$trigger["priority"].",". $trigger["status"].",".zbx_dbstr($trigger["comments"]).",". zbx_dbstr($trigger["url"]).",2,'{???:???}',". ($copy_mode ? 0 : $triggerid).")"); @@ -387,8 +390,6 @@ if(!$result) return $result; - $newtriggerid = DBinsert_id($result,"triggers","triggerid"); - $host = get_host_by_hostid($hostid); $newexpression = $trigger["expression"]; @@ -408,10 +409,11 @@ return FALSE; } - $result = DBexecute("insert into functions (itemid,triggerid,function,parameter)". - " values (".$host_item["itemid"].",$newtriggerid,". + $newfunctionid=get_dbid("functions","functionid"); + + $result = DBexecute("insert into functions (functionid,itemid,triggerid,function,parameter)". + " values ($newfunctionid,".$host_item["itemid"].",$newtriggerid,". zbx_dbstr($function["function"]).",".zbx_dbstr($function["parameter"]).")"); - $newfunctionid = DBinsert_id($result,"functions","functionid"); $newexpression = str_replace( "{".$function["functionid"]."}", diff --git a/frontends/php/include/users.inc.php b/frontends/php/include/users.inc.php index 19ea4281..0bdb19a6 100644 --- a/frontends/php/include/users.inc.php +++ b/frontends/php/include/users.inc.php @@ -43,8 +43,10 @@ } $passwd=md5($passwd); - $sql="insert into users (name,surname,alias,passwd,url,autologout,lang,refresh) values (".zbx_dbstr($name).",".zbx_dbstr($surname).",".zbx_dbstr($alias).",".zbx_dbstr($passwd).",".zbx_dbstr($url).",$autologout,".zbx_dbstr($lang).",$refresh)"; - return DBexecute($sql); + $userid = get_dbid("users","userid"); + $sql="insert into users (userid,name,surname,alias,passwd,url,autologout,lang,refresh) values ($userid,".zbx_dbstr($name).",".zbx_dbstr($surname).",".zbx_dbstr($alias).",".zbx_dbstr($passwd).",".zbx_dbstr($url).",$autologout,".zbx_dbstr($lang).",$refresh)"; + DBexecute($sql); + return $userid; } # Update User definition @@ -160,15 +162,15 @@ return 0; } - $sql="insert into usrgrp (name) values (".zbx_dbstr($name).")"; + $usrgrpid=get_dbid("usrgrp","usrgrpid"); + + $sql="insert into usrgrp (usrgrpid,name) values ($usrgrpid,".zbx_dbstr($name).")"; $result=DBexecute($sql); if(!$result) { return $result; } - $usrgrpid=DBinsert_id($result,"usrgrp","usrgrpid"); - update_user_groups($usrgrpid,$users); return $result; diff --git a/frontends/php/index.php b/frontends/php/index.php index 46d09532..abac0ec9 100644 --- a/frontends/php/index.php +++ b/frontends/php/index.php @@ -52,7 +52,8 @@ $password = md5(get_request("password","")); $result=DBselect("select u.userid,u.alias,u.name,u.surname,u.url,u.refresh from users u where". - " u.alias=".zbx_dbstr($name)." and u.passwd=".zbx_dbstr($password)); + " u.alias=".zbx_dbstr($name)." and u.passwd=".zbx_dbstr($password). + " and mod(u.userid,100)=".$ZBX_CURNODEID); $row=DBfetch($result); if($row) diff --git a/frontends/php/items.php b/frontends/php/items.php index b531d937..6fe0c480 100644 --- a/frontends/php/items.php +++ b/frontends/php/items.php @@ -347,7 +347,7 @@ show_header2(S_CONFIGURATION_OF_ITEMS_BIG, $form); echo BR; - $db_hosts=DBselect("select hostid from hosts"); + $db_hosts=DBselect("select hostid from hosts where mod(hostid,100)=$ZBX_CURNODEID"); if(isset($_REQUEST["form_copy_to"]) && isset($_REQUEST["group_itemid"])) { insert_copy_elements_to_forms("group_itemid"); @@ -363,7 +363,7 @@ $cmbGroup = new CComboBox("groupid",$_REQUEST["groupid"],"submit();"); $cmbGroup->AddItem(0,S_ALL_SMALL); - $result=DBselect("select groupid,name from groups order by name"); + $result=DBselect("select groupid,name from groups where mod(groupid,100)=$ZBX_CURNODEID order by name"); while($row=DBfetch($result)) { // Check if at least one host with read permission exists for this group @@ -389,6 +389,7 @@ else { $sql="select h.hostid,h.host from hosts h where h.status<>".HOST_STATUS_DELETED. + " and mod(h.hostid,100)=".$ZBX_CURNODEID. " group by h.hostid,h.host order by h.host"; } diff --git a/frontends/php/latest.php b/frontends/php/latest.php index 6eeb3c41..ade690f8 100644 --- a/frontends/php/latest.php +++ b/frontends/php/latest.php @@ -150,7 +150,7 @@ $cmbGroup = new CComboBox("groupid",$_REQUEST["groupid"],"submit()"); $cmbGroup->AddItem(0,S_ALL_SMALL); - $result=DBselect("select groupid,name from groups order by name"); + $result=DBselect("select groupid,name from groups where mod(groupid,100)=$ZBX_CURNODEID order by name"); while($row=DBfetch($result)) { // Check if at least one host with read permission exists for this group @@ -180,7 +180,9 @@ { $cmbHosts->AddItem(0,S_ALL_SMALL); $sql="select h.hostid,h.host from hosts h,items i where h.status=".HOST_STATUS_MONITORED. - " and i.status=".ITEM_STATUS_ACTIVE." and h.hostid=i.hostid group by h.hostid,h.host order by h.host"; + " and i.status=".ITEM_STATUS_ACTIVE." and h.hostid=i.hostid". + " and mod(h.hostid,100)=".$ZBX_CURNODEID. + " group by h.hostid,h.host order by h.host"; } $result=DBselect($sql); $first_hostid = -1; @@ -247,6 +249,7 @@ $any_app_exist = false; $db_applications = DBselect("select h.host,h.hostid,a.* from applications a,hosts h where a.hostid=h.hostid".$compare_host. + " and mod(h.hostid,100)=".$ZBX_CURNODEID. " order by a.name,a.applicationid,h.host"); while($db_app = DBfetch($db_applications)) { @@ -256,6 +259,7 @@ " where h.hostid=i.hostid and ia.applicationid=".$db_app["applicationid"]." and i.itemid=ia.itemid". " and h.status=".HOST_STATUS_MONITORED." and i.status=".ITEM_STATUS_ACTIVE. $compare_description.$compare_host. + " and mod(h.hostid,100)=".$ZBX_CURNODEID. " order by i.description"; $db_items = DBselect($sql); @@ -346,6 +350,7 @@ $sql="select h.host,h.hostid,i.* from hosts h, items i LEFT JOIN items_applications ia ON ia.itemid=i.itemid". " where ia.itemid is NULL and h.hostid=i.hostid and h.status=".HOST_STATUS_MONITORED." and i.status=".ITEM_STATUS_ACTIVE. $compare_description.$compare_host. + " and mod(h.hostid,100)=".$ZBX_CURNODEID. " order by i.description,h.host"; $db_items = DBselect($sql); diff --git a/frontends/php/maps.php b/frontends/php/maps.php index bd628901..0c192847 100644 --- a/frontends/php/maps.php +++ b/frontends/php/maps.php @@ -45,7 +45,7 @@ if($_REQUEST["sysmapid"] <=0 ) { - $db_sysmaps = DBselect("select sysmapid,name from sysmaps order by name"); + $db_sysmaps = DBselect("select sysmapid,name from sysmaps where mod(sysmapid,100)=$ZBX_CURNODEID order by name"); if($sysmap = DBfetch($db_sysmaps)) { $_REQUEST["sysmapid"] = $sysmap["sysmapid"]; @@ -82,7 +82,7 @@ $form->AddVar("fullscreen",$_REQUEST["fullscreen"]); $cmbMaps = new CComboBox("sysmapid",$_REQUEST["sysmapid"],"submit()"); - $result=DBselect("select sysmapid,name from sysmaps order by name"); + $result=DBselect("select sysmapid,name from sysmaps where mod(sysmapid,100)=$ZBX_CURNODEID order by name"); while($row=DBfetch($result)) { if(!check_right("Network map","R",$row["sysmapid"])) continue; diff --git a/frontends/php/overview.php b/frontends/php/overview.php index 9c80f6be..a3e3b8bb 100644 --- a/frontends/php/overview.php +++ b/frontends/php/overview.php @@ -77,7 +77,7 @@ $cmbGroup = new CComboBox("groupid",$_REQUEST["groupid"],"submit()"); $cmbGroup->AddItem(0,S_ALL_SMALL); - $result=DBselect("select groupid,name from groups order by name"); + $result=DBselect("select groupid,name from groups where mod(groupid,100)=$ZBX_CURNODEID order by name"); while($row=DBfetch($result)) { $result2=DBselect("select h.hostid,h.host from hosts h,items i,hosts_groups hg where". diff --git a/frontends/php/popup.php b/frontends/php/popup.php index 75f8bb56..7087709c 100644 --- a/frontends/php/popup.php +++ b/frontends/php/popup.php @@ -78,7 +78,7 @@ $groupid = get_request("groupid",get_profile("web.popup.groupid",0)); $cmbGroups = new CComboBox("groupid",$groupid,"submit()"); $cmbGroups->AddItem(0,S_ALL_SMALL); - $db_groups = DBselect("select groupid,name from groups order by name"); + $db_groups = DBselect("select groupid,name from groups where mod(groupid,100)=$ZBX_CURNODEID order by name"); while($group = DBfetch($db_groups)) { // Check if at least one host with read permission exists for this group $db_hosts = DBselect("select distinct h.hostid,h.host from hosts h,items i,hosts_groups hg". @@ -112,9 +112,12 @@ $sql = "select h.hostid,h.host from hosts h"; if(isset($groupid)) - $sql .= ",hosts_groups hg where h.hostid=hg.hostid and hg.groupid=$groupid"; + $sql .= ",hosts_groups hg where mod(h.hostid,100)=$ZBX_CURNODEID and h.hostid=hg.hostid and hg.groupid=$groupid"; else + { + $sql .= "where mod(h.hostid,100)=$ZBX_CURNODEID"; $cmbHosts->AddItem(0,S_ALL_SMALL); + } $first_hostid = 0; $db_hosts = DBselect($sql); @@ -156,7 +159,9 @@ $sql = "select * from hosts h"; if(isset($groupid)) - $sql .= ",hosts_groups hg where h.hostid=hg.hostid and hg.groupid=$groupid"; + $sql .= ",hosts_groups hg where mod(h.hostid,100)=$ZBX_CURNODEID and h.hostid=hg.hostid and hg.groupid=$groupid"; + else + $sql .= "where mod(h.hostid,100)=$ZBX_CURNODEID"; $db_hosts = DBselect($sql); while($host = DBfetch($db_hosts)) @@ -203,7 +208,7 @@ $table = new CTableInfo(S_NO_ITEMS); $table->SetHeader(array(S_KEY,S_DESCRIPTION)); - $sql = "select * from help_items where itemtype=$itemtype order by key_"; + $sql = "select * from help_items where mod(itemtypeid,100)=$ZBX_CURNODEID and itemtype=$itemtype order by key_"; $result = DBselect($sql); while($row = DBfetch($result)) @@ -234,6 +239,7 @@ $sql = "select distinct h.host,t.*". " from triggers t,hosts h,items i,functions f". " where f.itemid=i.itemid and h.hostid=i.hostid and t.triggerid=f.triggerid"; + " and mod(h.hostid,100)=".$ZBX_CURNODEID; if(isset($hostid)) $sql .= " and h.hostid=$hostid"; @@ -261,7 +267,8 @@ //add dependences $result1=DBselect("select t.triggerid,t.description from triggers t,trigger_depends d". - " where t.triggerid=d.triggerid_up and d.triggerid_down=".$row["triggerid"]); + " where t.triggerid=d.triggerid_up and d.triggerid_down=".$row["triggerid"]. + " and mod(t.triggerid,100)=".$ZBX_CURNODEID); if($row1=DBfetch($result1)) { array_push($description,BR.BR."<strong>".S_DEPENDS_ON."</strong>".SPACE.BR); @@ -352,12 +359,14 @@ function add_variable(formname,value) { $sql = "select i.* from items i where $hostid=i.hostid". " and i.value_type=".ITEM_VALUE_TYPE_LOG. + " and mod(i.itemid,100)=".$ZBX_CURNODEID. " order by i.description, i.key_"; } else { $sql = "select h.host,i.* from items i,hosts h". - " where i.value_type=".ITEM_VALUE_TYPE_LOG." and h.hostid=i.hostid order by i.description, i.key_"; + " where i.value_type=".ITEM_VALUE_TYPE_LOG." and h.hostid=i.hostid order by i.description, i.key_". + " and mod(i.itemid,100)=".$ZBX_CURNODEID. } $db_items = DBselect($sql); diff --git a/frontends/php/report2.php b/frontends/php/report2.php index 8911c461..3b6ecf00 100644 --- a/frontends/php/report2.php +++ b/frontends/php/report2.php @@ -55,7 +55,7 @@ $h2=S_GROUP.SPACE; $h2=$h2."<select class=\"biginput\" name=\"groupid\" onChange=\"submit()\">"; $h2=$h2.form_select("groupid",0,S_ALL_SMALL); - $result=DBselect("select groupid,name from groups order by name"); + $result=DBselect("select groupid,name from groups where mod(groupid,100)=$ZBX_CURNODEID order by name"); while($row=DBfetch($result)) { // Check if at least one host with read permission exists for this group @@ -86,7 +86,7 @@ } else { - $sql="select h.hostid,h.host from hosts h,items i where h.status=".HOST_STATUS_MONITORED." and h.hostid=i.hostid group by h.hostid,h.host order by h.host"; + $sql="select h.hostid,h.host from hosts h,items i where h.status=".HOST_STATUS_MONITORED." and h.hostid=i.hostid and mod(h.hostid,100)=$ZBX_CURNODEID group by h.hostid,h.host order by h.host"; } $result=DBselect($sql); diff --git a/frontends/php/report3.php b/frontends/php/report3.php index 0140d4c2..65d9003b 100644 --- a/frontends/php/report3.php +++ b/frontends/php/report3.php @@ -57,7 +57,7 @@ $h2=S_YEAR.SPACE; $h2=$h2."<input name=\"serviceid\" type=\"hidden\" value=".$_REQUEST["serviceid"].">"; $h2=$h2."<select class=\"biginput\" name=\"year\" onChange=\"submit()\">"; - $result=DBselect("select h.hostid,h.host from hosts h,items i where h.status=".HOST_STATUS_MONITORED." and h.hostid=i.hostid group by h.hostid,h.host order by h.host"); + $result=DBselect("select h.hostid,h.host from hosts h,items i where h.status=".HOST_STATUS_MONITORED." and h.hostid=i.hostid and mod(h.hostid,100)=$ZBX_CURNODEID group by h.hostid,h.host order by h.host"); $year=date("Y"); for($year=date("Y")-2;$year<=date("Y");$year++) diff --git a/frontends/php/report4.php b/frontends/php/report4.php index 070d67a7..4f0c6283 100644 --- a/frontends/php/report4.php +++ b/frontends/php/report4.php @@ -60,7 +60,7 @@ # $h2=S_GROUP.SPACE; $h2=S_YEAR.SPACE; $h2=$h2."<select class=\"biginput\" name=\"year\" onChange=\"submit()\">"; - $result=DBselect("select h.hostid,h.host from hosts h,items i where h.status=".HOST_STATUS_MONITORED." and h.hostid=i.hostid group by h.hostid,h.host order by h.host"); + $result=DBselect("select h.hostid,h.host from hosts h,items i where h.status=".HOST_STATUS_MONITORED." and h.hostid=i.hostid and mod(h.hostid,100)=$ZBX_CURNODEID group by h.hostid,h.host order by h.host"); $year=date("Y"); for($year=date("Y")-2;$year<=date("Y");$year++) @@ -79,7 +79,7 @@ $h2=$h2.SPACE.S_MEDIA_TYPE.SPACE; $h2=$h2."<select class=\"biginput\" name=\"media_type\" onChange=\"submit()\">"; // $h2=$h2.form_select("media_type","0",S_ALL_SMALL); - $result=DBselect("select * from media_type order by description"); + $result=DBselect("select * from media_type where mod(mediatypeid,100)=$ZBX_CURNODEID order by description"); $type_count=0; while($row=DBfetch($result)) { @@ -118,6 +118,7 @@ $header=array(new CCol(S_YEAR,"center")); $uindex=1; $result=DBselect("select * from users". + " where mod(userid,100)=".$ZBX_CURNODEID. " order by alias"); while($row=DBfetch($result)) { @@ -184,7 +185,7 @@ { $header=array(new CCol(SPACE.S_MONTH,"center")); $uindex=1; - $result=DBselect("select * from users order by alias"); + $result=DBselect("select * from users where mod(userid,100)=$ZBX_CURNODEID order by alias"); while($row=DBfetch($result)) { $header=array_merge($header,array(new CImg("vtext.php?text=".$row["alias"]))); @@ -249,7 +250,7 @@ { $header=array(new CCol(SPACE.S_DAY,"center")); $uindex=1; - $result=DBselect("select * from users order by alias"); + $result=DBselect("select * from users where mod(userid,100)=$ZBX_CURNODEID order by alias"); while($row=DBfetch($result)) { $header=array_merge($header,array(new CImg("vtext.php?text=".$row["alias"]))); @@ -321,7 +322,7 @@ $year=date("Y"); $header=array(new CCol(SPACE.S_FROM,"center"),new CCol(SPACE.S_TILL,"center")); $uindex=1; - $result=DBselect("select * from users order by alias"); + $result=DBselect("select * from users where mod(userid,100)=$ZBX_CURNODEID order by alias"); while($row=DBfetch($result)) { $header=array_merge($header,array(new CImg("vtext.php?text=".$row["alias"]))); diff --git a/frontends/php/report5.php b/frontends/php/report5.php index 54aa7e39..87c6b66f 100644 --- a/frontends/php/report5.php +++ b/frontends/php/report5.php @@ -82,6 +82,7 @@ t.triggerid=f.triggerid and t.triggerid=a.triggerid and a.clock>$time_now-$time_dif + mod(h.hostid,100)=$ZBX_CURNODEID group by h.host,t.triggerid,t.description,t.priority order by 5 desc,1,3", 100); diff --git a/frontends/php/screenconf.php b/frontends/php/screenconf.php index 95a4b77f..e7290736 100644 --- a/frontends/php/screenconf.php +++ b/frontends/php/screenconf.php @@ -80,7 +80,8 @@ $table = new CTableInfo(S_NO_SCREENS_DEFINED); $table->setHeader(array(S_ID,S_NAME,S_DIMENSION_COLS_ROWS,S_SCREEN)); - $result=DBselect("select screenid,name,hsize,vsize from screens order by name"); + $result=DBselect("select screenid,name,hsize,vsize from screens where mod(screenid,100)=$ZBX_CURNODEID". + " order by name"); while($row=DBfetch($result)) { if(!check_right("Screen","R",$row["screenid"])) continue; diff --git a/frontends/php/screens.php b/frontends/php/screens.php index 7b79d994..6bb349b4 100644 --- a/frontends/php/screens.php +++ b/frontends/php/screens.php @@ -78,7 +78,7 @@ $cmbScreens = new CComboBox("screenid",$_REQUEST["screenid"],"submit()"); $screen_correct = 0; $first_screen = 0; - $result=DBselect("select screenid,name from screens order by name"); + $result=DBselect("select screenid,name from screens where mod(screenid,100)=$ZBX_CURNODEID order by name"); while($row=DBfetch($result)) { if(!check_right("Screen","R",$row["screenid"])) diff --git a/frontends/php/services.php b/frontends/php/services.php index f9afb4d2..5de908d9 100644 --- a/frontends/php/services.php +++ b/frontends/php/services.php @@ -130,7 +130,7 @@ S_TRIGGER )); - $sql = "select serviceid,name,algorithm,triggerid from services order by sortorder,name"; + $sql = "select serviceid,name,algorithm,triggerid from services where mod(serviceid,100)=$ZBX_CURNODEID order by sortorder,name"; if(isset($_REQUEST["serviceid"])) { $form->AddVar("serviceid",$_REQUEST["serviceid"]); @@ -418,7 +418,7 @@ $frmDetails->AddVar("parentid",$_REQUEST["parentid"]); $cmbServers = new CComboBox("serverid"); - $result=DBselect("select hostid,host from hosts order by host"); + $result=DBselect("select hostid,host from hosts where mod(hostid,100)=$ZBX_CURNODEID order by host"); while($row=DBfetch($result)) { $cmbServers->AddItem($row["hostid"],$row["host"]); diff --git a/frontends/php/srv_status.php b/frontends/php/srv_status.php index 9d8d74bb..71007805 100644 --- a/frontends/php/srv_status.php +++ b/frontends/php/srv_status.php @@ -52,7 +52,7 @@ } $now=time(); - $result=DBselect("select serviceid,name,triggerid,status,showsla,goodsla from services order by sortorder,name"); + $result=DBselect("select serviceid,name,triggerid,status,showsla,goodsla from services where mod(serviceid,100)=$ZBX_CURNODEID order by sortorder,name"); // table_begin(); $table = new CTableInfo(); $table->SetHeader(array(S_SERVICE,S_STATUS,S_REASON,S_SLA_LAST_7_DAYS,nbsp(S_PLANNED_CURRENT_SLA),S_GRAPH)); @@ -158,7 +158,7 @@ else { $reason="<ul>"; - $sql="select s.triggerid,s.serviceid from services s, triggers t where s.status>0 and s.triggerid is not NULL and t.triggerid=s.triggerid order by s.status desc,t.description"; + $sql="select s.triggerid,s.serviceid from services s, triggers t where s.status>0 and s.triggerid is not NULL and t.triggerid=s.triggerid where mod(s.serviceid,100)=$ZBX_CURNODEID order by s.status desc,t.description"; $result2=DBselect($sql); while($row2=DBfetch($result2)) { diff --git a/frontends/php/sysmaps.php b/frontends/php/sysmaps.php index fbf3fb53..c7f54221 100644 --- a/frontends/php/sysmaps.php +++ b/frontends/php/sysmaps.php @@ -118,7 +118,7 @@ $table = new CTableInfo(S_NO_MAPS_DEFINED); $table->setHeader(array(S_ID,S_NAME,S_WIDTH,S_HEIGHT,S_MAP)); - $result=DBselect("select s.sysmapid,s.name,s.width,s.height from sysmaps s order by s.name"); + $result=DBselect("select sysmapid,name,width,height from sysmaps where mod(sysmapid,100)=$ZBX_CURNODEID order by name"); while($row=DBfetch($result)) { if(!check_right("Network map","U",$row["sysmapid"])) diff --git a/frontends/php/tr_status.php b/frontends/php/tr_status.php index 2e35700e..fac9040b 100644 --- a/frontends/php/tr_status.php +++ b/frontends/php/tr_status.php @@ -202,7 +202,7 @@ $h2=$h2."<select class=\"biginput\" name=\"groupid\" onChange=\"submit()\">"; $h2=$h2.form_select("groupid",0,S_ALL_SMALL); - $result=DBselect("select groupid,name from groups order by name"); + $result=DBselect("select groupid,name from groups where mod(groupid,100)=$ZBX_CURNODEID order by name"); while($row=DBfetch($result)) { // Check if at least one host with read permission exists for this group @@ -244,6 +244,7 @@ $sql="select h.hostid,h.host from hosts h,items i".$groupname. " where h.status=".HOST_STATUS_MONITORED." and h.hostid=i.hostid $groupcond". " and i.status=".ITEM_STATUS_ACTIVE." group by h.hostid,h.host order by h.host"; + " and mod(h.hostid,100)=$ZBX_CURNODEID"; $result=DBselect($sql); while($row=DBfetch($result)) @@ -350,6 +351,7 @@ $sql="select t.priority,count(*) as cnt from triggers t,hosts h,items i,functions f".$groupname. " where t.value=1 and t.status=0 and f.itemid=i.itemid and h.hostid=i.hostid". " and h.status=".HOST_STATUS_MONITORED." and i.status=".ITEM_STATUS_ACTIVE. + " and mod(h.hostid,100)=$ZBX_CURNODEID". " and t.triggerid=f.triggerid and t.description $select_cond $cond $groupcond group by t.priority"; } else @@ -357,6 +359,7 @@ $sql="select t.priority,count(*) as cnt from triggers t,hosts h,items i,functions f".$groupname. " where f.itemid=i.itemid and h.hostid=i.hostid and t.triggerid=f.triggerid and t.status=0". " and h.status=".HOST_STATUS_MONITORED." and i.status=".ITEM_STATUS_ACTIVE. + " and mod(h.hostid,100)=$ZBX_CURNODEID". " and t.description $select_cond $cond $groupcond group by t.priority"; } $result=DBselect($sql); @@ -488,6 +491,7 @@ "t.lastchange,t.comments,t.url,t.value from triggers t,hosts h,items i,functions f".$groupname. " where t.value=1 and t.status=0 and f.itemid=i.itemid and h.hostid=i.hostid and t.description". " $select_cond and t.triggerid=f.triggerid and i.status=".ITEM_STATUS_ACTIVE. + " and mod(h.hostid,100)=$ZBX_CURNODEID". " and h.status=".HOST_STATUS_MONITORED." $cond $groupcond $sort"); } else @@ -495,6 +499,7 @@ $result=DBselect("select distinct t.triggerid,t.status,t.description,t.expression,t.priority,". "t.lastchange,t.comments,t.url,t.value from triggers t,hosts h,items i,functions f".$groupname. " where f.itemid=i.itemid and h.hostid=i.hostid and t.triggerid=f.triggerid and t.status=0". + " and mod(h.hostid,100)=$ZBX_CURNODEID". " and t.description $select_cond and i.status=".ITEM_STATUS_ACTIVE." and h.status=".HOST_STATUS_MONITORED. " $cond $groupcond $sort"); } diff --git a/frontends/php/triggers.php b/frontends/php/triggers.php index bf2136e1..3bc18481 100644 --- a/frontends/php/triggers.php +++ b/frontends/php/triggers.php @@ -251,7 +251,7 @@ $_REQUEST["groupid"] = get_request("groupid",0); $cmbGroup = new CComboBox("groupid",$_REQUEST["groupid"],"submit();"); $cmbGroup->AddItem(0,S_ALL_SMALL); - $result=DBselect("select groupid,name from groups order by name"); + $result=DBselect("select groupid,name from groups where mod(groupid,100)=$ZBX_CURNODEID order by name"); while($row=DBfetch($result)) { // Check if at least one host with read permission exists for this group @@ -277,6 +277,7 @@ else { $sql="select h.hostid,h.host from hosts h,items i where i.hostid=h.hostid and h.status<>".HOST_STATUS_DELETED. + " and mod(h.hostid,100)=$ZBX_CURNODEID". " group by h.hostid,h.host order by h.host"; } @@ -327,7 +328,8 @@ $sql = "select distinct h.hostid,h.host,t.*". " from triggers t,hosts h,items i,functions f". - " where f.itemid=i.itemid and h.hostid=i.hostid and t.triggerid=f.triggerid"; + " where f.itemid=i.itemid and h.hostid=i.hostid and t.triggerid=f.triggerid". + " and mod(h.hostid,100)=$ZBX_CURNODEID"; if($_REQUEST["hostid"] > 0) $sql .= " and h.hostid=".$_REQUEST["hostid"]; @@ -456,7 +458,7 @@ else { /* FORM */ - $result=DBselect("select count(*) as cnt from hosts"); + $result=DBselect("select count(*) as cnt from hosts where mod(hostid,100)=$ZBX_CURNODEID"); $row=DBfetch($result); if($row["cnt"]>0) { diff --git a/frontends/php/users.php b/frontends/php/users.php index cf186a46..11d30306 100644 --- a/frontends/php/users.php +++ b/frontends/php/users.php @@ -211,8 +211,9 @@ $table=new CTableInfo(S_NO_USERS_DEFINED); $table->setHeader(array(S_ID,S_ALIAS,S_NAME,S_SURNAME,S_IS_ONLINE_Q,S_ACTIONS)); - $db_users=DBselect("select u.userid,u.alias,u.name,u.surname ". - "from users u order by u.alias"); + $db_users=DBselect("select userid,alias,name,surname ". + " from users where mod(userid,100)=".$ZBX_CURNODEID. + " order by alias"); while($db_user=DBfetch($db_users)) { if(!check_right("User","R",$db_user["userid"])) continue; @@ -306,7 +307,9 @@ $table = new CTableInfo(S_NO_USER_GROUPS_DEFINED); $table->setHeader(array(S_ID,S_NAME,S_MEMBERS)); - $result=DBselect("select usrgrpid,name from usrgrp order by name"); + $result=DBselect("select usrgrpid,name from usrgrp". + " where mod(usrgrpid,100)=".$ZBX_CURNODEID. + " order by name"); while($row=DBfetch($result)) { if(!check_right("User group","R",$row["usrgrpid"])) continue; |