summaryrefslogtreecommitdiffstats
path: root/frontends/php/include/db.inc.php
diff options
context:
space:
mode:
authorosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2007-08-13 08:22:32 +0000
committerosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2007-08-13 08:22:32 +0000
commitabaab90a1c9d3367f1ef636557cfe8e661716749 (patch)
tree3e266e5523a635c45a7e7ef6d4571e7323f26065 /frontends/php/include/db.inc.php
parent8901654871973b4267f106a97183001189189c82 (diff)
downloadzabbix-abaab90a1c9d3367f1ef636557cfe8e661716749.tar.gz
zabbix-abaab90a1c9d3367f1ef636557cfe8e661716749.tar.xz
zabbix-abaab90a1c9d3367f1ef636557cfe8e661716749.zip
- merger rev. 4546:4547 of branches/1.4.j [developed data monitoring of multiple nodes]
git-svn-id: svn://svn.zabbix.com/trunk@4549 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php/include/db.inc.php')
-rw-r--r--frontends/php/include/db.inc.php72
1 files changed, 56 insertions, 16 deletions
diff --git a/frontends/php/include/db.inc.php b/frontends/php/include/db.inc.php
index a55254a9..d142e309 100644
--- a/frontends/php/include/db.inc.php
+++ b/frontends/php/include/db.inc.php
@@ -480,40 +480,80 @@ if(isset($DB_TYPE) && $DB_TYPE == "ORACLE") {
function id2nodeid($id_var)
{
- return (int)bcdiv("$id_var","100000000000000");
+ return (int)bcdiv("$id_var",'100000000000000');
}
- function get_dbid($table,$field)
+ function DBin_node( $id_name, $nodes = null )
{
- global $ZBX_CURNODEID;
+ if ( is_null($nodes) ) $nodes = get_current_nodeid();
- if(!isset($ZBX_CURNODEID)) init_nodes();
+ if ( empty($nodes) ) $nodes = 0;
-/* $row=DBfetch(DBselect("select max($field) as id from $table where ".DBid2nodeid($field)." in (".$ZBX_CURNODEID.")"));
- if($row && !is_null($row["id"]))
+ if ( is_array($nodes) )
{
- return bcadd($row["id"],1);
+ $nodes = implode(',', $nodes);
}
- else
+ else if ( is_string($nodes) )
+ {
+ if ( !eregi('([0-9\,]+)', $nodes ) )
+ fatal_error('Incorrect "nodes" for "DBin_node". Passed ['.$nodes.']');
+ }
+ else if ( !is_numeric($nodes) )
{
- return bcadd(bcmul($ZBX_CURNODEID,"100000000000000"),1);
- }*/
+ fatal_error('Incorrect type of "nodes" for "DBin_node". Passed ['.gettype($nodes).']');
+ }
+
+ return (' '.DBid2nodeid($id_name).' in ('.$nodes.') ');
+ }
+
+ function in_node( $id_var, $nodes = null )
+ {
+ if ( is_null($nodes) ) $nodes = get_current_nodeid();
+ if ( empty($nodes) ) $nodes = 0;
+
+ if ( is_numeric($nodes) )
+ {
+ $nodes = array($nodes);
+ }
+ else if ( is_string($nodes) )
+ {
+ if ( !eregi('([0-9\,]+)', $nodes ) )
+ fatal_error('Incorrect "nodes" for "in_node". Passed ['.$nodes.']');
+
+ $nodes = explode(',', $nodes);
+ }
+ else if ( !is_array($nodes) )
+ {
+ fatal_error('Incorrect type of "nodes" for "in_node". Passed ['.gettype($nodes).']');
+ }
+
+ return in_array(id2nodeid($id_var), $nodes);
+ }
+
+ function get_dbid($table,$field)
+ {
+ $nodeid = get_current_nodeid(false);
$found = false;
do
{
- $row = DBfetch(DBselect("select nextid from ids where nodeid=$ZBX_CURNODEID and table_name='$table' and field_name='$field'"));
+ $row = DBfetch(DBselect('select nextid from ids '.
+ ' where nodeid='.$nodeid.
+ ' and table_name=\''.$table.'\' '.
+ ' and field_name=\''.$field.'\''));
+
if(!$row || is_null($row["nextid"]))
{
- $row=DBfetch(DBselect("select max($field) as id from $table where ".DBid2nodeid($field)." in (".$ZBX_CURNODEID.")"));
+ $row=DBfetch(DBselect("select max($field) as id from $table where ".DBin_node($field, $nodeid)));
if(!$row || is_null($row["id"]))
{
- DBexecute("insert into ids (nodeid,table_name,field_name,nextid) values ($ZBX_CURNODEID,'$table','$field',".bcadd(bcmul($ZBX_CURNODEID,"100000000000000"),1).")");
+ DBexecute("insert into ids (nodeid,table_name,field_name,nextid) ".
+ " values ($nodeid,'$table','$field',".bcadd(bcmul($nodeid,"100000000000000"),1).")");
}
else
{
- DBexecute("insert into ids (nodeid,table_name,field_name,nextid) values ($ZBX_CURNODEID,'$table','$field',".$row["id"].")");
+ DBexecute("insert into ids (nodeid,table_name,field_name,nextid) values ($nodeid,'$table','$field',".$row["id"].")");
}
continue;
}
@@ -521,9 +561,9 @@ if(isset($DB_TYPE) && $DB_TYPE == "ORACLE") {
{
$ret1 = $row["nextid"];
- DBexecute("update ids set nextid=nextid+1 where nodeid=$ZBX_CURNODEID and table_name='$table' and field_name='$field'");
+ DBexecute("update ids set nextid=nextid+1 where nodeid=$nodeid and table_name='$table' and field_name='$field'");
- $row = DBfetch(DBselect("select nextid from ids where nodeid=$ZBX_CURNODEID and table_name='$table' and field_name='$field'"));
+ $row = DBfetch(DBselect("select nextid from ids where nodeid=$nodeid and table_name='$table' and field_name='$field'"));
if(!$row || is_null($row["nextid"]))
{
/* Should never be here */