summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralex <alex@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2006-09-14 11:06:27 +0000
committeralex <alex@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2006-09-14 11:06:27 +0000
commit8755f9643aba3cffc5320321618fbe8e7b78b73b (patch)
tree61f79790fee2222b1d3c5c3cd3faf09c9de8f168
parent220a18752f8fefdd0af90ccd17cc045c2e6ae1a6 (diff)
downloadzabbix-8755f9643aba3cffc5320321618fbe8e7b78b73b.tar.gz
zabbix-8755f9643aba3cffc5320321618fbe8e7b78b73b.tar.xz
zabbix-8755f9643aba3cffc5320321618fbe8e7b78b73b.zip
Initial integration of distributed monitoring.
Changes 3196:HEAD of branches/distributed git-svn-id: svn://svn.zabbix.com/trunk@3306 97f52cf1-0a1b-0410-bd0e-c28be96e8082
-rw-r--r--configure.in1
-rw-r--r--create/data/data.sql12
-rw-r--r--create/data/data_small.sql97
-rw-r--r--create/data/nodes.sql63
-rwxr-xr-xcreate/data/recreate.sh45
-rw-r--r--create/mysql/schema.sql83
-rw-r--r--create/mysql/schema.sql.new985
-rw-r--r--frontends/php/actionconf.php13
-rw-r--r--frontends/php/audit.php4
-rw-r--r--frontends/php/bulkloader.php6
-rw-r--r--frontends/php/charts.php5
-rw-r--r--frontends/php/config.php15
-rw-r--r--frontends/php/events.php4
-rw-r--r--frontends/php/graphs.php5
-rw-r--r--frontends/php/hostprofiles.php9
-rw-r--r--frontends/php/hosts.php27
-rw-r--r--frontends/php/include/acknow.inc.php11
-rw-r--r--frontends/php/include/actions.inc.php17
-rw-r--r--frontends/php/include/audit.inc.php8
-rw-r--r--frontends/php/include/autoregistration.inc.php6
-rw-r--r--frontends/php/include/bulkloader.inc.php15
-rw-r--r--frontends/php/include/config.inc.php40
-rw-r--r--frontends/php/include/db.inc.php5
-rw-r--r--frontends/php/include/forms.inc.php5
-rw-r--r--frontends/php/include/graphs.inc.php16
-rw-r--r--frontends/php/include/hosts.inc.php27
-rw-r--r--frontends/php/include/items.inc.php15
-rw-r--r--frontends/php/include/maps.inc.php33
-rw-r--r--frontends/php/include/perm.inc.php6
-rw-r--r--frontends/php/include/screens.inc.php18
-rw-r--r--frontends/php/include/services.inc.php19
-rw-r--r--frontends/php/include/triggers.inc.php22
-rw-r--r--frontends/php/include/users.inc.php12
-rw-r--r--frontends/php/index.php3
-rw-r--r--frontends/php/items.php5
-rw-r--r--frontends/php/latest.php9
-rw-r--r--frontends/php/maps.php4
-rw-r--r--frontends/php/overview.php2
-rw-r--r--frontends/php/popup.php21
-rw-r--r--frontends/php/report2.php4
-rw-r--r--frontends/php/report3.php2
-rw-r--r--frontends/php/report4.php11
-rw-r--r--frontends/php/report5.php1
-rw-r--r--frontends/php/screenconf.php3
-rw-r--r--frontends/php/screens.php2
-rw-r--r--frontends/php/services.php4
-rw-r--r--frontends/php/srv_status.php4
-rw-r--r--frontends/php/sysmaps.php2
-rw-r--r--frontends/php/tr_status.php7
-rw-r--r--frontends/php/triggers.php8
-rw-r--r--frontends/php/users.php9
-rw-r--r--include/common.h27
-rw-r--r--include/db.h2
-rw-r--r--include/dbsync.h642
-rw-r--r--src/zabbix_server/Makefile.am5
-rw-r--r--src/zabbix_server/actions.c7
-rw-r--r--src/zabbix_server/actions.h2
-rw-r--r--src/zabbix_server/alerter/alerter.c2
-rw-r--r--src/zabbix_server/alerter/alerter.h2
-rw-r--r--src/zabbix_server/evalfunc.c2
-rw-r--r--src/zabbix_server/evalfunc.h1
-rw-r--r--src/zabbix_server/functions.c4
-rw-r--r--src/zabbix_server/nodesender/Makefile.am4
-rw-r--r--src/zabbix_server/nodesender/nodesender.c589
-rw-r--r--src/zabbix_server/nodesender/nodesender.h26
-rw-r--r--src/zabbix_server/nodewatcher/.deps/nodewatcher.Po396
-rw-r--r--src/zabbix_server/nodewatcher/Makefile.am4
-rw-r--r--src/zabbix_server/nodewatcher/nodewatcher.c260
-rw-r--r--src/zabbix_server/nodewatcher/nodewatcher.h25
-rw-r--r--src/zabbix_server/pinger/pinger.c8
-rw-r--r--src/zabbix_server/pinger/pinger.h2
-rw-r--r--src/zabbix_server/poller/checks_aggregate.c2
-rw-r--r--src/zabbix_server/poller/checks_aggregate.h2
-rw-r--r--src/zabbix_server/poller/poller.c12
-rw-r--r--src/zabbix_server/server.c23
-rw-r--r--src/zabbix_server/timer/timer.c3
-rw-r--r--src/zabbix_server/timer/timer.h10
-rw-r--r--src/zabbix_server/trapper/Makefile.am2
-rw-r--r--src/zabbix_server/trapper/active.c2
-rw-r--r--src/zabbix_server/trapper/active.h2
-rw-r--r--src/zabbix_server/trapper/autoregister.c2
-rw-r--r--src/zabbix_server/trapper/autoregister.h2
-rw-r--r--src/zabbix_server/trapper/nodesync.c258
-rw-r--r--src/zabbix_server/trapper/nodesync.h28
-rw-r--r--src/zabbix_server/trapper/trapper.c40
-rw-r--r--src/zabbix_server/zlog.c4
-rw-r--r--upgrades/dbpatches/1.1_1.3/mysql/patch.sql122
-rw-r--r--upgrades/dbpatches/1.1_1.3/oracle/patch.sql0
-rw-r--r--upgrades/dbpatches/1.1_1.3/postgresql/patch.sql0
89 files changed, 4071 insertions, 203 deletions
diff --git a/configure.in b/configure.in
index 5f2f9fff..8ef8acb1 100644
--- a/configure.in
+++ b/configure.in
@@ -982,6 +982,7 @@ AC_OUTPUT(Makefile src/Makefile src/libs/Makefile src/libs/zbxlog/Makefile src/l
src/zabbix_server/pinger/Makefile src/zabbix_agent/Makefile \
src/zabbix_server/housekeeper/Makefile src/zabbix_server/alerter/Makefile src/zabbix_server/Makefile \
src/zabbix_server/trapper/Makefile src/zabbix_server/poller/Makefile src/zabbix_server/timer/Makefile \
+ src/zabbix_server/nodewatcher/Makefile src/zabbix_server/nodesender/Makefile\
src/zabbix_get/Makefile src/libs/zbxcommon/Makefile src/libs/zbxsysinfo/linux/Makefile \
src/libs/zbxsysinfo/aix/Makefile src/libs/zbxsysinfo/freebsd/Makefile src/libs/zbxsysinfo/hpux/Makefile \
src/libs/zbxsysinfo/openbsd/Makefile src/libs/zbxsysinfo/osx/Makefile src/libs/zbxsysinfo/solaris/Makefile \
diff --git a/create/data/data.sql b/create/data/data.sql
index 0b7a7563..220e3d42 100644
--- a/create/data/data.sql
+++ b/create/data/data.sql
@@ -21,7 +21,7 @@
-- Dumping data for table `config`
--
-INSERT INTO config VALUES (365,365,600,'1-5,00:00-24:00');
+INSERT INTO config VALUES (1,365,365,600,'1-5,00:00-24:00');
--
-- Dumping data for table `media_type`
@@ -76,11 +76,11 @@ INSERT INTO groups VALUES (1,'Templates');
-- Dumping data for table `hosts_groups`
--
-INSERT INTO hosts_groups VALUES (10001,1);
-INSERT INTO hosts_groups VALUES (10002,1);
-INSERT INTO hosts_groups VALUES (10003,1);
-INSERT INTO hosts_groups VALUES (10004,1);
-INSERT INTO hosts_groups VALUES (10007,1);
+INSERT INTO hosts_groups VALUES (1,10001,1);
+INSERT INTO hosts_groups VALUES (2,10002,1);
+INSERT INTO hosts_groups VALUES (3,10003,1);
+INSERT INTO hosts_groups VALUES (4,10004,1);
+INSERT INTO hosts_groups VALUES (5,10007,1);
--
-- Dumping data for table `help_items`
diff --git a/create/data/data_small.sql b/create/data/data_small.sql
new file mode 100644
index 00000000..cc4bac9b
--- /dev/null
+++ b/create/data/data_small.sql
@@ -0,0 +1,97 @@
+--
+-- Zabbix
+-- Copyright (C) 2000,2001,2002,2003,2004 Alexei Vladishev
+--
+-- This program is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU General Public License as published by
+-- the Free Software Foundation; either version 2 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program; if not, write to the Free Software
+-- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+--
+
+--
+-- Dumping data for table `config`
+--
+
+INSERT INTO config VALUES (1,365,365,600,'1-5,00:00-24:00');
+
+--
+-- Dumping data for table `media_type`
+--
+
+INSERT INTO media_type VALUES (1,0,'Email','localhost','localhost','zabbix@localhost','','');
+
+--
+-- Dumping data for table `users`
+--
+
+INSERT INTO users VALUES (1,'Admin','Zabbix','Administrator','d41d8cd98f00b204e9800998ecf8427e',' ',900,'en_gb',30);
+INSERT INTO users VALUES (2,'guest','Default','User','d41d8cd98f00b204e9800998ecf8427e',' ',900,'en_gb',30);
+
+--
+-- Dumping data for table `usrgrp`
+--
+
+INSERT INTO usrgrp VALUES (1,'UNIX administrators');
+INSERT INTO usrgrp VALUES (2,'Database administrators');
+INSERT INTO usrgrp VALUES (3,'Network administrators');
+INSERT INTO usrgrp VALUES (4,'Security specialists');
+INSERT INTO usrgrp VALUES (5,'WEB administrators');
+INSERT INTO usrgrp VALUES (6,'Head of IT department');
+INSERT INTO usrgrp VALUES (7,'Zabbix administrators');
+
+--
+-- Dumping data for table `rights`
+--
+
+INSERT INTO rights VALUES (1,1,'Default permission','U',0);
+INSERT INTO rights VALUES (2,1,'Default permission','A',0);
+INSERT INTO rights VALUES (3,2,'Default permission','R',0);
+
+--
+-- Dumping data for table `hosts`
+--
+
+INSERT INTO hosts VALUES (10001,'Unix_t',0,'',10000,3,0,'',0,0,0);
+INSERT INTO hosts VALUES (10002,'Windows_t',0,'',10000,3,0,'',0,0,0);
+INSERT INTO hosts VALUES (10004,'Standalone_t',0,'',10000,3,0,'',0,0,0);
+INSERT INTO hosts VALUES (10003,'MySQL_t',0,'',10000,3,0,'',0,0,0);
+INSERT INTO hosts VALUES (10007,'SNMP_t',0,'',161,3,0,'',0,0,0);
+
+INSERT INTO hosts VALUES (10008,'Test',1,'127.0.0.1',10050,0,0,'',0,0,0);
+
+--
+-- Dumping data for table `groups`
+--
+
+INSERT INTO groups VALUES (1,'Templates');
+
+--
+-- Dumping data for table `hosts_groups`
+--
+
+INSERT INTO hosts_groups VALUES (1,10001,1);
+INSERT INTO hosts_groups VALUES (2,10002,1);
+INSERT INTO hosts_groups VALUES (3,10003,1);
+INSERT INTO hosts_groups VALUES (4,10004,1);
+INSERT INTO hosts_groups VALUES (5,10007,1);
+
+INSERT INTO items VALUES (10001,0,'','',161,10008,'Free memory','vm.memory.size[free]',30,7,365,0,NULL,NULL,NULL,0,0,'','B',0,0,NULL,'',0,'','','0','',0,'',0,0);
+INSERT INTO items VALUES (10002,0,'','',161,10008,'Free disk space on $1','vfs.fs.size[/,free]',30,7,365,0,NULL,NULL,NULL,0,0,'','B',0,0,NULL,'',0,'','','1','',0,'',0,0);
+INSERT INTO `items` VALUES (10010,0,'','',161,10008,'Processor load','system.cpu.load[,avg1]',5,7,365,0,NULL,NULL,NULL,0,0,'','',0,0,NULL,'',0,'','','0','',0,'',0,0);
+
+INSERT INTO functions VALUES (10010,10010,10010,NULL,'last','0');
+
+INSERT INTO triggers VALUES (10010,'{10010}>2','Processor load is too high on {HOSTNAME}','',0,2,3,0,0,'','',0);
+
+INSERT INTO `actions` VALUES (1,2,'{TRIGGER.NAME}: {STATUS}','{TRIGGER.NAME}: {STATUS}',1,0,600,0,0,0,'');
+
+INSERT INTO `media` VALUES (1,1,1,'aaa',0,63,'1-7,00:00-23:59;');
diff --git a/create/data/nodes.sql b/create/data/nodes.sql
new file mode 100644
index 00000000..8462bd94
--- /dev/null
+++ b/create/data/nodes.sql
@@ -0,0 +1,63 @@
+connect node7;
+delete from nodes;
+insert into nodes values (7, "Cologne",2, "127.0.0.1", 15057, 30, 365, 1, 5);
+insert into nodes values (6, "Berlin", 2, "127.0.0.1", 15056, 30, 365, 0, 5);
+insert into nodes values (5, "Germany",2, "127.0.0.1", 15055, 30, 365, 0, 4);
+insert into nodes values (4, "Zabbix", 2, "127.0.0.1", 15054, 30, 365, 0, 0);
+insert into nodes values (3, "Latvia", 2, "127.0.0.1", 15053, 30, 365, 0, 4);
+insert into nodes values (2, "Riga", 2, "127.0.0.1", 15052, 30, 365, 0, 3);
+insert into nodes values (1, "Dpils", 2, "127.0.0.1", 15051, 30, 365, 0, 3);
+connect node6;
+delete from nodes;
+insert into nodes values (7, "Cologne",2, "127.0.0.1", 15057, 30, 365, 0, 5);
+insert into nodes values (6, "Berlin", 2, "127.0.0.1", 15056, 30, 365, 1, 5);
+insert into nodes values (5, "Germany",2, "127.0.0.1", 15055, 30, 365, 0, 4);
+insert into nodes values (4, "Zabbix", 2, "127.0.0.1", 15054, 30, 365, 0, 0);
+insert into nodes values (3, "Latvia", 2, "127.0.0.1", 15053, 30, 365, 0, 4);
+insert into nodes values (2, "Riga", 2, "127.0.0.1", 15052, 30, 365, 0, 3);
+insert into nodes values (1, "Dpils", 2, "127.0.0.1", 15051, 30, 365, 0, 3);
+connect node5;
+delete from nodes;
+insert into nodes values (7, "Cologne",2, "127.0.0.1", 15057, 30, 365, 0, 5);
+insert into nodes values (6, "Berlin", 2, "127.0.0.1", 15056, 30, 365, 0, 5);
+insert into nodes values (5, "Germany",2, "127.0.0.1", 15055, 30, 365, 1, 4);
+insert into nodes values (4, "Zabbix", 2, "127.0.0.1", 15054, 30, 365, 0, 0);
+insert into nodes values (3, "Latvia", 2, "127.0.0.1", 15053, 30, 365, 0, 4);
+insert into nodes values (2, "Riga", 2, "127.0.0.1", 15052, 30, 365, 0, 3);
+insert into nodes values (1, "Dpils", 2, "127.0.0.1", 15051, 30, 365, 0, 3);
+connect node4;
+delete from nodes;
+insert into nodes values (7, "Cologne",2, "127.0.0.1", 15057, 30, 365, 0, 5);
+insert into nodes values (6, "Berlin", 2, "127.0.0.1", 15056, 30, 365, 0, 5);
+insert into nodes values (5, "Germany",2, "127.0.0.1", 15055, 30, 365, 0, 4);
+insert into nodes values (4, "Zabbix", 2, "127.0.0.1", 15054, 30, 365, 1, 0);
+insert into nodes values (3, "Latvia", 2, "127.0.0.1", 15053, 30, 365, 0, 4);
+insert into nodes values (2, "Riga", 2, "127.0.0.1", 15052, 30, 365, 0, 3);
+insert into nodes values (1, "Dpils", 2, "127.0.0.1", 15051, 30, 365, 0, 3);
+connect node3;
+delete from nodes;
+insert into nodes values (7, "Cologne",2, "127.0.0.1", 15057, 30, 365, 0, 5);
+insert into nodes values (6, "Berlin", 2, "127.0.0.1", 15056, 30, 365, 0, 5);
+insert into nodes values (5, "Germany",2, "127.0.0.1", 15055, 30, 365, 0, 4);
+insert into nodes values (4, "Zabbix", 2, "127.0.0.1", 15054, 30, 365, 0, 0);
+insert into nodes values (3, "Latvia", 2, "127.0.0.1", 15053, 30, 365, 1, 4);
+insert into nodes values (2, "Riga", 2, "127.0.0.1", 15052, 30, 365, 0, 3);
+insert into nodes values (1, "Dpils", 2, "127.0.0.1", 15051, 30, 365, 0, 3);
+connect node2;
+delete from nodes;
+insert into nodes values (7, "Cologne",2, "127.0.0.1", 15057, 30, 365, 0, 5);
+insert into nodes values (6, "Berlin", 2, "127.0.0.1", 15056, 30, 365, 0, 5);
+insert into nodes values (5, "Germany",2, "127.0.0.1", 15055, 30, 365, 0, 4);
+insert into nodes values (4, "Zabbix", 2, "127.0.0.1", 15054, 30, 365, 0, 0);
+insert into nodes values (3, "Latvia", 2, "127.0.0.1", 15053, 30, 365, 0, 4);
+insert into nodes values (2, "Riga", 2, "127.0.0.1", 15052, 30, 365, 1, 3);
+insert into nodes values (1, "Dpils", 2, "127.0.0.1", 15051, 30, 365, 0, 3);
+connect node1;
+delete from nodes;
+insert into nodes values (7, "Cologne",2, "127.0.0.1", 15057, 30, 365, 0, 5);
+insert into nodes values (6, "Berlin", 2, "127.0.0.1", 15056, 30, 365, 0, 5);
+insert into nodes values (5, "Germany",2, "127.0.0.1", 15055, 30, 365, 0, 4);
+insert into nodes values (4, "Zabbix", 2, "127.0.0.1", 15054, 30, 365, 0, 0);
+insert into nodes values (3, "Latvia", 2, "127.0.0.1", 15053, 30, 365, 0, 4);
+insert into nodes values (2, "Riga", 2, "127.0.0.1", 15052, 30, 365, 0, 3);
+insert into nodes values (1, "Dpils", 2, "127.0.0.1", 15051, 30, 365, 1, 3);
diff --git a/create/data/recreate.sh b/create/data/recreate.sh
new file mode 100755
index 00000000..51f360d4
--- /dev/null
+++ b/create/data/recreate.sh
@@ -0,0 +1,45 @@
+echo Killing servers
+killall zabbix_server >/dev/null 2>/dev/null
+sleep 1
+killall -9 zabbix_server >/dev/null 2>/dev/null
+echo Removing log files
+rm ~zabbix/logs/node*
+
+for i in 1 2 3 4 5 6 7; do
+ echo "drop database node$i"|mysql -uroot
+ echo "create database node$i"|mysql -uroot
+ cat ../mysql/schema.sql|mysql -uroot node$i
+ cat data.sql|sed -e "s/{10010}/{100100$i}/g"|mysql -uroot node$i
+# cat data_small.sql|sed -e "s/{10010}/{100100$i}/g"|mysql -uroot node$i
+done
+cat nodes.sql|mysql -uroot
+
+for i in 1 2 3 4 5 6 7; do
+ echo "update config set configid=100*configid+$i"|mysql -uroot node$i
+ echo "update media_type set mediatypeid=100*mediatypeid+$i"|mysql -uroot node$i
+ echo "update users set userid=100*userid+$i"|mysql -uroot node$i
+ echo "update usrgrp set usrgrpid=100*usrgrpid+$i"|mysql -uroot node$i
+ echo "update rights set rightid=100*rightid+$i"|mysql -uroot node$i
+ echo "update rights set userid=100*userid+$i"|mysql -uroot node$i
+ echo "update hosts set hostid=100*hostid+$i"|mysql -uroot node$i
+ echo "update groups set groupid=100*groupid+$i"|mysql -uroot node$i
+ echo "update hosts_groups set hostgroupid=100*hostgroupid+$i"|mysql -uroot node$i
+ echo "update hosts_groups set hostid=100*hostid+$i"|mysql -uroot node$i
+ echo "update hosts_groups set groupid=100*groupid+$i"|mysql -uroot node$i
+ echo "update items set itemid=100*itemid+$i"|mysql -uroot node$i
+ echo "update items set hostid=100*hostid+$i"|mysql -uroot node$i
+ echo "update functions set functionid=100*functionid+$i"|mysql -uroot node$i
+ echo "update functions set itemid=100*itemid+$i"|mysql -uroot node$i
+ echo "update functions set triggerid=100*triggerid+$i"|mysql -uroot node$i
+ echo "update triggers set triggerid=100*triggerid+$i"|mysql -uroot node$i
+ echo "update actions set actionid=100*actionid+$i"|mysql -uroot node$i
+ echo "update actions set userid=100*userid+$i"|mysql -uroot node$i
+ echo "update media set mediaid=100*mediaid+$i"|mysql -uroot node$i
+ echo "update media set userid=100*userid+$i"|mysql -uroot node$i
+ echo "update media set mediatypeid=100*mediatypeid+$i"|mysql -uroot node$i
+done
+
+
+for i in 1 2 3 4 5 6 7; do
+ ~zabbix/distributed/bin/zabbix_server -c /etc/zabbix/node$i.conf
+done
diff --git a/create/mysql/schema.sql b/create/mysql/schema.sql
index a8d723f1..2faa7e3d 100644
--- a/create/mysql/schema.sql
+++ b/create/mysql/schema.sql
@@ -17,6 +17,55 @@
-- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
--
+--
+-- Table structure for table 'nodes'
+--
+
+CREATE TABLE nodes (
+ nodeid int(4) NOT NULL auto_increment,
+ name varchar(64) DEFAULT '' NOT NULL,
+ timezone int(4) DEFAULT '0' NOT NULL,
+ ip varchar(15) DEFAULT '' NOT NULL,
+ port int(4) DEFAULT '0' NOT NULL,
+ slave_history int(4) DEFAULT '0' NOT NULL,
+ slave_trends int(4) DEFAULT '0' NOT NULL,
+ nodetype int(4) DEFAULT '0' NOT NULL,
+ masterid int(4) DEFAULT '0' NOT NULL,
+ PRIMARY KEY (nodeid)
+) type=InnoDB;
+
+--
+-- Table structure for table 'node_cksum'
+--
+
+CREATE TABLE node_cksum (
+ cksumid int(4) NOT NULL auto_increment,
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ tablename varchar(64) DEFAULT '' NOT NULL,
+ fieldname varchar(64) DEFAULT '' NOT NULL,
+ recordid int(4) DEFAULT '0' NOT NULL,
+ cksumtype int(4) DEFAULT '0' NOT NULL,
+ cksum char(32) DEFAULT '' NOT NULL,
+ PRIMARY KEY (cksumid),
+ KEY (nodeid,tablename,fieldname,recordid,cksumtype)
+) type=InnoDB;
+
+--
+-- Table structure for table 'node_configlog'
+--
+
+CREATE TABLE node_configlog (
+ conflogid int(4) NOT NULL auto_increment,
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ tablename varchar(64) DEFAULT '' NOT NULL,
+ recordid int(4) DEFAULT '0' NOT NULL,
+ operation int(4) DEFAULT '0' NOT NULL,
+ sync_master int(4) DEFAULT '0' NOT NULL,
+ sync_slave int(4) DEFAULT '0' NOT NULL,
+ PRIMARY KEY (nodeid,conflogid),
+ KEY (conflogid),
+ KEY (nodeid,tablename)
+) type=InnoDB;
--
-- Table structure for table 'services'
@@ -145,6 +194,7 @@ CREATE TABLE sysmaps (
--
CREATE TABLE config (
+ configid int(4) NOT NULL auto_increment,
-- smtp_server varchar(255) DEFAULT '' NOT NULL,
-- smtp_helo varchar(255) DEFAULT '' NOT NULL,
-- smtp_email varchar(255) DEFAULT '' NOT NULL,
@@ -152,7 +202,8 @@ CREATE TABLE config (
alert_history int(4) DEFAULT '0' NOT NULL,
alarm_history int(4) DEFAULT '0' NOT NULL,
refresh_unsupported int(4) DEFAULT '0' NOT NULL,
- work_period varchar(100) DEFAULT '1-5,00:00-24:00' NOT NULL
+ work_period varchar(100) DEFAULT '1-5,00:00-24:00' NOT NULL,
+ PRIMARY KEY (configid)
) type=InnoDB;
--
@@ -163,7 +214,8 @@ CREATE TABLE groups (
groupid int(4) NOT NULL auto_increment,
name varchar(64) DEFAULT '' NOT NULL,
PRIMARY KEY (groupid),
- UNIQUE (name)
+-- UNIQUE (name)
+ KEY (name)
) type=InnoDB;
--
@@ -171,9 +223,12 @@ CREATE TABLE groups (
--
CREATE TABLE hosts_groups (
+ hostgroupid int(4) NOT NULL auto_increment,
hostid int(4) DEFAULT '0' NOT NULL,
groupid int(4) DEFAULT '0' NOT NULL,
- PRIMARY KEY (hostid,groupid)
+ PRIMARY KEY (hostgroupid),
+-- UNIQUE (hostid,groupid)
+ KEY (hostid,groupid)
) type=InnoDB;
--
@@ -328,7 +383,8 @@ CREATE TABLE hosts (
errors_from int(4) DEFAULT '0' NOT NULL,
templateid int(4) DEFAULT '0' NOT NULL,
PRIMARY KEY (hostid),
- UNIQUE (host),
+-- UNIQUE (host),
+ KEY (host),
KEY (status)
) type=InnoDB;
@@ -442,9 +498,11 @@ CREATE TABLE triggers (
--
CREATE TABLE trigger_depends (
+ triggerdepid int(4) NOT NULL auto_increment,
triggerid_down int(4) DEFAULT '0' NOT NULL,
triggerid_up int(4) DEFAULT '0' NOT NULL,
- PRIMARY KEY (triggerid_down, triggerid_up),
+ PRIMARY KEY (triggerdepid),
+ UNIQUE KEY (triggerid_down, triggerid_up),
-- KEY (triggerid_down),
KEY (triggerid_up)
) type=InnoDB;
@@ -464,7 +522,8 @@ CREATE TABLE users (
lang varchar(5) DEFAULT 'en_gb' NOT NULL,
refresh int(4) DEFAULT '30' NOT NULL,
PRIMARY KEY (userid),
- UNIQUE (alias)
+-- UNIQUE (alias)
+ KEY (alias)
) type=InnoDB;
--
@@ -641,7 +700,8 @@ CREATE TABLE usrgrp (
usrgrpid int(4) NOT NULL auto_increment,
name varchar(64) DEFAULT '' NOT NULL,
PRIMARY KEY (usrgrpid),
- UNIQUE (name)
+-- UNIQUE (name)
+ KEY (name)
) type=InnoDB;
--
@@ -649,9 +709,12 @@ CREATE TABLE usrgrp (
--
CREATE TABLE users_groups (
+ id int(4) NOT NULL auto_increment,
usrgrpid int(4) DEFAULT '0' NOT NULL,
userid int(4) DEFAULT '0' NOT NULL,
- PRIMARY KEY (usrgrpid,userid)
+ PRIMARY KEY (id),
+-- UNIQUE (usrgrpid,userid)
+ KEY (usrgrpid,userid)
) type=InnoDB;
--
@@ -828,9 +891,11 @@ CREATE TABLE applications (
--
CREATE TABLE items_applications (
+ itemappid int(4) NOT NULL auto_increment,
applicationid int(4) DEFAULT '0' NOT NULL,
itemid int(4) DEFAULT '0' NOT NULL,
- PRIMARY KEY (applicationid,itemid)
+ PRIMARY KEY (itemappid),
+ UNIQUE (applicationid,itemid)
) type=InnoDB;
--
diff --git a/create/mysql/schema.sql.new b/create/mysql/schema.sql.new
new file mode 100644
index 00000000..d269d387
--- /dev/null
+++ b/create/mysql/schema.sql.new
@@ -0,0 +1,985 @@
+--
+-- ZABBIX
+-- Copyright (C) 2000-2005 SIA Zabbix
+--
+-- This program is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU General Public License as published by
+-- the Free Software Foundation; either version 2 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program; if not, write to the Free Software
+-- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+--
+
+
+--
+-- Table structure for table 'nodes'
+--
+
+CREATE TABLE nodes (
+ nodeid int(4) NOT NULL auto_increment,
+ name varchar(64) DEFAULT '' NOT NULL,
+ timezone int(4) DEFAULT '0' NOT NULL,
+ ip varchar(15) DEFAULT '' NOT NULL,
+ port int(4) DEFAULT '0' NOT NULL,
+ slave_history int(4) DEFAULT '0' NOT NULL,
+ slave_trends int(4) DEFAULT '0' NOT NULL,
+ nodetype int(4) DEFAULT '0' NOT NULL,
+ masterid int(4) DEFAULT '0' NOT NULL,
+ PRIMARY KEY (nodeid)
+) type=InnoDB;
+
+--
+-- Table structure for table 'node_cksum'
+--
+
+CREATE TABLE node_cksum (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ cksumid int(4) NOT NULL auto_increment,
+ tablename varchar(64) DEFAULT '' NOT NULL,
+ fieldname varchar(64) DEFAULT '' NOT NULL,
+ recordid int(4) DEFAULT '0' NOT NULL,
+ cksumtype int(4) DEFAULT '0' NOT NULL,
+ cksum char(32) DEFAULT '' NOT NULL,
+ PRIMARY KEY (nodeid,cksumid),
+ KEY (cksumid),
+ KEY (nodeid,tablename,fieldname,recordid,cksumtype)
+) type=InnoDB;
+
+--
+-- Table structure for table 'node_configlog'
+--
+
+CREATE TABLE node_configlog (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ conflogid int(4) NOT NULL auto_increment,
+ tablename varchar(64) DEFAULT '' NOT NULL,
+ recordid int(4) DEFAULT '0' NOT NULL,
+ operation int(4) DEFAULT '0' NOT NULL,
+ sync_master int(4) DEFAULT '0' NOT NULL,
+ sync_slave int(4) DEFAULT '0' NOT NULL,
+ PRIMARY KEY (nodeid,conflogid),
+ KEY (conflogid),
+ KEY (nodeid,tablename)
+) type=InnoDB;
+
+--
+-- Table structure for table 'services'
+--
+
+CREATE TABLE services (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ serviceid int(4) NOT NULL auto_increment,
+ name varchar(128) DEFAULT '' NOT NULL,
+ status int(1) DEFAULT '0' NOT NULL,
+ algorithm int(1) DEFAULT '0' NOT NULL,
+ triggerid int(4),
+ showsla int(1) DEFAULT '0' NOT NULL,
+ goodsla double(5,2) DEFAULT '99.9' NOT NULL,
+ sortorder int(4) DEFAULT '0' NOT NULL,
+ PRIMARY KEY (nodeid,serviceid),
+ KEY (serviceid)
+) type=InnoDB;
+
+--
+-- Table structure for table 'services_links'
+--
+
+CREATE TABLE services_links (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ linkid int(4) NOT NULL auto_increment,
+ serviceupid int(4) DEFAULT '0' NOT NULL,
+ servicedownid int(4) DEFAULT '0' NOT NULL,
+ soft int(1) DEFAULT '0' NOT NULL,
+ PRIMARY KEY (nodeid,linkid),
+ KEY (linkid),
+-- KEY (serviceupid),
+ KEY (nodeid,servicedownid),
+ UNIQUE (nodeid,serviceupid,servicedownid)
+) type=InnoDB;
+
+--
+-- Table structure for table 'graphs_items'
+--
+
+CREATE TABLE graphs_items (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ gitemid int(4) NOT NULL auto_increment,
+ graphid int(4) DEFAULT '0' NOT NULL,
+ itemid int(4) DEFAULT '0' NOT NULL,
+ drawtype int(4) DEFAULT '0' NOT NULL,
+ sortorder int(4) DEFAULT '0' NOT NULL,
+ color varchar(32) DEFAULT 'Dark Green' NOT NULL,
+ yaxisside int(1) DEFAULT '1' NOT NULL,
+ calc_fnc int(1) DEFAULT '2' NOT NULL,
+ type int(1) DEFAULT '0' NOT NULL,
+ periods_cnt int(4) DEFAULT '5' NOT NULL,
+ PRIMARY KEY (nodeid,gitemid),
+ KEY (gitemid)
+) type=InnoDB;
+
+--
+-- Table structure for table 'graphs'
+--
+
+CREATE TABLE graphs (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ graphid int(4) NOT NULL auto_increment,
+ name varchar(128) DEFAULT '' NOT NULL,
+ width int(4) DEFAULT '0' NOT NULL,
+ height int(4) DEFAULT '0' NOT NULL,
+ yaxistype int(1) DEFAULT '0' NOT NULL,
+ yaxismin double(16,4) DEFAULT '0' NOT NULL,
+ yaxismax double(16,4) DEFAULT '0' NOT NULL,
+ templateid int(4) DEFAULT '0' NOT NULL,
+ show_work_period int(1) DEFAULT '1' NOT NULL,
+ show_triggers int(1) DEFAULT '1' NOT NULL,
+ graphtype int(2) DEFAULT '0' NOT NULL,
+ PRIMARY KEY (nodeid,graphid),
+ KEY (graphid),
+ KEY (nodeid,name)
+) type=InnoDB;
+
+--
+-- Table structure for table 'sysmaps_links'
+--
+
+CREATE TABLE sysmaps_links (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ linkid int(4) NOT NULL auto_increment,
+ sysmapid int(4) DEFAULT '0' NOT NULL,
+ selementid1 int(4) DEFAULT '0' NOT NULL,
+ selementid2 int(4) DEFAULT '0' NOT NULL,
+ -- may be NULL
+ triggerid int(4),
+ drawtype_off int(4) DEFAULT '0' NOT NULL,
+ color_off varchar(32) DEFAULT 'Black' NOT NULL,
+ drawtype_on int(4) DEFAULT '0' NOT NULL,
+ color_on varchar(32) DEFAULT 'Red' NOT NULL,
+ PRIMARY KEY (nodeid,linkid),
+ KEY (linkid)
+) type=InnoDB;
+
+--
+-- Table structure for table 'sysmaps_elements'
+--
+
+CREATE TABLE sysmaps_elements (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ selementid int(4) NOT NULL auto_increment,
+ sysmapid int(4) DEFAULT '0' NOT NULL,
+ elementid int(4) DEFAULT '0' NOT NULL,
+ elementtype int(4) DEFAULT '0' NOT NULL,
+ icon varchar(32) DEFAULT 'Server' NOT NULL,
+ icon_on varchar(32) DEFAULT 'Server' NOT NULL,
+ label varchar(128) DEFAULT '' NOT NULL,
+ label_location int(1) DEFAULT '0' NOT NULL,
+ x int(4) DEFAULT '0' NOT NULL,
+ y int(4) DEFAULT '0' NOT NULL,
+ url varchar(255) DEFAULT '' NOT NULL,
+ PRIMARY KEY (nodeid,selementid),
+ KEY (selementid)
+) type=InnoDB;
+
+--
+-- Table structure for table 'sysmaps'
+--
+
+CREATE TABLE sysmaps (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ sysmapid int(4) NOT NULL auto_increment,
+ name varchar(128) DEFAULT '' NOT NULL,
+ width int(4) DEFAULT '0' NOT NULL,
+ height int(4) DEFAULT '0' NOT NULL,
+ background varchar(64) DEFAULT '' NOT NULL,
+ label_type int(4) DEFAULT '0' NOT NULL,
+ label_location int(1) DEFAULT '0' NOT NULL,
+ PRIMARY KEY (nodeid,sysmapid),
+ KEY (sysmapid),
+ UNIQUE (nodeid,name)
+) type=InnoDB;
+
+--
+-- Table structure for table 'config'
+--
+
+CREATE TABLE config (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ configid int(4) NOT NULL auto_increment,
+ alert_history int(4) DEFAULT '0' NOT NULL,
+ alarm_history int(4) DEFAULT '0' NOT NULL,
+ refresh_unsupported int(4) DEFAULT '0' NOT NULL,
+ work_period varchar(100) DEFAULT '1-5,00:00-24:00' NOT NULL,
+ PRIMARY KEY (nodeid,configid),
+ KEY (configid)
+) type=InnoDB;
+
+--
+-- Table structure for table 'groups'
+--
+
+CREATE TABLE groups (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ groupid int(4) NOT NULL auto_increment,
+ name varchar(64) DEFAULT '' NOT NULL,
+ PRIMARY KEY (nodeid,groupid),
+ KEY (groupid),
+ UNIQUE (nodeid,name)
+) type=InnoDB;
+
+--
+-- Table structure for table 'hosts_groups'
+--
+
+CREATE TABLE hosts_groups (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ hostgroupid int(4) NOT NULL auto_increment,
+ hostid int(4) DEFAULT '0' NOT NULL,
+ groupid int(4) DEFAULT '0' NOT NULL,
+ PRIMARY KEY (nodeid,hostgroupid),
+ KEY (hostgroupid),
+ UNIQUE (nodeid,hostid,groupid)
+) type=InnoDB;
+
+--
+-- Table structure for table 'alerts'
+--
+
+CREATE TABLE alerts (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ alertid int(4) NOT NULL auto_increment,
+ actionid int(4) DEFAULT '0' NOT NULL,
+ triggerid int(4) DEFAULT '0' NOT NULL,
+ userid int(4) DEFAULT '0' NOT NULL,
+ clock int(4) DEFAULT '0' NOT NULL,
+-- type varchar(10) DEFAULT '' NOT NULL,
+ mediatypeid int(4) DEFAULT '0' NOT NULL,
+ sendto varchar(100) DEFAULT '' NOT NULL,
+ subject varchar(255) DEFAULT '' NOT NULL,
+ message blob DEFAULT '' NOT NULL,
+ status int(4) DEFAULT '0' NOT NULL,
+ retries int(4) DEFAULT '0' NOT NULL,
+ error varchar(128) DEFAULT '' NOT NULL,
+ repeats int(4) DEFAULT '0' NOT NULL,
+ maxrepeats int(4) DEFAULT '0' NOT NULL,
+ nextcheck int(4) DEFAULT '0' NOT NULL,
+ delay int(4) DEFAULT '0' NOT NULL,
+
+ PRIMARY KEY (nodeid,alertid),
+ KEY (alertid),
+ INDEX (nodeid,actionid),
+ KEY clock (nodeid,clock),
+ KEY triggerid (nodeid,triggerid),
+ KEY status_retries (nodeid,status, retries),
+ KEY mediatypeid (nodeid,mediatypeid),
+ KEY userid (nodeid,userid)
+) type=InnoDB;
+
+--
+-- Table structure for table 'actions'
+--
+
+CREATE TABLE actions (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ actionid int(4) NOT NULL auto_increment,
+ userid int(4) DEFAULT '0' NOT NULL,
+--delay int(4) DEFAULT '0' NOT NULL,
+ subject varchar(255) DEFAULT '' NOT NULL,
+ message blob DEFAULT '' NOT NULL,
+--nextcheck int(4) DEFAULT '0' NOT NULL,
+ recipient int(1) DEFAULT '0' NOT NULL,
+ maxrepeats int(4) DEFAULT '0' NOT NULL,
+ repeatdelay int(4) DEFAULT '600' NOT NULL,
+ source int(1) DEFAULT '0' NOT NULL,
+ actiontype int(1) DEFAULT '0' NOT NULL,
+ status int(1) DEFAULT '0' NOT NULL,
+ scripts blob DEFAULT '' NOT NULL,
+ PRIMARY KEY (nodeid,actionid),
+ KEY (actionid)
+) type=InnoDB;
+
+--
+-- Table structure for table 'conditions'
+--
+
+CREATE TABLE conditions (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ conditionid int(4) NOT NULL auto_increment,
+ actionid int(4) DEFAULT '0' NOT NULL,
+ conditiontype int(4) DEFAULT '0' NOT NULL,
+ operator int(1) DEFAULT '0' NOT NULL,
+ value varchar(255) DEFAULT '' NOT NULL,
+ PRIMARY KEY (nodeid,conditionid),
+ KEY (conditionid),
+ KEY (nodeid,actionid)
+) type=InnoDB;
+
+--
+-- Table structure for table 'alarms'
+--
+
+CREATE TABLE alarms (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ alarmid int(4) NOT NULL auto_increment,
+ triggerid int(4) DEFAULT '0' NOT NULL,
+ clock int(4) DEFAULT '0' NOT NULL,
+ value int(4) DEFAULT '0' NOT NULL,
+ acknowledged int(1) DEFAULT '0' NOT NULL,
+ PRIMARY KEY (nodeid,alarmid),
+ KEY (alarmid),
+ KEY (nodeid,triggerid,clock),
+ KEY (nodeid,clock)
+) type=InnoDB;
+
+--
+-- Table structure for table 'functions'
+--
+
+CREATE TABLE functions (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ functionid int(4) NOT NULL auto_increment,
+ itemid int(4) DEFAULT '0' NOT NULL,
+ triggerid int(4) DEFAULT '0' NOT NULL,
+ lastvalue varchar(255),
+ function varchar(12) DEFAULT '' NOT NULL,
+ parameter varchar(255) DEFAULT '0' NOT NULL,
+ PRIMARY KEY (nodeid,functionid),
+ KEY (functionid),
+ KEY triggerid (nodeid,triggerid),
+ KEY itemidfunctionparameter (nodeid,itemid,function,parameter)
+) type=InnoDB;
+
+--
+-- Table structure for table 'history'
+--
+
+CREATE TABLE history (
+ itemid int(4) DEFAULT '0' NOT NULL,
+ clock int(4) DEFAULT '0' NOT NULL,
+ value double(16,4) DEFAULT '0.0000' NOT NULL,
+-- PRIMARY KEY (itemid,clock)
+ KEY itemidclock (itemid, clock)
+) type=InnoDB;
+
+--
+-- Table structure for table 'history_uint'
+--
+
+CREATE TABLE history_uint (
+ itemid int(4) DEFAULT '0' NOT NULL,
+ clock int(4) DEFAULT '0' NOT NULL,
+ value bigint unsigned DEFAULT '0' NOT NULL,
+-- PRIMARY KEY (itemid,clock)
+ KEY itemidclock (itemid, clock)
+) type=InnoDB;
+
+--
+-- Table structure for table 'history_str'
+--
+
+CREATE TABLE history_str (
+ itemid int(4) DEFAULT '0' NOT NULL,
+ clock int(4) DEFAULT '0' NOT NULL,
+ value varchar(255) DEFAULT '' NOT NULL,
+-- PRIMARY KEY (itemid,clock)
+ KEY itemidclock (itemid, clock)
+) type=InnoDB;
+
+--
+-- Table structure for table 'hosts'
+--
+
+CREATE TABLE hosts (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ hostid int(4) NOT NULL auto_increment,
+ host varchar(64) DEFAULT '' NOT NULL,
+ useip int(1) DEFAULT '1' NOT NULL,
+ ip varchar(15) DEFAULT '127.0.0.1' NOT NULL,
+ port int(4) DEFAULT '0' NOT NULL,
+ status int(4) DEFAULT '0' NOT NULL,
+-- If status=UNREACHABLE, host will not be checked until this time
+ disable_until int(4) DEFAULT '0' NOT NULL,
+ error varchar(128) DEFAULT '' NOT NULL,
+ available int(4) DEFAULT '0' NOT NULL,
+ errors_from int(4) DEFAULT '0' NOT NULL,
+ templateid int(4) DEFAULT '0' NOT NULL,
+ PRIMARY KEY (nodeid,hostid),
+ KEY (hostid),
+ UNIQUE (nodeid, host),
+ KEY (status)
+) type=InnoDB;
+
+--
+-- Table structure for table 'items'
+--
+
+CREATE TABLE items (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ itemid int(4) NOT NULL auto_increment,
+ type int(4) DEFAULT '0' NOT NULL,
+ snmp_community varchar(64) DEFAULT '' NOT NULL,
+ snmp_oid varchar(255) DEFAULT '' NOT NULL,
+ snmp_port int(4) DEFAULT '161' NOT NULL,
+ hostid int(4) NOT NULL,
+ description varchar(255) DEFAULT '' NOT NULL,
+ key_ varchar(64) DEFAULT '' NOT NULL,
+ delay int(4) DEFAULT '0' NOT NULL,
+ history int(4) DEFAULT '90' NOT NULL,
+ trends int(4) DEFAULT '365' NOT NULL,
+-- lastdelete is not longer required
+-- lastdelete int(4) DEFAULT '0' NOT NULL,
+ nextcheck int(4) DEFAULT '0' NOT NULL,
+ lastvalue varchar(255) DEFAULT NULL,
+ lastclock int(4) DEFAULT NULL,
+ prevvalue varchar(255) DEFAULT NULL,
+ status int(4) DEFAULT '0' NOT NULL,
+ value_type int(4) DEFAULT '0' NOT NULL,
+ trapper_hosts varchar(255) DEFAULT '' NOT NULL,
+ units varchar(10) DEFAULT '' NOT NULL,
+ multiplier int(4) DEFAULT '0' NOT NULL,
+ delta int(1) DEFAULT '0' NOT NULL,
+ prevorgvalue double(16,4) DEFAULT NULL,
+ snmpv3_securityname varchar(64) DEFAULT '' NOT NULL,
+ snmpv3_securitylevel int(1) DEFAULT '0' NOT NULL,
+ snmpv3_authpassphrase varchar(64) DEFAULT '' NOT NULL,
+ snmpv3_privpassphrase varchar(64) DEFAULT '' NOT NULL,
+
+ formula varchar(255) DEFAULT '0' NOT NULL,
+ error varchar(128) DEFAULT '' NOT NULL,
+
+ lastlogsize int(4) DEFAULT '0' NOT NULL,
+ logtimefmt varchar(64) DEFAULT '' NOT NULL,
+ templateid int(4) DEFAULT '0' NOT NULL,
+ valuemapid int(4) DEFAULT '0' NOT NULL,
+
+ PRIMARY KEY (nodeid,itemid),
+ KEY (itemid),
+ UNIQUE shortname (hostid,key_),
+-- KEY (hostid),
+ KEY (nextcheck),
+ KEY (status)
+) type=InnoDB;
+
+--
+-- Table structure for table 'media'
+--
+
+CREATE TABLE media (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ mediaid int(4) NOT NULL auto_increment,
+ userid int(4) DEFAULT '0' NOT NULL,
+-- type varchar(10) DEFAULT '' NOT NULL,
+ mediatypeid int(4) DEFAULT '0' NOT NULL,
+ sendto varchar(100) DEFAULT '' NOT NULL,
+ active int(4) DEFAULT '0' NOT NULL,
+ severity int(4) DEFAULT '63' NOT NULL,
+ period varchar(100) DEFAULT '1-7,00:00-23:59' NOT NULL,
+ PRIMARY KEY (nodeid,mediaid),
+ KEY (mediaid),
+ KEY (userid),
+ KEY (mediatypeid)
+) type=InnoDB;
+
+--
+-- Table structure for table 'media'
+--
+
+CREATE TABLE media_type (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ mediatypeid int(4) NOT NULL auto_increment,
+ type int(4) DEFAULT '0' NOT NULL,
+ description varchar(100) DEFAULT '' NOT NULL,
+ smtp_server varchar(255) DEFAULT '' NOT NULL,
+ smtp_helo varchar(255) DEFAULT '' NOT NULL,
+ smtp_email varchar(255) DEFAULT '' NOT NULL,
+ exec_path varchar(255) DEFAULT '' NOT NULL,
+ gsm_modem varchar(255) DEFAULT '' NOT NULL,
+ PRIMARY KEY (nodeid,mediatypeid),
+ KEY (mediatypeid)
+) type=InnoDB;
+
+--
+-- Table structure for table 'triggers'
+--
+
+CREATE TABLE triggers (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ triggerid int(4) NOT NULL auto_increment,
+ expression varchar(255) DEFAULT '' NOT NULL,
+ description varchar(255) DEFAULT '' NOT NULL,
+ url varchar(255) DEFAULT '' NOT NULL,
+ status int(4) DEFAULT '0' NOT NULL,
+ value int(4) DEFAULT '0' NOT NULL,
+ priority int(2) DEFAULT '0' NOT NULL,
+ lastchange int(4) DEFAULT '0' NOT NULL,
+ dep_level int(2) DEFAULT '0' NOT NULL,
+ comments blob,
+ error varchar(128) DEFAULT '' NOT NULL,
+ templateid int(4) DEFAULT '0' NOT NULL,
+ PRIMARY KEY (nodeid,triggerid),
+ KEY (triggerid),
+ KEY (status),
+ KEY (value)
+) type=InnoDB;
+
+--
+-- Table structure for table 'trigger_depends'
+--
+
+CREATE TABLE trigger_depends (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ triggerdepid int(4) NOT NULL auto_increment,
+ triggerid_down int(4) DEFAULT '0' NOT NULL,
+ triggerid_up int(4) DEFAULT '0' NOT NULL,
+ PRIMARY KEY (nodeid,triggerdepid),
+ KEY (triggerdepid),
+ UNIQUE (triggerid_down, triggerid_up),
+-- KEY (triggerid_down),
+ KEY (triggerid_up)
+) type=InnoDB;
+
+--
+-- Table structure for table 'users'
+--
+
+CREATE TABLE users (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ userid int(4) NOT NULL auto_increment,
+ alias varchar(100) DEFAULT '' NOT NULL,
+ name varchar(100) DEFAULT '' NOT NULL,
+ surname varchar(100) DEFAULT '' NOT NULL,
+ passwd char(32) DEFAULT '' NOT NULL,
+ url varchar(255) DEFAULT '' NOT NULL,
+ autologout int(4) DEFAULT '900' NOT NULL,
+ lang varchar(5) DEFAULT 'en_gb' NOT NULL,
+ refresh int(4) DEFAULT '30' NOT NULL,
+ PRIMARY KEY (nodeid,userid),
+ KEY (userid),
+ UNIQUE (nodeid, alias)
+) type=InnoDB;
+
+--
+-- Table structure for table 'auditlog'
+--
+
+CREATE TABLE auditlog (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ auditid int(4) NOT NULL auto_increment,
+ userid int(4) DEFAULT '0' NOT NULL,
+ clock int(4) DEFAULT '0' NOT NULL,
+ action int(4) DEFAULT '0' NOT NULL,
+ resourcetype int(4) DEFAULT '0' NOT NULL,
+ details varchar(128) DEFAULT '0' NOT NULL,
+ PRIMARY KEY (nodeid,auditid),
+ KEY (auditid),
+ KEY (userid,clock),
+ KEY (clock)
+) type=InnoDB;
+
+--
+-- Table structure for table 'sessions'
+--
+
+CREATE TABLE sessions (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ sessionid varchar(32) NOT NULL DEFAULT '',
+ userid int(4) NOT NULL DEFAULT '0',
+ lastaccess int(4) NOT NULL DEFAULT '0',
+ PRIMARY KEY (nodeid,sessionid),
+ KEY (sessionid)
+) type=InnoDB;
+
+--
+-- Table structure for table 'rights'
+--
+
+CREATE TABLE rights (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ rightid int(4) NOT NULL auto_increment,
+ userid int(4) DEFAULT '0' NOT NULL,
+ name char(255) DEFAULT '' NOT NULL,
+ permission char(1) DEFAULT '' NOT NULL,
+ id int(4),
+ PRIMARY KEY (nodeid,rightid),
+ KEY (rightid),
+ KEY (userid)
+) type=InnoDB;
+
+--
+-- Table structure for table 'problems'
+--
+
+-- CREATE TABLE problems (
+-- problemid int(4) NOT NULL auto_increment,
+-- userid int(4) DEFAULT '0' NOT NULL,
+-- triggerid int(4),
+-- lastupdate int(4) DEFAULT '0' NOT NULL,
+-- clock int(4) DEFAULT '0' NOT NULL,
+-- status int(1) DEFAULT '0' NOT NULL,
+-- description varchar(255) DEFAULT '' NOT NULL,
+-- categoryid int(4),
+ -- priority int(1) DEFAULT '0' NOT NULL,
+-- PRIMARY KEY (problemid),
+-- KEY (status),
+-- KEY (categoryid),
+-- KEY (priority)
+-- ) type=InnoDB;
+
+--
+-- Table structure for table 'categories'
+--
+
+-- CREATE TABLE categories (
+-- categoryid int(4) NOT NULL auto_increment,
+-- descripion varchar(64) DEFAULT '' NOT NULL,
+-- PRIMARY KEY (categoryid)
+-- ) type=InnoDB;
+
+--
+-- Table structure for table 'problems_categories'
+--
+
+-- CREATE TABLE problems_comments (
+-- commentid int(4) NOT NULL auto_increment,
+-- problemid int(4) DEFAULT '0' NOT NULL,
+-- clock int(4),
+-- status_before int(1) DEFAULT '0' NOT NULL,
+-- status_after int(1) DEFAULT '0' NOT NULL,
+-- comment blob,
+-- PRIMARY KEY (commentid),
+-- KEY (problemid,clock)
+-- ) type=InnoDB;
+
+--
+-- Table structure for table 'service_alarms'
+--
+
+CREATE TABLE service_alarms (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ servicealarmid int(4) NOT NULL auto_increment,
+ serviceid int(4) DEFAULT '0' NOT NULL,
+ clock int(4) DEFAULT '0' NOT NULL,
+ value int(4) DEFAULT '0' NOT NULL,
+ PRIMARY KEY (nodeid,servicealarmid),
+ KEY (servicealarmid),
+ KEY (serviceid,clock),
+ KEY (clock)
+) type=InnoDB;
+
+--
+-- Table structure for table 'profiles'
+--
+
+CREATE TABLE profiles (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ profileid int(4) NOT NULL auto_increment,
+ userid int(4) DEFAULT '0' NOT NULL,
+ idx varchar(64) DEFAULT '' NOT NULL,
+ value varchar(255) DEFAULT '' NOT NULL,
+ valuetype int(4) DEFAULT 0 NOT NULL,
+ PRIMARY KEY (nodeid,profileid),
+ KEY (profileid),
+-- KEY (userid),
+ UNIQUE (userid,idx)
+) type=InnoDB;
+
+--
+-- Table structure for table 'screens'
+--
+
+CREATE TABLE screens (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ screenid int(4) NOT NULL auto_increment,
+ name varchar(255) DEFAULT 'Screen' NOT NULL,
+ hsize int(4) DEFAULT '1' NOT NULL,
+ vsize int(4) DEFAULT '1' NOT NULL,
+ PRIMARY KEY (nodeid,screenid),
+ KEY (screenid)
+) TYPE=InnoDB;
+
+--
+-- Table structure for table 'screens_items'
+--
+
+CREATE TABLE screens_items (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ screenitemid int(4) NOT NULL auto_increment,
+ screenid int(4) DEFAULT '0' NOT NULL,
+ resourcetype int(4) DEFAULT '0' NOT NULL,
+ resourceid int(4) DEFAULT '0' NOT NULL,
+ width int(4) DEFAULT '320' NOT NULL,
+ height int(4) DEFAULT '200' NOT NULL,
+ x int(4) DEFAULT '0' NOT NULL,
+ y int(4) DEFAULT '0' NOT NULL,
+ colspan int(4) DEFAULT '0' NOT NULL,
+ rowspan int(4) DEFAULT '0' NOT NULL,
+ elements int(4) DEFAULT '25' NOT NULL,
+ valign int(2) DEFAULT '0' NOT NULL,
+ halign int(2) DEFAULT '0' NOT NULL,
+ style int(4) DEFAULT '0' NOT NULL,
+ url varchar(255) DEFAULT '' NOT NULL,
+ PRIMARY KEY (nodeid,screenitemid),
+ KEY (screenitemid)
+) TYPE=InnoDB;
+
+--
+-- Table structure for table 'stats'
+--
+
+--CREATE TABLE stats (
+-- itemid int(4) DEFAULT '0' NOT NULL,
+-- year int(4) DEFAULT '0' NOT NULL,
+-- month int(4) DEFAULT '0' NOT NULL,
+-- day int(4) DEFAULT '0' NOT NULL,
+-- hour int(4) DEFAULT '0' NOT NULL,
+-- value_max double(16,4) DEFAULT '0.0000' NOT NULL,
+-- value_min double(16,4) DEFAULT '0.0000' NOT NULL,
+-- value_avg double(16,4) DEFAULT '0.0000' NOT NULL,
+-- PRIMARY KEY (itemid,year,month,day,hour)
+--) type=InnoDB;
+
+--
+-- Table structure for table 'usrgrp'
+--
+
+CREATE TABLE usrgrp (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ usrgrpid int(4) NOT NULL auto_increment,
+ name varchar(64) DEFAULT '' NOT NULL,
+ PRIMARY KEY (nodeid,usrgrpid),
+ KEY (usrgrpid),
+ UNIQUE (nodeid,name)
+) type=InnoDB;
+
+--
+-- Table structure for table 'users_groups'
+--
+
+CREATE TABLE users_groups (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ id int(4) NOT NULL auto_increment,
+ usrgrpid int(4) DEFAULT '0' NOT NULL,
+ userid int(4) DEFAULT '0' NOT NULL,
+ PRIMARY KEY (nodeid,id),
+ KEY (id),
+ UNIQUE (nodeid,usrgrpid,userid)
+) type=InnoDB;
+
+--
+-- Table structure for table 'trends'
+--
+
+CREATE TABLE trends (
+ itemid int(4) DEFAULT '0' NOT NULL,
+ clock int(4) DEFAULT '0' NOT NULL,
+ num int(2) DEFAULT '0' NOT NULL,
+ value_min double(16,4) DEFAULT '0.0000' NOT NULL,
+ value_avg double(16,4) DEFAULT '0.0000' NOT NULL,
+ value_max double(16,4) DEFAULT '0.0000' NOT NULL,
+ PRIMARY KEY (itemid,clock)
+) type=InnoDB;
+
+--
+-- Table structure for table 'images'
+--
+
+CREATE TABLE images (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ imageid int(4) NOT NULL auto_increment,
+ imagetype int(4) DEFAULT '0' NOT NULL,
+ name varchar(64) DEFAULT '0' NOT NULL,
+ image longblob DEFAULT '' NOT NULL,
+ PRIMARY KEY (nodeid,imageid),
+ KEY (imageid),
+ UNIQUE (nodeid,imagetype, name)
+) type=InnoDB;
+
+--
+-- Table structure for table 'hosts_templates'
+--
+
+CREATE TABLE hosts_templates (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ hosttemplateid int(4) NOT NULL auto_increment,
+ hostid int(4) DEFAULT '0' NOT NULL,
+ templateid int(4) DEFAULT '0' NOT NULL,
+ items int(1) DEFAULT '0' NOT NULL,
+ triggers int(1) DEFAULT '0' NOT NULL,
+ graphs int(1) DEFAULT '0' NOT NULL,
+ PRIMARY KEY (nodeid,hosttemplateid),
+ KEY (hosttemplateid),
+ UNIQUE (nodeid,hostid, templateid)
+) type=InnoDB;
+
+--
+-- Table structure for table 'history_log'
+--
+
+CREATE TABLE history_log (
+ id int(4) NOT NULL auto_increment,
+ itemid int(4) DEFAULT '0' NOT NULL,
+ clock int(4) DEFAULT '0' NOT NULL,
+ timestamp int(4) DEFAULT '0' NOT NULL,
+ source varchar(64) DEFAULT '' NOT NULL,
+ severity int(4) DEFAULT '0' NOT NULL,
+ value text DEFAULT '' NOT NULL,
+ PRIMARY KEY (id),
+ KEY itemidclock (itemid, clock)
+) type=InnoDB;
+
+--
+-- Table structure for table 'history_text'
+--
+
+CREATE TABLE history_text (
+ id int(4) NOT NULL auto_increment,
+ itemid int(4) DEFAULT '0' NOT NULL,
+ clock int(4) DEFAULT '0' NOT NULL,
+ value text DEFAULT '' NOT NULL,
+ PRIMARY KEY (id),
+ KEY itemidclock (itemid, clock)
+) type=InnoDB;
+
+--
+-- Table structure for table 'hosts_profiles'
+--
+
+CREATE TABLE hosts_profiles (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ hostid int(4) DEFAULT '0' NOT NULL,
+ devicetype varchar(64) DEFAULT '' NOT NULL,
+ name varchar(64) DEFAULT '' NOT NULL,
+ os varchar(64) DEFAULT '' NOT NULL,
+ serialno varchar(64) DEFAULT '' NOT NULL,
+ tag varchar(64) DEFAULT '' NOT NULL,
+ macaddress varchar(64) DEFAULT '' NOT NULL,
+ hardware blob DEFAULT '' NOT NULL,
+ software blob DEFAULT '' NOT NULL,
+ contact blob DEFAULT '' NOT NULL,
+ location blob DEFAULT '' NOT NULL,
+ notes blob DEFAULT '' NOT NULL,
+ PRIMARY KEY (nodeid,hostid)
+) type=InnoDB;
+
+--
+-- Table structure for table 'autoreg'
+--
+
+CREATE TABLE autoreg (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ id int(4) NOT NULL auto_increment,
+ priority int(4) DEFAULT '0' NOT NULL,
+ pattern varchar(255) DEFAULT '' NOT NULL,
+ hostid int(4) DEFAULT '0' NOT NULL,
+ PRIMARY KEY (nodeid,id),
+ KEY (id)
+) type=InnoDB;
+
+--
+-- Table structure for table 'valuemaps'
+--
+
+CREATE TABLE valuemaps (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ valuemapid int(4) NOT NULL auto_increment,
+ name varchar(64) DEFAULT '' NOT NULL,
+ PRIMARY KEY (nodeid,valuemapid),
+ KEY (valuemapid),
+ UNIQUE (nodeid,name)
+) type=InnoDB;
+
+--
+-- Table structure for table 'mapping'
+--
+
+CREATE TABLE mappings (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ mappingid int(4) NOT NULL auto_increment,
+ valuemapid int(4) DEFAULT '0' NOT NULL,
+ value varchar(64) DEFAULT '' NOT NULL,
+ newvalue varchar(64) DEFAULT '' NOT NULL,
+ PRIMARY KEY (nodeid,mappingid),
+ KEY (mappingid),
+ KEY valuemapid (valuemapid)
+) type=InnoDB;
+
+--
+-- Table structure for table 'housekeeper'
+--
+
+CREATE TABLE housekeeper (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ housekeeperid int(4) NOT NULL auto_increment,
+ tablename varchar(64) DEFAULT '' NOT NULL,
+ field varchar(64) DEFAULT '' NOT NULL,
+ value int(4) DEFAULT '0' NOT NULL,
+ PRIMARY KEY (nodeid,housekeeperid),
+ KEY (housekeeperid)
+) type=InnoDB;
+
+--
+-- Table structure for table 'acknowledges'
+--
+
+CREATE TABLE acknowledges (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ acknowledgeid int(4) NOT NULL auto_increment,
+ userid int(4) DEFAULT '0' NOT NULL,
+ alarmid int(4) DEFAULT '0' NOT NULL,
+ clock int(4) DEFAULT '0' NOT NULL,
+ message varchar(255) DEFAULT '' NOT NULL,
+ PRIMARY KEY (nodeid,acknowledgeid),
+ KEY (acknowledgeid),
+ KEY userid (userid),
+ KEY alarmid (alarmid),
+ KEY clock (clock)
+) type=InnoDB;
+
+--
+-- Table structure for table 'applications'
+--
+
+CREATE TABLE applications (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ applicationid int(4) NOT NULL auto_increment,
+ hostid int(4) DEFAULT '0' NOT NULL,
+ name varchar(255) DEFAULT '' NOT NULL,
+ templateid int(4) DEFAULT '0' NOT NULL,
+ PRIMARY KEY (nodeid,applicationid),
+ KEY (applicationid),
+ KEY templateid (templateid),
+ UNIQUE appname (hostid,name)
+) type=InnoDB;
+
+--
+-- Table structure for table 'items_applications'
+--
+
+CREATE TABLE items_applications (
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ itemappid int(4) NOT NULL auto_increment,
+ applicationid int(4) DEFAULT '0' NOT NULL,
+ itemid int(4) DEFAULT '0' NOT NULL,
+ PRIMARY KEY (nodeid,itemappid),
+ KEY (itemappid),
+ UNIQUE (applicationid,itemid)
+) type=InnoDB;
+
+--
+-- Table structure for table 'help_items'
+--
+
+CREATE TABLE help_items (
+ itemtype int(4) DEFAULT '0' NOT NULL,
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ key_ varchar(64) DEFAULT '' NOT NULL,
+ description varchar(255) DEFAULT '' NOT NULL,
+ PRIMARY KEY (itemtype, key_)
+) type=InnoDB;
+
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;
diff --git a/include/common.h b/include/common.h
index 162a8c08..50849e28 100644
--- a/include/common.h
+++ b/include/common.h
@@ -201,6 +201,30 @@
#define SERVICE_ALGORITHM_MAX 1
#define SERVICE_ALGORITHM_MIN 2
+/* Types of nodes check sums */
+#define NODE_CKSUM_TYPE_OLD 0
+#define NODE_CKSUM_TYPE_NEW 1
+
+/* Types of operation in config log */
+#define NODE_CONFIGLOG_OP_UPDATE 0
+#define NODE_CONFIGLOG_OP_ADD 1
+#define NODE_CONFIGLOG_OP_DELETE 2
+
+#define ZBX_TYPE_INT 0
+#define ZBX_TYPE_CHAR 1
+#define ZBX_TYPE_FLOAT 2
+#define ZBX_TYPE_BLOB 3
+#define ZBX_TYPE_TEXT 4
+#define ZBX_TYPE_UINT 5
+
+/* Flags */
+#define ZBX_SYNC 1
+#define ZBX_NOSYNC 2
+
+/* Types of nodes */
+#define NODE_TYPE_REMOTE 0
+#define NODE_TYPE_LOCAL 1
+
#define ZABBIX_FORKS 5
#define TRAPPERD_FORKS 5
@@ -258,6 +282,9 @@ AGENT_RESULT {
ZBX_LIST list;
};
+#define ZBX_COND_NODEID " %s=%d "
+#define LOCAL_NODE(fieldid) "mod(" fieldid ",100)",CONFIG_NODEID
+
/* agent result types */
#define AR_UINT64 1
#define AR_DOUBLE 2
diff --git a/include/db.h b/include/db.h
index b3effc14..36b286bc 100644
--- a/include/db.h
+++ b/include/db.h
@@ -138,7 +138,7 @@ void PG_DBfree_result(DB_RESULT result);
#define ZBX_SQL_ITEM_SELECT "i.itemid,i.key_,h.host,h.port,i.delay,i.description,i.nextcheck,i.type,i.snmp_community,i.snmp_oid,h.useip,h.ip,i.history,i.lastvalue,i.prevvalue,i.hostid,h.status,i.value_type,h.errors_from,i.snmp_port,i.delta,i.prevorgvalue,i.lastclock,i.units,i.multiplier,i.snmpv3_securityname,i.snmpv3_securitylevel,i.snmpv3_authpassphrase,i.snmpv3_privpassphrase,i.formula,h.available,i.status,i.trapper_hosts,i.logtimefmt,i.valuemapid from hosts h, items i"
-#define ZBX_MAX_SQL_LEN 4096
+#define ZBX_MAX_SQL_LEN 16384
DB_HOST
{
diff --git a/include/dbsync.h b/include/dbsync.h
new file mode 100644
index 00000000..e3463e8c
--- /dev/null
+++ b/include/dbsync.h
@@ -0,0 +1,642 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#ifndef ZABBIX_DBSYNC_H
+#define ZABBIX_DBSYNC_H
+
+#define ZBX_FIELD struct zbx_field_type
+ZBX_FIELD
+{
+ char *name;
+ int type;
+ int flags;
+};
+
+#define ZBX_TABLE struct zbx_table_type
+ZBX_TABLE
+{
+ char *table;
+ char *recid;
+ int flags;
+ ZBX_FIELD fields[64];
+};
+
+static ZBX_TABLE tables[]={
+ {"nodes", "nodeid", ZBX_NOSYNC,
+ {
+ {"nodeid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"name", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"timezone", ZBX_TYPE_INT, ZBX_SYNC},
+ {"ip", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"port", ZBX_TYPE_INT, ZBX_SYNC},
+ {"slave_history",ZBX_TYPE_INT, ZBX_SYNC},
+ {"slave_trends",ZBX_TYPE_INT, ZBX_SYNC},
+ {"nodetype", ZBX_TYPE_INT, ZBX_SYNC},
+ {"masterid", ZBX_TYPE_INT, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"services", "serviceid", ZBX_SYNC,
+ {
+ {"serviceid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"name", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"status", ZBX_TYPE_INT, ZBX_SYNC},
+ {"algorithm", ZBX_TYPE_INT, ZBX_SYNC},
+ {"triggerid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"showsla", ZBX_TYPE_INT, ZBX_SYNC},
+ {"goodsla", ZBX_TYPE_FLOAT, ZBX_SYNC},
+ {"sortorder", ZBX_TYPE_INT, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"services_links", "linkid", ZBX_SYNC,
+ {
+ {"linkid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"serviceupid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"servicedownid",ZBX_TYPE_INT, ZBX_SYNC},
+ {"soft", ZBX_TYPE_INT, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"graphs_items", "gitemid", ZBX_SYNC,
+ {
+ {"gitemid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"graphid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"itemid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"drawtype", ZBX_TYPE_INT, ZBX_SYNC},
+ {"sortorder", ZBX_TYPE_INT, ZBX_SYNC},
+ {"color", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"yaxisside", ZBX_TYPE_INT, ZBX_SYNC},
+ {"calc_fnc", ZBX_TYPE_INT, ZBX_SYNC},
+ {"type", ZBX_TYPE_INT, ZBX_SYNC},
+ {"periods_cnt", ZBX_TYPE_INT, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"graphs", "graphid", ZBX_SYNC,
+ {
+ {"graphid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"name", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"width", ZBX_TYPE_INT, ZBX_SYNC},
+ {"height", ZBX_TYPE_INT, ZBX_SYNC},
+ {"yaxistype", ZBX_TYPE_INT, ZBX_SYNC},
+ {"yaxismin", ZBX_TYPE_FLOAT, ZBX_SYNC},
+ {"yaxismax", ZBX_TYPE_FLOAT, ZBX_SYNC},
+ {"templateid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"show_work_period",ZBX_TYPE_INT, ZBX_SYNC},
+ {"show_triggers",ZBX_TYPE_INT, ZBX_SYNC},
+ {"graphtype", ZBX_TYPE_INT, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"sysmaps_links", "linkid", ZBX_SYNC,
+ {
+ {"linkid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"sysmapid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"selementid1", ZBX_TYPE_INT, ZBX_SYNC},
+ {"selementid2", ZBX_TYPE_INT, ZBX_SYNC},
+ {"triggerid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"drawtype_off",ZBX_TYPE_INT, ZBX_SYNC},
+ {"color_off", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"drawtype_on", ZBX_TYPE_INT, ZBX_SYNC},
+ {"color_on", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"sysmaps_elements", "selementid", ZBX_SYNC,
+ {
+ {"selementid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"sysmapid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"elementid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"elementtype", ZBX_TYPE_INT, ZBX_SYNC},
+ {"icon", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"icon_on", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"label", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"label_location",ZBX_TYPE_INT, ZBX_SYNC},
+ {"x", ZBX_TYPE_INT, ZBX_SYNC},
+ {"y", ZBX_TYPE_INT, ZBX_SYNC},
+ {"url", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"sysmaps", "sysmapid", ZBX_SYNC,
+ {
+ {"sysmapid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"name", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"width", ZBX_TYPE_INT, ZBX_SYNC},
+ {"height", ZBX_TYPE_INT, ZBX_SYNC},
+ {"background", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"label_type", ZBX_TYPE_INT, ZBX_SYNC},
+ {"label_location",ZBX_TYPE_INT, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"config", "configid", ZBX_SYNC,
+ {
+ {"configid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"alert_history", ZBX_TYPE_INT, ZBX_SYNC},
+ {"alarm_history", ZBX_TYPE_INT, ZBX_SYNC},
+ {"refresh_unsupported", ZBX_TYPE_INT, ZBX_SYNC},
+ {"work_period", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"groups", "groupid", ZBX_SYNC,
+ {
+ {"groupid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"name", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"hosts_groups", "hostgroupid", ZBX_SYNC,
+ {
+ {"hostgroupid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"hostid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"groupid", ZBX_TYPE_INT, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"alerts", "alertid", ZBX_SYNC,
+ {
+ {"alertid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"actionid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"triggerid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"userid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"clock", ZBX_TYPE_INT, ZBX_SYNC},
+ {"mediatypeid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"sendto", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"subject", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"message", ZBX_TYPE_BLOB, ZBX_SYNC},
+ {"status", ZBX_TYPE_INT, ZBX_SYNC},
+ {"retries", ZBX_TYPE_INT, ZBX_SYNC},
+ {"error", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"repeats", ZBX_TYPE_INT, ZBX_SYNC},
+ {"maxrepeats", ZBX_TYPE_INT, ZBX_SYNC},
+ {"nextcheck", ZBX_TYPE_INT, ZBX_SYNC},
+ {"delay", ZBX_TYPE_INT, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"actions", "actionid", ZBX_SYNC,
+ {
+ {"actionid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"userid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"subject", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"message", ZBX_TYPE_BLOB, ZBX_SYNC},
+ {"recipient", ZBX_TYPE_INT, ZBX_SYNC},
+ {"maxrepeats", ZBX_TYPE_INT, ZBX_SYNC},
+ {"repeatdelay", ZBX_TYPE_INT, ZBX_SYNC},
+ {"source", ZBX_TYPE_INT, ZBX_SYNC},
+ {"actiontype", ZBX_TYPE_INT, ZBX_SYNC},
+ {"status", ZBX_TYPE_INT, ZBX_SYNC},
+ {"scripts", ZBX_TYPE_BLOB, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"conditions", "conditionid", ZBX_SYNC,
+ {
+ {"conditionid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"actionid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"conditiontype", ZBX_TYPE_INT, ZBX_SYNC},
+ {"operator", ZBX_TYPE_INT, ZBX_SYNC},
+ {"value", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"alarms", "alarmid", ZBX_NOSYNC,
+ {
+ {"alarmid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"triggerid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"clock", ZBX_TYPE_INT, ZBX_SYNC},
+ {"value", ZBX_TYPE_INT, ZBX_SYNC},
+ {"acknowledged", ZBX_TYPE_INT, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"functions", "functionid", ZBX_SYNC,
+ {
+ {"functionid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"itemid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"triggerid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"lastvalue", ZBX_TYPE_CHAR, ZBX_NOSYNC},
+ {"function", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"parameter", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"history", NULL, ZBX_NOSYNC,
+ {
+ {"itemid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"clock", ZBX_TYPE_INT, ZBX_SYNC},
+ {"value", ZBX_TYPE_FLOAT, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"history_uint", NULL, ZBX_NOSYNC,
+ {
+ {"itemid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"clock", ZBX_TYPE_INT, ZBX_SYNC},
+ {"value", ZBX_TYPE_UINT, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"history_str", NULL, ZBX_NOSYNC,
+ {
+ {"itemid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"clock", ZBX_TYPE_INT, ZBX_SYNC},
+ {"value", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"hosts", "hostid", ZBX_SYNC,
+ {
+ {"hostid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"host", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"useip", ZBX_TYPE_INT, ZBX_SYNC},
+ {"ip", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"port", ZBX_TYPE_INT, ZBX_SYNC},
+ {"status", ZBX_TYPE_INT, ZBX_SYNC},
+ {"disable_until", ZBX_TYPE_INT, ZBX_NOSYNC},
+ {"error", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"available", ZBX_TYPE_INT, ZBX_SYNC},
+ {"errors_from", ZBX_TYPE_INT, ZBX_NOSYNC},
+ {"templateid", ZBX_TYPE_INT, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"items", "itemid", ZBX_SYNC,
+ {
+ {"itemid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"type", ZBX_TYPE_INT, ZBX_SYNC},
+ {"snmp_community", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"snmp_oid", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"snmp_port", ZBX_TYPE_INT, ZBX_SYNC},
+ {"hostid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"description", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"key_", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"delay", ZBX_TYPE_INT, ZBX_SYNC},
+ {"history", ZBX_TYPE_INT, ZBX_SYNC},
+ {"trends", ZBX_TYPE_INT, ZBX_SYNC},
+ {"nextcheck", ZBX_TYPE_INT, ZBX_NOSYNC},
+ {"lastvalue", ZBX_TYPE_CHAR, ZBX_NOSYNC},
+ {"lastclock", ZBX_TYPE_INT, ZBX_NOSYNC},
+ {"prevvalue", ZBX_TYPE_CHAR, ZBX_NOSYNC},
+ {"status", ZBX_TYPE_INT, ZBX_SYNC},
+ {"value_type", ZBX_TYPE_INT, ZBX_SYNC},
+ {"trapper_hosts", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"units", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"multiplier", ZBX_TYPE_INT, ZBX_SYNC},
+ {"delta", ZBX_TYPE_INT, ZBX_SYNC},
+ {"prevorgvalue", ZBX_TYPE_FLOAT, ZBX_NOSYNC},
+ {"snmpv3_securityname", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"snmpv3_securitylevel",ZBX_TYPE_INT, ZBX_SYNC},
+ {"snmpv3_authpassphrase",ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"snmpv3_privpassphrase",ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"formula", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"error", ZBX_TYPE_CHAR, ZBX_SYNC},
+
+ {"lastlogsize", ZBX_TYPE_INT, ZBX_NOSYNC},
+ {"logtimefmt", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"templateid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"valuemapid", ZBX_TYPE_INT, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"media", "mediaid", ZBX_SYNC,
+ {
+ {"mediaid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"userid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"mediatypeid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"sendto", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"active", ZBX_TYPE_INT, ZBX_SYNC},
+ {"severity", ZBX_TYPE_INT, ZBX_SYNC},
+ {"period", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"media_type", "mediatypeid", ZBX_SYNC,
+ {
+ {"mediatypeid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"type", ZBX_TYPE_INT, ZBX_SYNC},
+ {"description", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"smtp_server", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"smtp_helo", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"smtp_email", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"exec_path", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"gsm_modem", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"triggers", "triggerid", ZBX_SYNC,
+ {
+ {"triggerid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"expression", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"description", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"url", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"status", ZBX_TYPE_INT, ZBX_SYNC},
+ {"value", ZBX_TYPE_INT, ZBX_SYNC},
+ {"priority", ZBX_TYPE_INT, ZBX_SYNC},
+ {"lastchange", ZBX_TYPE_INT, ZBX_NOSYNC},
+ {"dep_level", ZBX_TYPE_INT, ZBX_SYNC},
+ {"comments", ZBX_TYPE_BLOB, ZBX_SYNC},
+ {"error", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"templateid", ZBX_TYPE_INT, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"trigger_depends", "triggerdepid", ZBX_SYNC,
+ {
+ {"triggerdepid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"triggerid_down", ZBX_TYPE_INT, ZBX_SYNC},
+ {"triggerid_up", ZBX_TYPE_INT, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"users", "userid", ZBX_SYNC,
+ {
+ {"userid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"alias", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"name", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"surname", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"passwd", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"url", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"autologout", ZBX_TYPE_INT, ZBX_SYNC},
+ {"lang", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"refresh", ZBX_TYPE_INT, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"auditlog", "auditid", ZBX_NOSYNC,
+ {
+ {"auditid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"userid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"clock", ZBX_TYPE_INT, ZBX_SYNC},
+ {"action", ZBX_TYPE_INT, ZBX_SYNC},
+ {"resourcetype", ZBX_TYPE_INT, ZBX_SYNC},
+ {"details", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"sessions", "sessionid", ZBX_NOSYNC,
+ {
+ {"sessionid", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"userid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"lastaccess", ZBX_TYPE_INT, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"rights", "rightid", ZBX_SYNC,
+ {
+ {"rightid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"userid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"name", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"permission", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"id", ZBX_TYPE_INT, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"service_alarms", "servicealarmid", ZBX_NOSYNC,
+ {
+ {"servicealarmid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"serviceid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"clock", ZBX_TYPE_INT, ZBX_SYNC},
+ {"value", ZBX_TYPE_INT, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"profiles", "profileid", ZBX_SYNC,
+ {
+ {"profileid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"userid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"idx", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"value", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"valuetype", ZBX_TYPE_INT, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"screens", "screenid", ZBX_SYNC,
+ {
+ {"screenid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"name", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"hsize", ZBX_TYPE_INT, ZBX_SYNC},
+ {"vsize", ZBX_TYPE_INT, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"screens_items", "screenitemid", ZBX_SYNC,
+ {
+ {"screenitemid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"screenid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"resourcetype", ZBX_TYPE_INT, ZBX_SYNC},
+ {"resourceid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"width", ZBX_TYPE_INT, ZBX_SYNC},
+ {"height", ZBX_TYPE_INT, ZBX_SYNC},
+ {"x", ZBX_TYPE_INT, ZBX_SYNC},
+ {"y", ZBX_TYPE_INT, ZBX_SYNC},
+ {"colspan", ZBX_TYPE_INT, ZBX_SYNC},
+ {"rowspan", ZBX_TYPE_INT, ZBX_SYNC},
+ {"elements", ZBX_TYPE_INT, ZBX_SYNC},
+ {"valign", ZBX_TYPE_INT, ZBX_SYNC},
+ {"halign", ZBX_TYPE_INT, ZBX_SYNC},
+ {"style", ZBX_TYPE_INT, ZBX_SYNC},
+ {"url", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"usrgrp", "usrgrpid", ZBX_SYNC,
+ {
+ {"usrgrpid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"name", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"users_groups", "id", ZBX_SYNC,
+ {
+ {"id", ZBX_TYPE_INT, ZBX_SYNC},
+ {"usrgrpid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"userid", ZBX_TYPE_INT, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"trends", NULL, ZBX_NOSYNC,
+ {
+ {"itemid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"clock", ZBX_TYPE_INT, ZBX_SYNC},
+ {"num", ZBX_TYPE_INT, ZBX_SYNC},
+ {"value_min", ZBX_TYPE_FLOAT, ZBX_SYNC},
+ {"value_avg", ZBX_TYPE_FLOAT, ZBX_SYNC},
+ {"value_max", ZBX_TYPE_FLOAT, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"images", "imageid", ZBX_SYNC,
+ {
+ {"imageid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"imagetype", ZBX_TYPE_INT, ZBX_SYNC},
+ {"name", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"image", ZBX_TYPE_BLOB, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"hosts_templates", "hosttemplateid", ZBX_SYNC,
+ {
+ {"hosttemplateid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"hostid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"templateid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"items", ZBX_TYPE_INT, ZBX_SYNC},
+ {"triggers", ZBX_TYPE_INT, ZBX_SYNC},
+ {"graphs", ZBX_TYPE_INT, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"history_log", "id", ZBX_NOSYNC,
+ {
+ {"id", ZBX_TYPE_INT, ZBX_SYNC},
+ {"itemid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"clock", ZBX_TYPE_INT, ZBX_SYNC},
+ {"timestamp", ZBX_TYPE_INT, ZBX_SYNC},
+ {"source", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"severity", ZBX_TYPE_INT, ZBX_SYNC},
+ {"value", ZBX_TYPE_TEXT, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"history_text", "id", ZBX_NOSYNC,
+ {
+ {"id", ZBX_TYPE_INT, ZBX_SYNC},
+ {"itemid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"clock", ZBX_TYPE_INT, ZBX_SYNC},
+ {"value", ZBX_TYPE_TEXT, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"hosts_profiles", "hostid", ZBX_SYNC,
+ {
+ {"hostid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"devicetype", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"name", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"os", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"serialno", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"tag", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"macaddress", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"hardware", ZBX_TYPE_BLOB, ZBX_SYNC},
+ {"software", ZBX_TYPE_BLOB, ZBX_SYNC},
+ {"contact", ZBX_TYPE_BLOB, ZBX_SYNC},
+ {"location", ZBX_TYPE_BLOB, ZBX_SYNC},
+ {"notes", ZBX_TYPE_BLOB, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"autoreg", "id", ZBX_SYNC,
+ {
+ {"id", ZBX_TYPE_INT, ZBX_SYNC},
+ {"priority", ZBX_TYPE_INT, ZBX_SYNC},
+ {"pattern", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"hostid", ZBX_TYPE_INT, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"valuemaps", "valuemapid", ZBX_SYNC,
+ {
+ {"valuemapid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"name", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"mappings", "mappingid", ZBX_SYNC,
+ {
+ {"mappingid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"valuemapid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"value", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"newvalue", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"housekeeper", "housekeeperid",ZBX_NOSYNC,
+ {
+ {"housekeeperid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"tablename", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"field", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"value", ZBX_TYPE_INT, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"acknowledges", "acknowledgeid", ZBX_SYNC,
+ {
+ {"acknowledgeid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"userid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"alarmid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"clock", ZBX_TYPE_INT, ZBX_SYNC},
+ {"message", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"applications", "applicationid", ZBX_SYNC,
+ {
+ {"applicationid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"hostid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"name", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"templateid", ZBX_TYPE_INT, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"items_applications", "itemappid", ZBX_SYNC,
+ {
+ {"itemappid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"applicationid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"itemid", ZBX_TYPE_INT, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"help_items", NULL, ZBX_NOSYNC,
+ {
+ {"itemtype", ZBX_TYPE_INT, ZBX_SYNC},
+ {"key_", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"description", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"node_cksum", "cksumid", ZBX_NOSYNC,
+ {
+ {"cksumid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"nodeid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"tablename", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"fieldname", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"recordid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"cksumtype", ZBX_TYPE_INT, ZBX_SYNC},
+ {"cksum", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {0}
+ }
+ },
+ {"node_configlog", "conflogif", ZBX_NOSYNC,
+ {
+ {"conflogid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"nodeid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"tablename", ZBX_TYPE_CHAR, ZBX_SYNC},
+ {"recordid", ZBX_TYPE_INT, ZBX_SYNC},
+ {"operation", ZBX_TYPE_INT, ZBX_SYNC},
+ {"sync_master", ZBX_TYPE_INT, ZBX_SYNC},
+ {"sync_slave", ZBX_TYPE_INT, ZBX_SYNC},
+ {0}
+ }
+ },
+ {0}
+};
+
+#endif
diff --git a/src/zabbix_server/Makefile.am b/src/zabbix_server/Makefile.am
index beb9dd06..a4e0b907 100644
--- a/src/zabbix_server/Makefile.am
+++ b/src/zabbix_server/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = alerter housekeeper pinger poller timer trapper
+SUBDIRS = alerter housekeeper pinger poller timer trapper nodewatcher nodesender
INCLUDES=-I@top_srcdir@/include @MYSQL_INCLUDE@ @ORACLE_INCLUDE@ @SNMP_INCLUDE@ @PGSQL_INCLUDE@
bin_PROGRAMS = zabbix_server
@@ -7,7 +7,8 @@ zabbix_server_CPPFLAGS = -DZABBIX_DAEMON
zabbix_server_LDADD = ../libs/zbxsysinfo/libzbxsysinfo.a ../libs/zbxsysinfo/@ARCH@/libzbxsysinfo2.a \
../libs/zbxlog/libzbxlog.a ../libs/zbxnix/libzbxnix.a ../libs/zbxsys/libzbxsys.a ../libs/zbxconf/libzbxconf.a \
../libs/zbxnet/libzbxnet.a pinger/libzbxpinger.a poller/libzbxpoller.a housekeeper/libzbxhousekeeper.a \
-alerter/libzbxalerter.a timer/libzbxtimer.a trapper/libzbxtrapper.a ../libs/zbxemail/libzbxemail.a \
+alerter/libzbxalerter.a timer/libzbxtimer.a trapper/libzbxtrapper.a nodewatcher/libzbxnodewatcher.a \
+nodesender/libzbxnodesender.a ../libs/zbxemail/libzbxemail.a \
../libs/zbxsms/libzbxsms.a ../libs/zbxdbhigh/libzbxdbhigh.a ../libs/zbxcommon/libzbxcommon.a \
../libs/zbxcrypto/libzbxcrypto.a @MYSQL_LIBS@ @PGSQL_LIBS@ @ORACLE_LIBS@ @LDAP_LIBS@ @SNMP_LIBS@
zabbix_server_LDFLAGS=@MYSQL_LFLAGS@ @PGSQL_LFLAGS@ @ORACLE_LFLAGS@ @LDAP_LFLAGS@ @SNMP_LFLAGS@
diff --git a/src/zabbix_server/actions.c b/src/zabbix_server/actions.c
index 86892f4c..bcc0a51d 100644
--- a/src/zabbix_server/actions.c
+++ b/src/zabbix_server/actions.c
@@ -234,7 +234,8 @@ static void run_remote_command(char* host_name, char* command)
zabbix_log(LOG_LEVEL_DEBUG, "run_remote_command START [hostname: '%s', command: '%s']", host_name, command);
- result = DBselect("select distinct host,ip,useip,port from hosts where host='%s'", host_name);
+ result = DBselect("select distinct host,ip,useip,port from hosts where host='%s' and " ZBX_COND_NODEID,
+ host_name, LOCAL_NODE("hostid"));
row = DBfetch(result);
if(row)
{
@@ -380,7 +381,7 @@ static int get_next_command(char** command_list, char** alias, int* is_group, ch
if(alias == '\0' || command == '\0') continue;
if(is_group)
{
- result = DBselect("select distinct h.host from hosts_groups hg,hosts h, groups g where hg.hostid=h.hostid and hg.groupid=g.groupid and g.name='%s'", alias);
+ result = DBselect("select distinct h.host from hosts_groups hg,hosts h, groups g where hg.hostid=h.hostid and hg.groupid=g.groupid and g.name='%s' and" ZBX_COND_NODEID, alias, LOCAL_NODE("h.hostid"));
while((row=DBfetch(result)))
{
run_remote_command(row[0], command);
@@ -683,7 +684,7 @@ void apply_actions(DB_TRIGGER *trigger,int alarmid,int trigger_value)
/* zbx_snprintf(sql,sizeof(sql),"select actionid,userid,delay,subject,message,recipient,maxrepeats,repeatdelay,scripts,actiontype from actions where nextcheck<=%d and status=%d", now, ACTION_STATUS_ACTIVE);*/
/* No support of action delay anymore */
- result = DBselect("select actionid,userid,subject,message,recipient,maxrepeats,repeatdelay,scripts,actiontype from actions where status=%d", ACTION_STATUS_ACTIVE);
+ result = DBselect("select actionid,userid,subject,message,recipient,maxrepeats,repeatdelay,scripts,actiontype from actions where status=%d and" ZBX_COND_NODEID, ACTION_STATUS_ACTIVE, LOCAL_NODE("actionid"));
while((row=DBfetch(result)))
{
diff --git a/src/zabbix_server/actions.h b/src/zabbix_server/actions.h
index 2d9becd7..983d7ee7 100644
--- a/src/zabbix_server/actions.h
+++ b/src/zabbix_server/actions.h
@@ -24,6 +24,8 @@
#include "common.h"
#include "db.h"
+extern int CONFIG_NODEID;
+
void apply_actions(DB_TRIGGER *trigger,int alarmid,int trigger_value);
#endif
diff --git a/src/zabbix_server/alerter/alerter.c b/src/zabbix_server/alerter/alerter.c
index 472fba96..7b22b115 100644
--- a/src/zabbix_server/alerter/alerter.c
+++ b/src/zabbix_server/alerter/alerter.c
@@ -177,7 +177,7 @@ int main_alerter_loop()
now = time(NULL);
/* zbx_snprintf(sql,sizeof(sql),"select a.alertid,a.mediatypeid,a.sendto,a.subject,a.message,a.status,a.retries,mt.mediatypeid,mt.type,mt.description,mt.smtp_server,mt.smtp_helo,mt.smtp_email,mt.exec_path from alerts a,media_type mt where a.status=0 and a.retries<3 and a.mediatypeid=mt.mediatypeid order by a.clock"); */
- result = DBselect("select a.alertid,a.mediatypeid,a.sendto,a.subject,a.message,a.status,a.retries,mt.mediatypeid,mt.type,mt.description,mt.smtp_server,mt.smtp_helo,mt.smtp_email,mt.exec_path,a.delay,mt.gsm_modem from alerts a,media_type mt where a.status=%d and a.retries<3 and (a.repeats<a.maxrepeats or a.maxrepeats=0) and a.nextcheck<=%d and a.mediatypeid=mt.mediatypeid order by a.clock", ALERT_STATUS_NOT_SENT, now);
+ result = DBselect("select a.alertid,a.mediatypeid,a.sendto,a.subject,a.message,a.status,a.retries,mt.mediatypeid,mt.type,mt.description,mt.smtp_server,mt.smtp_helo,mt.smtp_email,mt.exec_path,a.delay,mt.gsm_modem from alerts a,media_type mt where a.status=%d and a.retries<3 and (a.repeats<a.maxrepeats or a.maxrepeats=0) and a.nextcheck<=%d and a.mediatypeid=mt.mediatypeid and " ZBX_COND_NODEID " order by a.clock", ALERT_STATUS_NOT_SENT, now, LOCAL_NODE("mt.mediatypeid"));
while((row=DBfetch(result)))
{
diff --git a/src/zabbix_server/alerter/alerter.h b/src/zabbix_server/alerter/alerter.h
index 5fba1229..1b2f69d7 100644
--- a/src/zabbix_server/alerter/alerter.h
+++ b/src/zabbix_server/alerter/alerter.h
@@ -28,6 +28,8 @@ extern char *CONFIG_DBPASSWORD;
extern char *CONFIG_DBSOCKET;
extern char *CONFIG_ALERT_SCRIPTS_PATH;
+extern int CONFIG_NODEID;
+
extern void signal_handler( int sig );
int main_alerter_loop();
diff --git a/src/zabbix_server/evalfunc.c b/src/zabbix_server/evalfunc.c
index 679e92b0..29b7a1d6 100644
--- a/src/zabbix_server/evalfunc.c
+++ b/src/zabbix_server/evalfunc.c
@@ -1263,7 +1263,7 @@ int evaluate_FUNCTION2(char *value,char *host,char *key,char *function,char *par
zabbix_log(LOG_LEVEL_DEBUG, "In evaluate_FUNCTION2()" );
- result = DBselect("select %s where h.host='%s' and h.hostid=i.hostid and i.key_='%s'", ZBX_SQL_ITEM_SELECT, host, key );
+ result = DBselect("select %s where h.host='%s' and h.hostid=i.hostid and i.key_='%s'" ZBX_COND_NODEID, ZBX_SQL_ITEM_SELECT, host, key, LOCAL_NODE("h.hostid"));
row = DBfetch(result);
diff --git a/src/zabbix_server/evalfunc.h b/src/zabbix_server/evalfunc.h
index 348a61f0..eca3e118 100644
--- a/src/zabbix_server/evalfunc.h
+++ b/src/zabbix_server/evalfunc.h
@@ -30,6 +30,7 @@
#define ZBX_FLAG_SEC 0
#define ZBX_FLAG_VALUES 1
+extern int CONFIG_NODEID;
int evaluate_FUNCTION(char *value,DB_ITEM *item,char *function,char *parameter);
int evaluate_FUNCTION2(char *value,char *host,char *key,char *function,char *parameter);
diff --git a/src/zabbix_server/functions.c b/src/zabbix_server/functions.c
index 2ff3c25c..2262eb7e 100644
--- a/src/zabbix_server/functions.c
+++ b/src/zabbix_server/functions.c
@@ -412,7 +412,7 @@ int process_data(int sockfd,char *server,char *key,char *value,char *lastlogsize
DBescape_string(server, server_esc, MAX_STRING_LEN);
DBescape_string(key, key_esc, MAX_STRING_LEN);
- result = DBselect("select %s where h.status=%d and h.hostid=i.hostid and h.host='%s' and i.key_='%s' and i.status=%d and i.type in (%d,%d)", ZBX_SQL_ITEM_SELECT, HOST_STATUS_MONITORED, server_esc, key_esc, ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE);
+ result = DBselect("select %s where h.status=%d and h.hostid=i.hostid and h.host='%s' and i.key_='%s' and i.status=%d and i.type in (%d,%d) and" ZBX_COND_NODEID, ZBX_SQL_ITEM_SELECT, HOST_STATUS_MONITORED, server_esc, key_esc, ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, LOCAL_NODE("h.hostid"));
row=DBfetch(result);
@@ -425,7 +425,7 @@ int process_data(int sockfd,char *server,char *key,char *value,char *lastlogsize
DBfree_result(result);
/* Same SQL */
- result = DBselect("select %s where h.status=%d and h.hostid=i.hostid and h.host='%s' and i.key_='%s' and i.status=%d and i.type in (%d,%d)", ZBX_SQL_ITEM_SELECT, HOST_STATUS_MONITORED, server_esc, key_esc, ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE);
+ result = DBselect("select %s where h.status=%d and h.hostid=i.hostid and h.host='%s' and i.key_='%s' and i.status=%d and i.type in (%d,%d) and" ZBX_COND_NODEID, ZBX_SQL_ITEM_SELECT, HOST_STATUS_MONITORED, server_esc, key_esc, ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, LOCAL_NODE("hostid"));
row = DBfetch(result);
if(!row)
{
diff --git a/src/zabbix_server/nodesender/Makefile.am b/src/zabbix_server/nodesender/Makefile.am
new file mode 100644
index 00000000..53ab135c
--- /dev/null
+++ b/src/zabbix_server/nodesender/Makefile.am
@@ -0,0 +1,4 @@
+SUBDIRS=
+INCLUDES=-I@top_srcdir@/include @MYSQL_INCLUDE@ @ORACLE_INCLUDE@
+lib_LIBRARIES=libzbxnodesender.a
+libzbxnodesender_a_SOURCES=nodesender.c
diff --git a/src/zabbix_server/nodesender/nodesender.c b/src/zabbix_server/nodesender/nodesender.c
new file mode 100644
index 00000000..8f3f1c61
--- /dev/null
+++ b/src/zabbix_server/nodesender/nodesender.c
@@ -0,0 +1,589 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2006 SIA Zabbix
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+
+#include <sys/wait.h>
+
+#include <string.h>
+
+#ifdef HAVE_NETDB_H
+ #include <netdb.h>
+#endif
+
+/* Required for getpwuid */
+#include <pwd.h>
+
+#include <signal.h>
+#include <errno.h>
+
+#include <time.h>
+
+#include "common.h"
+#include "cfg.h"
+#include "db.h"
+#include "log.h"
+#include "zlog.h"
+
+#include "dbsync.h"
+#include "nodesender.h"
+
+#define ZBX_NODE_MASTER 0
+#define ZBX_NODE_SLAVE 1
+
+extern int CONFIG_NODEID;
+
+/******************************************************************************
+ * *
+ * Function: send_to_node *
+ * *
+ * Purpose: send configuration changes to required node *
+ * *
+ * Parameters: *
+ * *
+ * Return value: SUCCESS - processed succesfully *
+ * FAIL - an error occured *
+ * *
+ * Author: Alexei Vladishev *
+ * *
+ * Comments: *
+ * *
+ ******************************************************************************/
+static int send_to_node(int dest_nodeid, int nodeid, char *xml)
+{
+ int i,s;
+ char answer[MAX_STRING_LEN];
+ struct hostent *hp;
+
+ struct sockaddr_in myaddr_in;
+ struct sockaddr_in servaddr_in;
+ char ip[MAX_STRING_LEN];
+ int port;
+ int ret = FAIL;
+ int written;
+
+ DB_RESULT result;
+ DB_ROW row;
+
+// zabbix_log( LOG_LEVEL_WARNING, "In send_to_node (%d,%d)", nodeid, strlen(xml));
+// zabbix_log( LOG_LEVEL_WARNING, "NODE %d: Sending data of node %d to node %d", CONFIG_NODEID, nodeid, dest_nodeid);
+
+ result = DBselect("select ip, port from nodes where nodeid=%d", dest_nodeid);
+ row = DBfetch(result);
+ if(!row)
+ {
+ DBfree_result(result);
+ zabbix_log( LOG_LEVEL_WARNING, "Node [%d] in unknown", dest_nodeid);
+ return FAIL;
+ }
+ strncpy(ip,row[0],sizeof(ip));
+ port=atoi(row[1]);
+ DBfree_result(result);
+
+// zabbix_log( LOG_LEVEL_WARNING, "In send_to_node IP (%s:%d)", ip, port);
+ servaddr_in.sin_family=AF_INET;
+ hp=gethostbyname(ip);
+
+ if(hp==NULL)
+ {
+ zabbix_log( LOG_LEVEL_WARNING, "Cannot resolve [%s] for node [%d]", ip, dest_nodeid);
+ return FAIL;
+ }
+
+ servaddr_in.sin_addr.s_addr=((struct in_addr *)(hp->h_addr))->s_addr;
+
+ servaddr_in.sin_port=htons(port);
+
+ s=socket(AF_INET,SOCK_STREAM,0);
+ if(s == -1)
+ {
+ zabbix_log( LOG_LEVEL_WARNING, "Cannot create socket [%s] for node [%d]", ip, dest_nodeid);
+ return FAIL;
+ }
+
+ myaddr_in.sin_family = AF_INET;
+ myaddr_in.sin_port=0;
+ myaddr_in.sin_addr.s_addr=INADDR_ANY;
+
+ if( connect(s,(struct sockaddr *)&servaddr_in,sizeof(struct sockaddr_in)) == -1 )
+ {
+ zabbix_log( LOG_LEVEL_WARNING, "Cannot connect [%s] to node [%d]", ip, dest_nodeid);
+ close(s);
+ return FAIL;
+ }
+
+ written = 0;
+
+ while(written<strlen(xml))
+ {
+ i=write(s, xml+written,strlen(xml)-written);
+ if(i == -1)
+ {
+ zabbix_log( LOG_LEVEL_WARNING, "Error writing to node [%d] [%s]", dest_nodeid, strerror(errno));
+ close(s);
+ return FAIL;
+ }
+ written+=i;
+// zabbix_log( LOG_LEVEL_WARNING, "Wrote %d of %d bytes to node %d", written, strlen(xml), nodeid);
+ }
+ i=sizeof(struct sockaddr_in);
+/* i=recvfrom(s,result,MAX_STRING_LEN-1,0,(struct sockaddr *)&servaddr_in,(socklen_t *)&i);*/
+ i=read(s,answer,MAX_STRING_LEN-1);
+ if(i==-1)
+ {
+ zabbix_log( LOG_LEVEL_WARNING, "Error reading from node [%d]", dest_nodeid);
+ close(s);
+ return FAIL;
+ }
+
+ answer[i-1]=0;
+
+ if(strcmp(answer,"OK") == 0)
+ {
+ ret = SUCCEED;
+ }
+
+ if( close(s)!=0 )
+ {
+ }
+
+ return ret;
+}
+
+/******************************************************************************
+ * *
+ * Function: send_config_data *
+ * *
+ * Purpose: send configuration changes to required node *
+ * *
+ * Parameters: *
+ * *
+ * Return value: SUCCESS - processed succesfully *
+ * FAIL - an error occured *
+ * *
+ * Author: Alexei Vladishev *
+ * *
+ * Comments: *
+ * *
+ ******************************************************************************/
+static int send_config_data(int nodeid, int dest_nodeid, int maxlogid, int node_type)
+{
+ DB_RESULT result;
+ DB_RESULT result2;
+ DB_ROW row;
+ DB_ROW row2;
+
+#define ZBX_XML_MAX 161024*1024
+ char *xml;
+ char tmp[MAX_STRING_LEN];
+ char fields[MAX_STRING_LEN];
+
+ int i,j;
+
+ xml=malloc(ZBX_XML_MAX);
+
+ xml[0]=0;
+
+// zabbix_log( LOG_LEVEL_WARNING, "In send_config_data(local:%d,nodeid:%d,dest_node:%d,maxlogid:%d,type:%d)",local_nodeid, nodeid, dest_nodeid,maxlogid,node_type);
+
+ /* Begin work */
+ if(node_type == ZBX_NODE_MASTER)
+ {
+ result=DBselect("select tablename,recordid,operation from node_configlog where nodeid=%d and sync_master=0 and conflogid<=%d order by tablename,operation", nodeid, maxlogid);
+ }
+ else
+ {
+ result=DBselect("select tablename,recordid,operation from node_configlog where nodeid=%d and sync_slave=0 and conflogid<=%d order by tablename,operation", nodeid, maxlogid);
+ }
+
+// snprintf(tmp,sizeof(tmp),"<Data type='config'>\n<Node id='%d'>\n</Node>\n<Version>1.4</Version>\n<Records>\n", nodeid);
+ zbx_snprintf(tmp,sizeof(tmp),"Data|%d|%d\n", CONFIG_NODEID, nodeid);
+ strncat(xml,tmp,ZBX_XML_MAX);
+
+ while((row=DBfetch(result)))
+ {
+// zabbix_log( LOG_LEVEL_WARNING, "Fetched [%s,%s,%s]",row[0],row[1],row[2]);
+ for(i=0;tables[i].table!=0;i++)
+ {
+ if(strcmp(tables[i].table, row[0])==0) break;
+ }
+
+ /* Found table */
+ if(tables[i].table!=0)
+ {
+ fields[0]=0;
+ /* for each field */
+ for(j=0;tables[i].fields[j].name!=0;j++)
+ {
+ strncat(fields,tables[i].fields[j].name,sizeof(fields));
+ strncat(fields,",",sizeof(fields));
+ }
+ if(fields[0]!=0) fields[strlen(fields)-1]=0;
+
+ result2=DBselect("select %s from %s where %s=%s", fields, row[0], tables[i].recid,row[1]);
+// zabbix_log( LOG_LEVEL_WARNING,"select %s from %s where %s=%s",fields, row[0], tables[i].recid,row[1]);
+ row2=DBfetch(result2);
+
+ if(row2)
+ {
+ zbx_snprintf(tmp,sizeof(tmp),"%s|%s|%s",
+ row[0], row[1], row[2]);
+// zabbix_log( LOG_LEVEL_WARNING, "TMP [%s]",tmp);
+ strncat(xml,tmp,ZBX_XML_MAX);
+ /* for each field */
+ for(j=0;tables[i].fields[j].name!=0;j++)
+ {
+// snprintf(tmp,sizeof(tmp),"<Record table='%s' field='%s' op='%s' recid='%s'>%s<Record>\n",
+// row[0], tables[i].fields[j].name, row[2], row[1], row2[j]);
+// // Fieldname, type, value
+ if(DBis_null(row2[j]) == SUCCEED)
+ {
+// zabbix_log( LOG_LEVEL_WARNING, "Field name [%s] [%s]",tables[i].fields[j].name,row2[j]);
+// if(strcmp("snmpv3_securityname",tables[i].fields[j].name)==0)
+// {
+// zabbix_log( LOG_LEVEL_WARNING, "snmpv3_securityname [%s]",row2[j]);
+// }
+ zbx_snprintf(tmp,sizeof(tmp),"|%s|%d|NULL",
+ tables[i].fields[j].name,tables[i].fields[j].type);
+ }
+ else
+ {
+ zbx_snprintf(tmp,sizeof(tmp),"|%s|%d|%s",
+ tables[i].fields[j].name,tables[i].fields[j].type,row2[j]);
+// if(strcmp("snmpv3_securityname",tables[i].fields[j].name)==0)
+// {
+// zabbix_log( LOG_LEVEL_WARNING, "snmpv3_securityname 2[%s]",row2[j]);
+// }
+ }
+// zabbix_log( LOG_LEVEL_WARNING, "TMP [%s]",tmp);
+ strncat(xml,tmp,ZBX_XML_MAX);
+ }
+ strncat(xml,"\n",ZBX_XML_MAX);
+
+ }
+ else
+ {
+ zabbix_log( LOG_LEVEL_WARNING, "Cannot select %s from table [%s]",tables[i].fields[j],row[0]);
+ }
+ DBfree_result(result2);
+ }
+ else
+ {
+ zabbix_log( LOG_LEVEL_WARNING, "Cannot find table [%s]",row[0]);
+ }
+ }
+// snprintf(tmp,sizeof(tmp),"</Records></Data>\n");
+// strncat(xml,tmp,ZBX_XML_MAX);
+//
+// zabbix_log( LOG_LEVEL_WARNING, "DATA [%s]",xml);
+ if(send_to_node(dest_nodeid, nodeid, xml) == SUCCEED)
+ {
+ if(node_type == ZBX_NODE_MASTER)
+ {
+ DBexecute("update node_configlog set sync_master=1 where nodeid=%d and sync_master=0 and conflogid<=%d", nodeid, maxlogid);
+ }
+ else
+ {
+ DBexecute("update node_configlog set sync_slave=1 where nodeid=%d and sync_slave=0 and conflogid<=%d", nodeid, maxlogid);
+ }
+ }
+
+ DBfree_result(result);
+ free(xml);
+ /* Commit */
+
+ return SUCCEED;
+}
+
+/******************************************************************************
+ * *
+ * Function: get_slave_node *
+ * *
+ * Purpose: send configuration changes to required node *
+ * *
+ * Parameters: *
+ * *
+ * Return value: SUCCESS - processed succesfully *
+ * FAIL - an error occured *
+ * *
+ * Author: Alexei Vladishev *
+ * *
+ * Comments: *
+ * *
+ ******************************************************************************/
+static int get_slave_node(int nodeid)
+{
+ DB_RESULT result;
+ DB_ROW row;
+ int ret = 0;
+ int m;
+
+// zabbix_log( LOG_LEVEL_WARNING, "In get_slave_node(%d,%d)",local_nodeid, nodeid);
+ /* Begin work */
+
+ result = DBselect("select masterid from nodes where nodeid=%d", nodeid);
+ row = DBfetch(result);
+ if(row)
+ {
+ m = atoi(row[0]);
+ if(m == CONFIG_NODEID)
+ {
+ ret = nodeid;
+ }
+ else if(m ==0)
+ {
+ ret = m;
+ }
+ else ret = get_slave_node(m);
+ }
+ DBfree_result(result);
+
+ return ret;
+}
+
+/******************************************************************************
+ * *
+ * Function: get_master_node *
+ * *
+ * Purpose: send configuration changes to required node *
+ * *
+ * Parameters: *
+ * *
+ * Return value: SUCCESS - processed succesfully *
+ * FAIL - an error occured *
+ * *
+ * Author: Alexei Vladishev *
+ * *
+ * Comments: *
+ * *
+ ******************************************************************************/
+static int get_master_node(int nodeid)
+{
+ DB_RESULT result;
+ DB_ROW row;
+ int ret = 0;
+
+// zabbix_log( LOG_LEVEL_WARNING, "In get_master_node(%d,%d)",local_nodeid, nodeid);
+ /* Begin work */
+
+ result = DBselect("select masterid from nodes where nodeid=%d", CONFIG_NODEID);
+ row = DBfetch(result);
+ if(row)
+ {
+ ret = atoi(row[0]);
+ }
+ DBfree_result(result);
+
+ return ret;
+}
+
+/******************************************************************************
+ * *
+ * Function: send_config_data *
+ * *
+ * Purpose: send configuration changes to required node *
+ * *
+ * Parameters: *
+ * *
+ * Return value: SUCCESS - processed succesfully *
+ * FAIL - an error occured *
+ * *
+ * Author: Alexei Vladishev *
+ * *
+ * Comments: *
+ * *
+ ******************************************************************************/
+static int send_to_master_and_slave(int nodeid)
+{
+ DB_RESULT result;
+ DB_ROW row;
+ int master_nodeid, slave_nodeid;
+ int master_result, slave_result;
+ int maxlogid;
+
+// zabbix_log( LOG_LEVEL_WARNING, "In send_to_master_and_slave(local:%d,node:%d)",local_nodeid, nodeid);
+ /* Begin work */
+
+ result = DBselect("select min(conflogid),max(conflogid) from node_configlog where nodeid=%d", nodeid);
+
+ row = DBfetch(result);
+
+ if(DBis_null(row[0]) == SUCCEED)
+ {
+// zabbix_log( LOG_LEVEL_WARNING, "No configuration changes of node %d on node %d", nodeid, local_nodeid);
+ DBfree_result(result);
+ return SUCCEED;
+ }
+ if(atoi(row[1])-atoi(row[0])>200)
+ {
+ maxlogid = atoi(row[0])+200;
+ }
+ else
+ {
+ maxlogid = atoi(row[1]);
+ }
+ DBfree_result(result);
+
+
+ /* Send data to master and slave if required */
+// zabbix_log( LOG_LEVEL_WARNING, "Node [%d]", nodeid);
+// zabbix_log( LOG_LEVEL_WARNING, "Local node [%d]", local_nodeid);
+ master_nodeid=get_master_node(nodeid);
+// zabbix_log( LOG_LEVEL_WARNING, "Master node [%d]", master_nodeid);
+ slave_nodeid=get_slave_node(nodeid);
+// zabbix_log( LOG_LEVEL_WARNING, "Slave node [%d]", slave_nodeid);
+
+ if(master_nodeid != 0)
+ {
+ master_result = send_config_data(nodeid, master_nodeid, maxlogid, ZBX_NODE_MASTER);
+ }
+
+ if(slave_nodeid != 0)
+ {
+ slave_result = send_config_data(nodeid, slave_nodeid, maxlogid, ZBX_NODE_SLAVE);
+ }
+
+ if( (master_nodeid!=0) && (slave_nodeid != 0))
+ {
+ if((master_result == SUCCEED) && (slave_result == SUCCEED))
+ {
+ DBexecute("delete from node_configlog where nodeid=%d and sync_slave=1 and sync_master=1 and conflogid<=%d", nodeid, maxlogid);
+// zabbix_log(LOG_LEVEL_WARNING,"delete from node_configlog where nodeid=%d and sync_slave=1 and sync_master=1 and conflogid<=%d", nodeid, maxlogid);
+ }
+ }
+
+ if(master_nodeid!=0)
+ {
+ if(master_result == SUCCEED)
+ {
+ DBexecute("delete from node_configlog where nodeid=%d and sync_master=1 and conflogid<=%d", nodeid, maxlogid);
+// zabbix_log(LOG_LEVEL_WARNING,"delete from node_configlog where nodeid=%d and sync_master=1 and conflogid<=%d", nodeid, maxlogid);
+ }
+ }
+
+ if(slave_nodeid!=0)
+ {
+ if(slave_result == SUCCEED)
+ {
+ DBexecute("delete from node_configlog where nodeid=%d and sync_slave=1 and conflogid<=%d", nodeid, maxlogid);
+// zabbix_log(LOG_LEVEL_WARNING,"delete from node_configlog where nodeid=%d and sync_slave=1 and conflogid<=%d", nodeid, maxlogid);
+ }
+ }
+
+ return SUCCEED;
+}
+
+
+/******************************************************************************
+ * *
+ * Function: process_node *
+ * *
+ * Purpose: select all related nodes and send config changes *
+ * *
+ * Parameters: *
+ * *
+ * Return value: SUCCESS - processed succesfully *
+ * FAIL - an error occured *
+ * *
+ * Author: Alexei Vladishev *
+ * *
+ * Comments: *
+ * *
+ ******************************************************************************/
+static int process_node(int nodeid)
+{
+ DB_RESULT result;
+ DB_ROW row;
+
+// zabbix_log( LOG_LEVEL_WARNING, "In process_node(local:%d,node:%d)",local_nodeid, nodeid);
+ /* Begin work */
+
+ send_to_master_and_slave(nodeid);
+
+ result = DBselect("select nodeid from nodes where masterid=%d", nodeid);
+ while((row=DBfetch(result)))
+ {
+ process_node(atoi(row[0]));
+ }
+ DBfree_result(result);
+
+ return SUCCEED;
+}
+
+/******************************************************************************
+ * *
+ * Function: main_nodesender_loop *
+ * *
+ * Purpose: periodically sends config changes and history to related nodes *
+ * *
+ * Parameters: *
+ * *
+ * Return value: *
+ * *
+ * Author: Alexei Vladishev *
+ * *
+ * Comments: never returns *
+ * *
+ ******************************************************************************/
+int main_nodesender_loop()
+{
+ DB_RESULT result;
+ DB_ROW row;
+
+// zabbix_log( LOG_LEVEL_WARNING, "In main_nodesender_loop()");
+ for(;;)
+ {
+
+ zbx_setproctitle("connecting to the database");
+
+ DBconnect();
+
+ result = DBselect("select nodeid from nodes where nodetype=%d",NODE_TYPE_LOCAL);
+
+ row = DBfetch(result);
+
+ if(row)
+ {
+ if(CONFIG_NODEID != atoi(row[0]))
+ {
+ zabbix_log( LOG_LEVEL_WARNING, "NodeID does not match configuration settings. Processing of the node is disabled.");
+ }
+ else
+ {
+ process_node(atoi(row[0]));
+ }
+ }
+
+ DBfree_result(result);
+
+ DBclose();
+
+ zbx_setproctitle("node sender [sleeping for %d seconds]", 30);
+
+ sleep(30);
+ }
+}
diff --git a/src/zabbix_server/nodesender/nodesender.h b/src/zabbix_server/nodesender/nodesender.h
new file mode 100644
index 00000000..23d735d5
--- /dev/null
+++ b/src/zabbix_server/nodesender/nodesender.h
@@ -0,0 +1,26 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#ifndef ZABBIX_NODESENDER_H
+#define ZABBIX_NODESENDER_H
+
+
+int main_nodesender_loop();
+
+#endif
diff --git a/src/zabbix_server/nodewatcher/.deps/nodewatcher.Po b/src/zabbix_server/nodewatcher/.deps/nodewatcher.Po
new file mode 100644
index 00000000..0c9aef3d
--- /dev/null
+++ b/src/zabbix_server/nodewatcher/.deps/nodewatcher.Po
@@ -0,0 +1,396 @@
+nodewatcher.o nodewatcher.o: nodewatcher.c ../../../include/config.h \
+ /usr/include/stdio.h /usr/include/features.h /usr/include/sys/cdefs.h \
+ /usr/include/gnu/stubs.h \
+ /usr/lib/gcc-lib/x86_64-linux-gnu/3.3.6/include/stddef.h \
+ /usr/include/bits/types.h /usr/include/bits/wordsize.h \
+ /usr/include/bits/typesizes.h /usr/include/libio.h \
+ /usr/include/_G_config.h /usr/include/wchar.h /usr/include/bits/wchar.h \
+ /usr/include/gconv.h \
+ /usr/lib/gcc-lib/x86_64-linux-gnu/3.3.6/include/stdarg.h \
+ /usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h \
+ /usr/include/stdlib.h /usr/include/sys/types.h /usr/include/time.h \
+ /usr/include/endian.h /usr/include/bits/endian.h \
+ /usr/include/sys/select.h /usr/include/bits/select.h \
+ /usr/include/bits/sigset.h /usr/include/bits/time.h \
+ /usr/include/sys/sysmacros.h /usr/include/bits/pthreadtypes.h \
+ /usr/include/alloca.h /usr/include/unistd.h \
+ /usr/include/bits/posix_opt.h /usr/include/bits/confname.h \
+ /usr/include/getopt.h /usr/include/sys/stat.h /usr/include/bits/stat.h \
+ /usr/include/sys/socket.h /usr/include/sys/uio.h \
+ /usr/include/bits/uio.h /usr/include/bits/socket.h \
+ /usr/lib/gcc-lib/x86_64-linux-gnu/3.3.6/include/limits.h \
+ /usr/lib/gcc-lib/x86_64-linux-gnu/3.3.6/include/syslimits.h \
+ /usr/include/limits.h /usr/include/bits/posix1_lim.h \
+ /usr/include/bits/local_lim.h /usr/include/linux/limits.h \
+ /usr/include/bits/posix2_lim.h /usr/include/bits/sockaddr.h \
+ /usr/include/asm/socket.h /usr/include/asm-x86_64/socket.h \
+ /usr/include/asm/sockios.h /usr/include/asm-x86_64/sockios.h \
+ /usr/include/netinet/in.h /usr/include/stdint.h /usr/include/bits/in.h \
+ /usr/include/bits/byteswap.h /usr/include/sys/wait.h \
+ /usr/include/signal.h /usr/include/bits/signum.h \
+ /usr/include/bits/siginfo.h /usr/include/bits/sigaction.h \
+ /usr/include/bits/sigcontext.h /usr/include/bits/sigstack.h \
+ /usr/include/bits/sigthread.h /usr/include/sys/resource.h \
+ /usr/include/bits/resource.h /usr/include/bits/waitflags.h \
+ /usr/include/bits/waitstatus.h /usr/include/string.h \
+ /usr/include/netdb.h /usr/include/rpc/netdb.h /usr/include/bits/netdb.h \
+ /usr/include/pwd.h /usr/include/errno.h /usr/include/bits/errno.h \
+ /usr/include/linux/errno.h /usr/include/asm/errno.h \
+ /usr/include/asm-x86_64/errno.h ../../../include/common.h \
+ ../../../include/sysinc.h /usr/include/assert.h /usr/include/ctype.h \
+ /usr/include/strings.h /usr/include/sys/time.h \
+ /usr/include/linux/kernel.h /usr/include/arpa/nameser.h \
+ /usr/include/sys/param.h /usr/include/linux/param.h \
+ /usr/include/asm/param.h /usr/include/asm-x86_64/param.h \
+ /usr/include/sys/bitypes.h /usr/include/arpa/nameser_compat.h \
+ /usr/include/dirent.h /usr/include/bits/dirent.h /usr/include/fcntl.h \
+ /usr/include/bits/fcntl.h /usr/include/ldap.h /usr/include/lber.h \
+ /usr/include/lber_types.h /usr/include/ldap_cdefs.h \
+ /usr/include/ldap_features.h /usr/include/sys/procfs.h \
+ /usr/include/sys/user.h /usr/include/pthread.h /usr/include/sched.h \
+ /usr/include/bits/sched.h /usr/include/bits/setjmp.h \
+ /usr/include/resolv.h /usr/include/sys/statvfs.h \
+ /usr/include/bits/statvfs.h /usr/include/sys/swap.h \
+ /usr/include/sys/syscall.h /usr/include/asm/unistd.h \
+ /usr/include/asm-x86_64/unistd.h /usr/include/bits/syscall.h \
+ /usr/include/sys/sysctl.h /usr/include/linux/sysctl.h \
+ /usr/include/linux/types.h /usr/include/sys/sysinfo.h \
+ /usr/include/sys/vfs.h /usr/include/sys/statfs.h \
+ /usr/include/bits/statfs.h /usr/include/net/if.h /usr/include/syslog.h \
+ /usr/include/sys/syslog.h /usr/include/sys/ipc.h \
+ /usr/include/bits/ipctypes.h /usr/include/bits/ipc.h \
+ /usr/include/sys/sem.h /usr/include/bits/sem.h /usr/include/sys/shm.h \
+ /usr/include/bits/shm.h /usr/include/math.h \
+ /usr/include/bits/huge_val.h /usr/include/bits/mathdef.h \
+ /usr/include/bits/mathcalls.h /usr/include/regex.h \
+ /usr/include/arpa/inet.h /usr/include/sys/mount.h \
+ /usr/include/sys/ioctl.h /usr/include/bits/ioctls.h \
+ /usr/include/asm/ioctls.h /usr/include/asm-x86_64/ioctls.h \
+ /usr/include/asm/ioctl.h /usr/include/asm-x86_64/ioctl.h \
+ /usr/include/bits/ioctl-types.h /usr/include/sys/ttydefaults.h \
+ /usr/include/sys/timeb.h ../../../include/zbxtypes.h \
+ ../../../include/cfg.h ../../../include/db.h /usr/include/mysql/mysql.h \
+ /usr/include/mysql/mysql_com.h /usr/include/mysql/mysql_version.h \
+ /usr/include/mysql/my_alloc.h /usr/include/mysql/errmsg.h \
+ /usr/include/mysql/mysqld_error.h ../../../include/log.h \
+ ../../../include/zlog.h ../../../include/dbsync.h nodewatcher.h
+
+../../../include/config.h:
+
+/usr/include/stdio.h:
+
+/usr/include/features.h:
+
+/usr/include/sys/cdefs.h:
+
+/usr/include/gnu/stubs.h:
+
+/usr/lib/gcc-lib/x86_64-linux-gnu/3.3.6/include/stddef.h:
+
+/usr/include/bits/types.h:
+
+/usr/include/bits/wordsize.h:
+
+/usr/include/bits/typesizes.h:
+
+/usr/include/libio.h:
+
+/usr/include/_G_config.h:
+
+/usr/include/wchar.h:
+
+/usr/include/bits/wchar.h:
+
+/usr/include/gconv.h:
+
+/usr/lib/gcc-lib/x86_64-linux-gnu/3.3.6/include/stdarg.h:
+
+/usr/include/bits/stdio_lim.h:
+
+/usr/include/bits/sys_errlist.h:
+
+/usr/include/stdlib.h:
+
+/usr/include/sys/types.h:
+
+/usr/include/time.h:
+
+/usr/include/endian.h:
+
+/usr/include/bits/endian.h:
+
+/usr/include/sys/select.h:
+
+/usr/include/bits/select.h:
+
+/usr/include/bits/sigset.h:
+
+/usr/include/bits/time.h:
+
+/usr/include/sys/sysmacros.h:
+
+/usr/include/bits/pthreadtypes.h:
+
+/usr/include/alloca.h:
+
+/usr/include/unistd.h:
+
+/usr/include/bits/posix_opt.h:
+
+/usr/include/bits/confname.h:
+
+/usr/include/getopt.h:
+
+/usr/include/sys/stat.h:
+
+/usr/include/bits/stat.h:
+
+/usr/include/sys/socket.h:
+
+/usr/include/sys/uio.h:
+
+/usr/include/bits/uio.h:
+
+/usr/include/bits/socket.h:
+
+/usr/lib/gcc-lib/x86_64-linux-gnu/3.3.6/include/limits.h:
+
+/usr/lib/gcc-lib/x86_64-linux-gnu/3.3.6/include/syslimits.h:
+
+/usr/include/limits.h:
+
+/usr/include/bits/posix1_lim.h:
+
+/usr/include/bits/local_lim.h:
+
+/usr/include/linux/limits.h:
+
+/usr/include/bits/posix2_lim.h:
+
+/usr/include/bits/sockaddr.h:
+
+/usr/include/asm/socket.h:
+
+/usr/include/asm-x86_64/socket.h:
+
+/usr/include/asm/sockios.h:
+
+/usr/include/asm-x86_64/sockios.h:
+
+/usr/include/netinet/in.h:
+
+/usr/include/stdint.h:
+
+/usr/include/bits/in.h:
+
+/usr/include/bits/byteswap.h:
+
+/usr/include/sys/wait.h:
+
+/usr/include/signal.h:
+
+/usr/include/bits/signum.h:
+
+/usr/include/bits/siginfo.h:
+
+/usr/include/bits/sigaction.h:
+
+/usr/include/bits/sigcontext.h:
+
+/usr/include/bits/sigstack.h:
+
+/usr/include/bits/sigthread.h:
+
+/usr/include/sys/resource.h:
+
+/usr/include/bits/resource.h:
+
+/usr/include/bits/waitflags.h:
+
+/usr/include/bits/waitstatus.h:
+
+/usr/include/string.h:
+
+/usr/include/netdb.h:
+
+/usr/include/rpc/netdb.h:
+
+/usr/include/bits/netdb.h:
+
+/usr/include/pwd.h:
+
+/usr/include/errno.h:
+
+/usr/include/bits/errno.h:
+
+/usr/include/linux/errno.h:
+
+/usr/include/asm/errno.h:
+
+/usr/include/asm-x86_64/errno.h:
+
+../../../include/common.h:
+
+../../../include/sysinc.h:
+
+/usr/include/assert.h:
+
+/usr/include/ctype.h:
+
+/usr/include/strings.h:
+
+/usr/include/sys/time.h:
+
+/usr/include/linux/kernel.h:
+
+/usr/include/arpa/nameser.h:
+
+/usr/include/sys/param.h:
+
+/usr/include/linux/param.h:
+
+/usr/include/asm/param.h:
+
+/usr/include/asm-x86_64/param.h:
+
+/usr/include/sys/bitypes.h:
+
+/usr/include/arpa/nameser_compat.h:
+
+/usr/include/dirent.h:
+
+/usr/include/bits/dirent.h:
+
+/usr/include/fcntl.h:
+
+/usr/include/bits/fcntl.h:
+
+/usr/include/ldap.h:
+
+/usr/include/lber.h:
+
+/usr/include/lber_types.h:
+
+/usr/include/ldap_cdefs.h:
+
+/usr/include/ldap_features.h:
+
+/usr/include/sys/procfs.h:
+
+/usr/include/sys/user.h:
+
+/usr/include/pthread.h:
+
+/usr/include/sched.h:
+
+/usr/include/bits/sched.h:
+
+/usr/include/bits/setjmp.h:
+
+/usr/include/resolv.h:
+
+/usr/include/sys/statvfs.h:
+
+/usr/include/bits/statvfs.h:
+
+/usr/include/sys/swap.h:
+
+/usr/include/sys/syscall.h:
+
+/usr/include/asm/unistd.h:
+
+/usr/include/asm-x86_64/unistd.h:
+
+/usr/include/bits/syscall.h:
+
+/usr/include/sys/sysctl.h:
+
+/usr/include/linux/sysctl.h:
+
+/usr/include/linux/types.h:
+
+/usr/include/sys/sysinfo.h:
+
+/usr/include/sys/vfs.h:
+
+/usr/include/sys/statfs.h:
+
+/usr/include/bits/statfs.h:
+
+/usr/include/net/if.h:
+
+/usr/include/syslog.h:
+
+/usr/include/sys/syslog.h:
+
+/usr/include/sys/ipc.h:
+
+/usr/include/bits/ipctypes.h:
+
+/usr/include/bits/ipc.h:
+
+/usr/include/sys/sem.h:
+
+/usr/include/bits/sem.h:
+
+/usr/include/sys/shm.h:
+
+/usr/include/bits/shm.h:
+
+/usr/include/math.h:
+
+/usr/include/bits/huge_val.h:
+
+/usr/include/bits/mathdef.h:
+
+/usr/include/bits/mathcalls.h:
+
+/usr/include/regex.h:
+
+/usr/include/arpa/inet.h:
+
+/usr/include/sys/mount.h:
+
+/usr/include/sys/ioctl.h:
+
+/usr/include/bits/ioctls.h:
+
+/usr/include/asm/ioctls.h:
+
+/usr/include/asm-x86_64/ioctls.h:
+
+/usr/include/asm/ioctl.h:
+
+/usr/include/asm-x86_64/ioctl.h:
+
+/usr/include/bits/ioctl-types.h:
+
+/usr/include/sys/ttydefaults.h:
+
+/usr/include/sys/timeb.h:
+
+../../../include/zbxtypes.h:
+
+../../../include/cfg.h:
+
+../../../include/db.h:
+
+/usr/include/mysql/mysql.h:
+
+/usr/include/mysql/mysql_com.h:
+
+/usr/include/mysql/mysql_version.h:
+
+/usr/include/mysql/my_alloc.h:
+
+/usr/include/mysql/errmsg.h:
+
+/usr/include/mysql/mysqld_error.h:
+
+../../../include/log.h:
+
+../../../include/zlog.h:
+
+../../../include/dbsync.h:
+
+nodewatcher.h:
diff --git a/src/zabbix_server/nodewatcher/Makefile.am b/src/zabbix_server/nodewatcher/Makefile.am
new file mode 100644
index 00000000..e8af7e8f
--- /dev/null
+++ b/src/zabbix_server/nodewatcher/Makefile.am
@@ -0,0 +1,4 @@
+SUBDIRS=
+INCLUDES=-I@top_srcdir@/include @MYSQL_INCLUDE@ @ORACLE_INCLUDE@
+lib_LIBRARIES=libzbxnodewatcher.a
+libzbxnodewatcher_a_SOURCES=nodewatcher.c
diff --git a/src/zabbix_server/nodewatcher/nodewatcher.c b/src/zabbix_server/nodewatcher/nodewatcher.c
new file mode 100644
index 00000000..d86611cd
--- /dev/null
+++ b/src/zabbix_server/nodewatcher/nodewatcher.c
@@ -0,0 +1,260 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2006 SIA Zabbix
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+
+#include <sys/wait.h>
+
+#include <string.h>
+
+#ifdef HAVE_NETDB_H
+ #include <netdb.h>
+#endif
+
+/* Required for getpwuid */
+#include <pwd.h>
+
+#include <signal.h>
+#include <errno.h>
+
+#include <time.h>
+
+#include "common.h"
+#include "cfg.h"
+#include "db.h"
+#include "log.h"
+#include "zlog.h"
+
+#include "dbsync.h"
+#include "nodewatcher.h"
+
+/******************************************************************************
+ * *
+ * Function: calculate_checksums *
+ * *
+ * Purpose: calculate check sums of configuration data *
+ * *
+ * Parameters: *
+ * *
+ * Return value: SUCCESS - calculated succesfully *
+ * FAIL - an error occured *
+ * *
+ * Author: Alexei Vladishev *
+ * *
+ * Comments: *
+ * *
+ ******************************************************************************/
+static int calculate_checksums()
+{
+
+ char sql[64000];
+ char tmp[MAX_STRING_LEN];
+ char fields[MAX_STRING_LEN];
+
+ int i = 0;
+ int j;
+ DB_RESULT result;
+ DB_RESULT result2;
+ DB_ROW row,row2;
+
+// zabbix_log( LOG_LEVEL_WARNING, "In calculate_checksums");
+ DBexecute("delete from node_cksum where cksumtype=%d", NODE_CKSUM_TYPE_NEW);
+ // insert into node_cksum (select NULL,0,'items','itemid',itemid,0,md5(concat(key_)) as md5 from items);
+
+ /* Select all nodes */
+ zbx_snprintf(sql,sizeof(sql),"select nodeid from nodes");
+ result =DBselect(sql);
+ while((row=DBfetch(result)))
+ {
+ zbx_snprintf(sql,sizeof(sql),"select 'table ','field ',itemid, '012345678901234' from items where 1=0\n");
+
+ for(i=0;tables[i].table!=0;i++)
+ {
+// zabbix_log( LOG_LEVEL_WARNING, "In calculate_checksums2 [%s]", tables[i].table );
+ /* Do not sync some of tables */
+ if( (tables[i].flags & ZBX_SYNC) ==0) continue;
+
+ j=0;
+ fields[0]=0;
+ while(tables[i].fields[j].name != 0)
+ {
+// zabbix_log( LOG_LEVEL_WARNING, "In calculate_checksums2 [%s,%s]", tables[i].table,tables[i].fields[j].name );
+ strncat(fields,tables[i].fields[j].name,sizeof(tmp));
+ strncat(fields,",",sizeof(tmp));
+ j++;
+ }
+ if(fields[0]!=0) fields[strlen(fields)-1] = 0;
+
+ // select table,recid,md5(fields) from table union all ...
+ zbx_snprintf(tmp,sizeof(tmp),"union all select '%s','%s',%s,md5(concat(%s)) from %s where mod(%s,100)=%s\n",
+ tables[i].table, tables[i].recid, tables[i].recid, fields, tables[i].table, tables[i].recid, row[0]);
+ strncat(sql,tmp,sizeof(sql));
+ }
+// zabbix_log( LOG_LEVEL_WARNING, "SQL [%s]", sql);
+
+ result2 =DBselect(sql);
+ while((row2=DBfetch(result2)))
+ {
+ DBexecute("insert into node_cksum (nodeid,tablename,fieldname,recordid,cksumtype,cksum)"\
+ "values (%s,'%s','%s',%s,%d,'%s')",row[0],row2[0],row2[1],row2[2],NODE_CKSUM_TYPE_NEW,row2[3]);
+ }
+ DBfree_result(result2);
+ }
+ DBfree_result(result);
+
+
+ return SUCCEED;
+}
+
+/******************************************************************************
+ * *
+ * Function: update_checksums *
+ * *
+ * Purpose: overwrite old checksums with new ones *
+ * *
+ * Parameters: *
+ * *
+ * Return value: SUCCESS - calculated succesfully *
+ * FAIL - an error occured *
+ * *
+ * Author: Alexei Vladishev *
+ * *
+ * Comments: *
+ * *
+ ******************************************************************************/
+static int update_checksums()
+{
+ /* Begin work */
+ DBexecute("delete from node_cksum where cksumtype=%d", NODE_CKSUM_TYPE_OLD);
+ DBexecute("update node_cksum set cksumtype=%d where cksumtype=%d", NODE_CKSUM_TYPE_OLD, NODE_CKSUM_TYPE_NEW);
+ /* Commit */
+
+ return SUCCEED;
+}
+
+/******************************************************************************
+ * *
+ * Function: compare_checksums *
+ * *
+ * Purpose: compare new checksums with old ones. Write difference to *
+ * table 'node_config' *
+ * *
+ * Parameters: *
+ * *
+ * Return value: SUCCESS - calculated succesfully *
+ * FAIL - an error occured *
+ * *
+ * Author: Alexei Vladishev *
+ * *
+ * Comments: *
+ * *
+ ******************************************************************************/
+static int compare_checksums()
+{
+ DB_RESULT result;
+ DB_ROW row;
+
+ /* Begin work */
+
+ /* Find updated records */
+ result = DBselect("select new.nodeid,new.tablename,new.recordid from node_cksum old, node_cksum new where new.tablename=old.tablename and new.recordid=old.recordid and new.fieldname=old.fieldname and new.nodeid=old.nodeid and new.cksum<>old.cksum and new.cksumtype=%d and old.cksumtype=%d", NODE_CKSUM_TYPE_NEW, NODE_CKSUM_TYPE_OLD);
+ while((row=DBfetch(result)))
+ {
+// zabbix_log( LOG_LEVEL_WARNING, "Adding record to node_configlog");
+ DBexecute("insert into node_configlog (nodeid,tablename,recordid,operation)" \
+ "values (%s,'%s',%s,%d)", row[0],row[1],row[2],NODE_CONFIGLOG_OP_UPDATE);
+ }
+ DBfree_result(result);
+
+ /* Find new records */
+ result = DBselect("select new.nodeid,new.tablename,new.recordid from node_cksum new" \
+ " left join node_cksum old" \
+ " on new.tablename=old.tablename and new.recordid=old.recordid and new.fieldname=old.fieldname and new.nodeid=old.nodeid and new.cksumtype<>old.cksumtype" \
+ " where old.cksumid is null and new.cksumtype=%d", NODE_CKSUM_TYPE_NEW);
+
+ while((row=DBfetch(result)))
+ {
+// zabbix_log( LOG_LEVEL_WARNING, "Adding record to node_configlog");
+ DBexecute("insert into node_configlog (nodeid,tablename,recordid,operation)" \
+ "values (%s,'%s',%s,%d)", row[0],row[1],row[2],NODE_CONFIGLOG_OP_ADD);
+ }
+ DBfree_result(result);
+
+ /* Find deleted records */
+ result = DBselect("select new.nodeid,new.tablename,new.recordid from node_cksum new" \
+ " left join node_cksum old" \
+ " on new.tablename=old.tablename and new.recordid=old.recordid and new.fieldname=old.fieldname and new.nodeid=old.nodeid and new.cksumtype<>old.cksumtype" \
+ " where old.cksumid is null and new.cksumtype=%d", NODE_CKSUM_TYPE_OLD);
+
+ while((row=DBfetch(result)))
+ {
+// zabbix_log( LOG_LEVEL_WARNING, "Adding record to node_configlog");
+ DBexecute("insert into node_configlog (nodeid,tablename,recordid,operation)" \
+ "values (%s,'%s',%s,%d)", row[0],row[1],row[2],NODE_CONFIGLOG_OP_DELETE);
+ }
+ DBfree_result(result);
+
+ /* Commit */
+
+ return SUCCEED;
+}
+
+
+/******************************************************************************
+ * *
+ * Function: main_nodewatcher_loop *
+ * *
+ * Purpose: periodically calculates checks sum of config data *
+ * *
+ * Parameters: *
+ * *
+ * Return value: *
+ * *
+ * Author: Alexei Vladishev *
+ * *
+ * Comments: never returns *
+ * *
+ ******************************************************************************/
+int main_nodewatcher_loop()
+{
+// zabbix_log( LOG_LEVEL_WARNING, "In main_nodeupdater_loop()");
+ for(;;)
+ {
+
+ zbx_setproctitle("connecting to the database");
+
+ DBconnect();
+ calculate_checksums();
+ compare_checksums();
+ update_checksums();
+ DBclose();
+
+ zbx_setproctitle("sender [sleeping for %d seconds]", 30);
+
+ sleep(30);
+ }
+}
diff --git a/src/zabbix_server/nodewatcher/nodewatcher.h b/src/zabbix_server/nodewatcher/nodewatcher.h
new file mode 100644
index 00000000..ea4ca409
--- /dev/null
+++ b/src/zabbix_server/nodewatcher/nodewatcher.h
@@ -0,0 +1,25 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#ifndef ZABBIX_NODEWATCHER_H
+#define ZABBIX_NODEWATCHER_H
+
+int main_nodewatcher_loop();
+
+#endif
diff --git a/src/zabbix_server/pinger/pinger.c b/src/zabbix_server/pinger/pinger.c
index 112a9a1e..e134b9bd 100644
--- a/src/zabbix_server/pinger/pinger.c
+++ b/src/zabbix_server/pinger/pinger.c
@@ -132,11 +132,11 @@ static int process_value(char *key, char *host, AGENT_RESULT *value)
/* IP address? */
if(is_ip(host) == SUCCEED)
{
- result = DBselect("select i.itemid,i.key_,h.host,h.port,i.delay,i.description,i.nextcheck,i.type,i.snmp_community,i.snmp_oid,h.useip,h.ip,i.history,i.lastvalue,i.prevvalue,i.value_type,i.trapper_hosts,i.delta,i.units,i.multiplier,i.formula from items i,hosts h where h.status=%d and h.hostid=i.hostid and h.ip='%s' and i.key_='%s' and i.status=%d and i.type=%d", HOST_STATUS_MONITORED, host, key, ITEM_STATUS_ACTIVE, ITEM_TYPE_SIMPLE);
+ result = DBselect("select i.itemid,i.key_,h.host,h.port,i.delay,i.description,i.nextcheck,i.type,i.snmp_community,i.snmp_oid,h.useip,h.ip,i.history,i.lastvalue,i.prevvalue,i.value_type,i.trapper_hosts,i.delta,i.units,i.multiplier,i.formula from items i,hosts h where h.status=%d and h.hostid=i.hostid and h.ip='%s' and i.key_='%s' and i.status=%d and i.type=%d and" ZBX_COND_NODEID, HOST_STATUS_MONITORED, host, key, ITEM_STATUS_ACTIVE, ITEM_TYPE_SIMPLE, LOCAL_NODE("h.hostid"));
}
else
{
- result = DBselect("select i.itemid,i.key_,h.host,h.port,i.delay,i.description,i.nextcheck,i.type,i.snmp_community,i.snmp_oid,h.useip,h.ip,i.history,i.lastvalue,i.prevvalue,i.value_type,i.trapper_hosts,i.delta,i.units,i.multiplier,i.formula from items i,hosts h where h.status=%d and h.hostid=i.hostid and h.host='%s' and i.key_='%s' and i.status=%d and i.type=%d", HOST_STATUS_MONITORED, host, key, ITEM_STATUS_ACTIVE, ITEM_TYPE_SIMPLE);
+ result = DBselect("select i.itemid,i.key_,h.host,h.port,i.delay,i.description,i.nextcheck,i.type,i.snmp_community,i.snmp_oid,h.useip,h.ip,i.history,i.lastvalue,i.prevvalue,i.value_type,i.trapper_hosts,i.delta,i.units,i.multiplier,i.formula from items i,hosts h where h.status=%d and h.hostid=i.hostid and h.host='%s' and i.key_='%s' and i.status=%d and i.type=%d and" ZBX_COND_NODEID, HOST_STATUS_MONITORED, host, key, ITEM_STATUS_ACTIVE, ITEM_TYPE_SIMPLE, LOCAL_NODE("configid"));
}
row=DBfetch(result);
@@ -233,7 +233,7 @@ static int create_host_file(void)
now=time(NULL);
/* Select hosts monitored by IP */
- result = DBselect("select distinct h.ip from hosts h,items i where i.hostid=h.hostid and (h.status=%d or (h.status=%d and h.available=%d and h.disable_until<=%d)) and (i.key_='%s' or i.key_='%s') and i.type=%d and i.status=%d and h.useip=1", HOST_STATUS_MONITORED, HOST_STATUS_MONITORED, HOST_AVAILABLE_FALSE, now, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY, ITEM_TYPE_SIMPLE, ITEM_STATUS_ACTIVE);
+ result = DBselect("select distinct h.ip from hosts h,items i where i.hostid=h.hostid and (h.status=%d or (h.status=%d and h.available=%d and h.disable_until<=%d)) and (i.key_='%s' or i.key_='%s') and i.type=%d and i.status=%d and h.useip=1 and" ZBX_COND_NODEID, HOST_STATUS_MONITORED, HOST_STATUS_MONITORED, HOST_AVAILABLE_FALSE, now, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY, ITEM_TYPE_SIMPLE, ITEM_STATUS_ACTIVE, LOCAL_NODE("h.hostid"));
while((row=DBfetch(result)))
{
@@ -247,7 +247,7 @@ static int create_host_file(void)
DBfree_result(result);
/* Select hosts monitored by hostname */
- result = DBselect("select distinct h.host from hosts h,items i where i.hostid=h.hostid and (h.status=%d or (h.status=%d and h.available=%d and h.disable_until<=%d)) and (i.key_='%s' or i.key_='%s') and i.type=%d and i.status=%d and h.useip=0", HOST_STATUS_MONITORED, HOST_STATUS_MONITORED, HOST_AVAILABLE_FALSE, now, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY, ITEM_TYPE_SIMPLE, ITEM_STATUS_ACTIVE);
+ result = DBselect("select distinct h.host from hosts h,items i where i.hostid=h.hostid and (h.status=%d or (h.status=%d and h.available=%d and h.disable_until<=%d)) and (i.key_='%s' or i.key_='%s') and i.type=%d and i.status=%d and h.useip=0 and" ZBX_COND_NODEID, HOST_STATUS_MONITORED, HOST_STATUS_MONITORED, HOST_AVAILABLE_FALSE, now, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY, ITEM_TYPE_SIMPLE, ITEM_STATUS_ACTIVE, LOCAL_NODE("h.hostid"));
while((row=DBfetch(result)))
{
diff --git a/src/zabbix_server/pinger/pinger.h b/src/zabbix_server/pinger/pinger.h
index e4f1d08d..e87088fc 100644
--- a/src/zabbix_server/pinger/pinger.h
+++ b/src/zabbix_server/pinger/pinger.h
@@ -29,6 +29,8 @@ extern char *CONFIG_DBPASSWORD;
extern char *CONFIG_DBSOCKET;
extern char *CONFIG_FPING_LOCATION;
+extern int CONFIG_NODEID;
+
extern void signal_handler( int sig );
void main_pinger_loop();
diff --git a/src/zabbix_server/poller/checks_aggregate.c b/src/zabbix_server/poller/checks_aggregate.c
index 09e6261e..14272dd1 100644
--- a/src/zabbix_server/poller/checks_aggregate.c
+++ b/src/zabbix_server/poller/checks_aggregate.c
@@ -110,7 +110,7 @@ static int evaluate_aggregate(AGENT_RESULT *res,char *grpfunc, char *hostgroup,
DBescape_string(hostgroup,hostgroup_esc,MAX_STRING_LEN);
/* Get list of affected item IDs */
strscpy(items,"0");
- result = DBselect("select itemid from items,hosts_groups,hosts,groups where hosts_groups.groupid=groups.groupid and items.hostid=hosts.hostid and hosts_groups.hostid=hosts.hostid and groups.name='%s' and items.key_='%s' and items.status=%d and hosts.status=%d",hostgroup_esc, itemkey_esc, ITEM_STATUS_ACTIVE, HOST_STATUS_MONITORED);
+ result = DBselect("select itemid from items i,hosts_groups hg,hosts h,groups g where hosts_groups.groupid=groups.groupid and items.hostid=hosts.hostid and hosts_groups.hostid=hosts.hostid and groups.name='%s' and items.key_='%s' and items.status=%d and hosts.status=%d and" ZBX_COND_NODEID,hostgroup_esc, itemkey_esc, ITEM_STATUS_ACTIVE, HOST_STATUS_MONITORED, LOCAL_NODE("h.hostid"));
while((row=DBfetch(result)))
{
diff --git a/src/zabbix_server/poller/checks_aggregate.h b/src/zabbix_server/poller/checks_aggregate.h
index a111cc45..f218ec08 100644
--- a/src/zabbix_server/poller/checks_aggregate.h
+++ b/src/zabbix_server/poller/checks_aggregate.h
@@ -29,6 +29,8 @@
#include "db.h"
#include "log.h"
+extern int CONFIG_NODEID;
+
extern int get_value_aggregate(DB_ITEM *item, AGENT_RESULT *result);
#endif
diff --git a/src/zabbix_server/poller/poller.c b/src/zabbix_server/poller/poller.c
index 8e88b1e6..64ea2604 100644
--- a/src/zabbix_server/poller/poller.c
+++ b/src/zabbix_server/poller/poller.c
@@ -121,17 +121,17 @@ static int get_minnextcheck(int now)
2 == UNREACHABLE */
if(my_server_num == 4)
{
- result = DBselect("select count(*),min(i.nextcheck) as nextcheck from items i,hosts h where i.nextcheck<=%d and i.status in (%d) and i.type not in (%d,%d) and h.status=%d and h.disable_until<=%d and h.errors_from!=0 and h.hostid=i.hostid and i.key_ not in ('%s','%s','%s','%s') order by nextcheck", now, ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, HOST_STATUS_MONITORED, now, SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY,SERVER_ZABBIXLOG_KEY);
+ result = DBselect("select count(*),min(nextcheck) as nextcheck from items i,hosts h where i.nextcheck<=%d and i.status in (%d) and i.type not in (%d,%d) and h.status=%d and h.disable_until<=%d and h.errors_from!=0 and h.hostid=i.hostid and i.key_ not in ('%s','%s','%s','%s') and " ZBX_COND_NODEID "order by nextcheck", now, ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, HOST_STATUS_MONITORED, now, SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY,SERVER_ZABBIXLOG_KEY, LOCAL_NODE("h.hostid"));
}
else
{
if(CONFIG_REFRESH_UNSUPPORTED != 0)
{
- result = DBselect("select count(*),min(nextcheck) from items i,hosts h where h.status=%d and h.disable_until<%d and h.errors_from=0 and h.hostid=i.hostid and i.status in (%d,%d) and i.type not in (%d,%d) and mod(i.itemid,%d)=%d and i.key_ not in ('%s','%s','%s','%s')", HOST_STATUS_MONITORED, now, ITEM_STATUS_ACTIVE, ITEM_STATUS_NOTSUPPORTED, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, CONFIG_POLLER_FORKS-5,my_server_num-5,SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY,SERVER_ZABBIXLOG_KEY);
+ result = DBselect("select count(*),min(nextcheck) from items i,hosts h where h.status=%d and h.disable_until<%d and h.errors_from=0 and h.hostid=i.hostid and i.status in (%d,%d) and i.type not in (%d,%d) and mod(i.itemid,%d)=%d and i.key_ not in ('%s','%s','%s','%s') and" ZBX_COND_NODEID, HOST_STATUS_MONITORED, now, ITEM_STATUS_ACTIVE, ITEM_STATUS_NOTSUPPORTED, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, CONFIG_POLLER_FORKS-7,my_server_num-7,SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY,SERVER_ZABBIXLOG_KEY, LOCAL_NODE("h.hostid"));
}
else
{
- result = DBselect("select count(*),min(nextcheck) from items i,hosts h where h.status=%d and h.disable_until<%d and h.errors_from=0 and h.hostid=i.hostid and i.status in (%d,%d) and i.type not in (%d) and mod(i.itemid,%d)=%d and i.key_ not in ('%s','%s','%s','%s')", HOST_STATUS_MONITORED, now, ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, CONFIG_POLLER_FORKS-5,my_server_num-5,SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY,SERVER_ZABBIXLOG_KEY);
+ result = DBselect("select count(*),min(nextcheck) from items i,hosts h where h.status=%d and h.disable_until<%d and h.errors_from=0 and h.hostid=i.hostid and i.status in (%d,%d) and i.type not in (%d) and mod(i.itemid,%d)=%d and i.key_ not in ('%s','%s','%s','%s') and" ZBX_COND_NODEID, HOST_STATUS_MONITORED, now, ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, CONFIG_POLLER_FORKS-7,my_server_num-7,SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY,SERVER_ZABBIXLOG_KEY, LOCAL_NODE("h.hostid"));
}
}
@@ -229,17 +229,17 @@ int get_values(void)
/* Poller for unreachable hosts */
if(my_server_num == 4)
{
- result = DBselect("select %s where i.nextcheck<=%d and i.status in (%d) and i.type not in (%d,%d) and h.status=%d and h.disable_until<=%d and h.errors_from!=0 and h.hostid=i.hostid and i.key_ not in ('%s','%s','%s','%s') order by i.nextcheck", ZBX_SQL_ITEM_SELECT, now, ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, HOST_STATUS_MONITORED, now, SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY,SERVER_ZABBIXLOG_KEY);
+ result = DBselect("select %s where i.nextcheck<=%d and i.status in (%d) and i.type not in (%d,%d) and h.status=%d and h.disable_until<=%d and h.errors_from!=0 and h.hostid=i.hostid and i.key_ not in ('%s','%s','%s','%s') and " ZBX_COND_NODEID " order by i.nextcheck", ZBX_SQL_ITEM_SELECT, now, ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, HOST_STATUS_MONITORED, now, SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY,SERVER_ZABBIXLOG_KEY, LOCAL_NODE("h.hostid"));
}
else
{
if(CONFIG_REFRESH_UNSUPPORTED != 0)
{
- result = DBselect("select %s where i.nextcheck<=%d and i.status in (%d,%d) and i.type not in (%d,%d) and h.status=%d and h.disable_until<=%d and h.errors_from=0 and h.hostid=i.hostid and mod(i.itemid,%d)=%d and i.key_ not in ('%s','%s','%s','%s') order by i.nextcheck", ZBX_SQL_ITEM_SELECT, now, ITEM_STATUS_ACTIVE, ITEM_STATUS_NOTSUPPORTED, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, HOST_STATUS_MONITORED, now, CONFIG_POLLER_FORKS-5,my_server_num-5,SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY,SERVER_ZABBIXLOG_KEY);
+ result = DBselect("select %s where i.nextcheck<=%d and i.status in (%d,%d) and i.type not in (%d,%d) and h.status=%d and h.disable_until<=%d and h.errors_from=0 and h.hostid=i.hostid and mod(i.itemid,%d)=%d and i.key_ not in ('%s','%s','%s','%s') and " ZBX_COND_NODEID " order by i.nextcheck", ZBX_SQL_ITEM_SELECT, now, ITEM_STATUS_ACTIVE, ITEM_STATUS_NOTSUPPORTED, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, HOST_STATUS_MONITORED, now, CONFIG_POLLER_FORKS-7,my_server_num-7,SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY,SERVER_ZABBIXLOG_KEY, LOCAL_NODE("h.hostid"));
}
else
{
- result = DBselect("select %s where i.nextcheck<=%d and i.status in (%d) and i.type not in (%d,%d) and h.status=%d and h.disable_until<=%d and h.errors_from=0 and h.hostid=i.hostid and mod(i.itemid,%d)=%d and i.key_ not in ('%s','%s','%s','%s') order by i.nextcheck", ZBX_SQL_ITEM_SELECT, now, ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, HOST_STATUS_MONITORED, now, CONFIG_POLLER_FORKS-5,my_server_num-5,SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY,SERVER_ZABBIXLOG_KEY);
+ result = DBselect("select %s where i.nextcheck<=%d and i.status in (%d) and i.type not in (%d,%d) and h.status=%d and h.disable_until<=%d and h.errors_from=0 and h.hostid=i.hostid and mod(i.itemid,%d)=%d and i.key_ not in ('%s','%s','%s','%s') and " ZBX_COND_NODEID " order by i.nextcheck", ZBX_SQL_ITEM_SELECT, now, ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, HOST_STATUS_MONITORED, now, CONFIG_POLLER_FORKS-7,my_server_num-7,SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY,SERVER_ZABBIXLOG_KEY, LOCAL_NODE("h.hostid"));
}
}
diff --git a/src/zabbix_server/server.c b/src/zabbix_server/server.c
index eef7d8c1..2757a1b6 100644
--- a/src/zabbix_server/server.c
+++ b/src/zabbix_server/server.c
@@ -60,6 +60,8 @@
#include "poller/checks_snmp.h"
#include "timer/timer.h"
#include "trapper/trapper.h"
+#include "nodewatcher/nodewatcher.h"
+#include "nodesender/nodesender.h"
#define LISTENQ 1024
@@ -123,6 +125,8 @@ char *CONFIG_DBSOCKET = NULL;
int CONFIG_DBPORT = 3306;
int CONFIG_ENABLE_REMOTE_COMMANDS = 0;
+int CONFIG_NODEID = 0;
+
/* From table config */
int CONFIG_REFRESH_UNSUPPORTED = 0;
@@ -146,7 +150,7 @@ void init_config(void)
static struct cfg_line cfg[]=
{
/* PARAMETER ,VAR ,FUNC, TYPE(0i,1s),MANDATORY,MIN,MAX */
- {"StartPollers",&CONFIG_POLLER_FORKS,0,TYPE_INT,PARM_OPT,6,255},
+ {"StartPollers",&CONFIG_POLLER_FORKS,0,TYPE_INT,PARM_OPT,8,255},
{"HousekeepingFrequency",&CONFIG_HOUSEKEEPING_FREQUENCY,0,TYPE_INT,PARM_OPT,1,24},
{"SenderFrequency",&CONFIG_SENDER_FREQUENCY,0,TYPE_INT,PARM_OPT,5,3600},
{"PingerFrequency",&CONFIG_PINGER_FREQUENCY,0,TYPE_INT,PARM_OPT,1,3600},
@@ -171,6 +175,7 @@ void init_config(void)
{"DBPassword",&CONFIG_DBPASSWORD,0,TYPE_STRING,PARM_OPT,0,0},
{"DBSocket",&CONFIG_DBSOCKET,0,TYPE_STRING,PARM_OPT,0,0},
{"DBPort",&CONFIG_DBPORT,0,TYPE_INT,PARM_OPT,1024,65535},
+ {"NodeID",&CONFIG_NODEID,0,TYPE_INT,PARM_OPT,0,65535},
{0}
};
@@ -445,7 +450,8 @@ int MAIN_ZABBIX_ENTRY(void)
DBconnect();
- result = DBselect("select refresh_unsupported from config");
+ zabbix_log( LOG_LEVEL_WARNING, "Cond1 " ZBX_COND_NODEID, LOCAL_NODE("configid"));
+ result = DBselect("select refresh_unsupported from config where " ZBX_COND_NODEID, LOCAL_NODE("configid"));
row = DBfetch(result);
if(row && DBis_null(row[0]) != SUCCEED)
@@ -453,6 +459,7 @@ int MAIN_ZABBIX_ENTRY(void)
CONFIG_REFRESH_UNSUPPORTED = atoi(row[0]);
}
DBfree_result(result);
+ zabbix_log( LOG_LEVEL_WARNING, "OK");
/* Need to set trigger status to UNKNOWN since last run */
/* DBconnect() already made in init_config() */
@@ -542,6 +549,18 @@ int MAIN_ZABBIX_ENTRY(void)
main_poller_loop(server_num);
}
+ else if(server_num == 5)
+ {
+/* Periodic checker of node configuration changes */
+ zabbix_log( LOG_LEVEL_WARNING, "server #%d started [Node watcher]",server_num);
+ main_nodewatcher_loop();
+ }
+ else if(server_num == 6)
+ {
+/* Node communications */
+ zabbix_log( LOG_LEVEL_WARNING, "server #%d started [Node sender]",server_num);
+ main_nodesender_loop();
+ }
else
{
#ifdef HAVE_SNMP
diff --git a/src/zabbix_server/timer/timer.c b/src/zabbix_server/timer/timer.c
index 04c77d6c..72dfb8e4 100644
--- a/src/zabbix_server/timer/timer.c
+++ b/src/zabbix_server/timer/timer.c
@@ -42,6 +42,7 @@
#include "zlog.h"
#include "common.h"
+#include "timer.h"
extern void update_triggers(int itemid);
extern void update_functions(DB_ITEM *item);
@@ -89,7 +90,7 @@ void main_timer_loop()
#endif
*/
- result = DBselect("select distinct %s, functions f where h.hostid=i.hostid and h.status=%d and i.status=%d and f.function in ('nodata','date','dayofweek','time','now') and i.itemid=f.itemid", ZBX_SQL_ITEM_SELECT, HOST_STATUS_MONITORED, ITEM_STATUS_ACTIVE);
+ result = DBselect("select distinct %s, functions f where h.hostid=i.hostid and h.status=%d and i.status=%d and f.function in ('nodata','date','dayofweek','time','now') and i.itemid=f.itemid and" ZBX_COND_NODEID, ZBX_SQL_ITEM_SELECT, HOST_STATUS_MONITORED, ITEM_STATUS_ACTIVE, LOCAL_NODE("h.hostid"));
while((row=DBfetch(result)))
{
diff --git a/src/zabbix_server/timer/timer.h b/src/zabbix_server/timer/timer.h
index bcd95c1d..469eb099 100644
--- a/src/zabbix_server/timer/timer.h
+++ b/src/zabbix_server/timer/timer.h
@@ -20,14 +20,8 @@
#ifndef ZABBIX_TIMER_H
#define ZABBIX_TIMER_H
-/*
-extern void signal_handler(int);
-extern int server_num;
+extern int CONFIG_NODEID;
-extern int CONFIG_TIMEOUT;
-extern int CONFIG_SUCKERD_FORKS;
-*/
-
-int main_timer_loop();
+void main_timer_loop();
#endif
diff --git a/src/zabbix_server/trapper/Makefile.am b/src/zabbix_server/trapper/Makefile.am
index 5053811e..9b3e40aa 100644
--- a/src/zabbix_server/trapper/Makefile.am
+++ b/src/zabbix_server/trapper/Makefile.am
@@ -1,5 +1,5 @@
SUBDIRS=
INCLUDES=-I@top_srcdir@/include @MYSQL_INCLUDE@ @ORACLE_INCLUDE@ @PGSQL_INCLUDE@
lib_LIBRARIES=libzbxtrapper.a
-libzbxtrapper_a_SOURCES=active.c autoregister.h autoregister.c trapper.c
+libzbxtrapper_a_SOURCES=active.c autoregister.h autoregister.c trapper.c nodesync.c
libzbxtrapper_a_LIBADD = ../../libs/zbxdbhigh/libzbxdbhigh.a
diff --git a/src/zabbix_server/trapper/active.c b/src/zabbix_server/trapper/active.c
index 8ac24c7f..1dc83091 100644
--- a/src/zabbix_server/trapper/active.c
+++ b/src/zabbix_server/trapper/active.c
@@ -68,7 +68,7 @@ int send_list_of_active_checks(int sockfd, char *host)
zabbix_log( LOG_LEVEL_DEBUG, "In send_list_of_active_checks()");
- result = DBselect("select i.key_,i.delay,i.lastlogsize from items i,hosts h where i.hostid=h.hostid and h.status=%d and i.status=%d and i.type=%d and h.host='%s'", HOST_STATUS_MONITORED, ITEM_STATUS_ACTIVE, ITEM_TYPE_ZABBIX_ACTIVE, host);
+ result = DBselect("select i.key_,i.delay,i.lastlogsize from items i,hosts h where i.hostid=h.hostid and h.status=%d and i.status=%d and i.type=%d and h.host='%s' and" ZBX_COND_NODEID, HOST_STATUS_MONITORED, ITEM_STATUS_ACTIVE, ITEM_TYPE_ZABBIX_ACTIVE, host, LOCAL_NODE("h.hostid"));
while((row=DBfetch(result)))
{
diff --git a/src/zabbix_server/trapper/active.h b/src/zabbix_server/trapper/active.h
index afeb9b28..b10bf034 100644
--- a/src/zabbix_server/trapper/active.h
+++ b/src/zabbix_server/trapper/active.h
@@ -24,6 +24,8 @@
#include "common.h"
#include "db.h"
+extern int CONFIG_NODEID;
+
int send_list_of_active_checks(int sockfd, char *host);
#endif
diff --git a/src/zabbix_server/trapper/autoregister.c b/src/zabbix_server/trapper/autoregister.c
index 747b4d42..edf9f083 100644
--- a/src/zabbix_server/trapper/autoregister.c
+++ b/src/zabbix_server/trapper/autoregister.c
@@ -56,7 +56,7 @@ int autoregister(char *server)
return FAIL;
}
- result = DBselect("select id,pattern,hostid from autoreg order by priority");
+ result = DBselect("select id,pattern,hostid from autoreg where " ZBX_COND_NODEID " order by priority", LOCAL_NODE("id"));
while((row=DBfetch(result)))
{
diff --git a/src/zabbix_server/trapper/autoregister.h b/src/zabbix_server/trapper/autoregister.h
index ec308c67..4bf93016 100644
--- a/src/zabbix_server/trapper/autoregister.h
+++ b/src/zabbix_server/trapper/autoregister.h
@@ -20,6 +20,8 @@
#ifndef ZABBIX_AUTOREGISTER_H
#define ZABBIX_AUTOREGISTER_H
+extern int CONFIG_NODEID;
+
int autoregister(char *server);
#endif
diff --git a/src/zabbix_server/trapper/nodesync.c b/src/zabbix_server/trapper/nodesync.c
new file mode 100644
index 00000000..0d0346ee
--- /dev/null
+++ b/src/zabbix_server/trapper/nodesync.c
@@ -0,0 +1,258 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <netinet/in.h>
+#include <netdb.h>
+
+#include <string.h>
+
+#include <time.h>
+
+#include <sys/socket.h>
+#include <errno.h>
+
+/* Functions: pow(), round() */
+#include <math.h>
+
+#include "common.h"
+#include "db.h"
+#include "log.h"
+#include "zlog.h"
+
+#include "dbsync.h"
+#include "nodesync.h"
+
+int get_field(char *line, char *result, int num)
+{
+ int delim=0;
+ int ptr=0;
+ int i;
+
+ int ret = FAIL;
+
+ for(i=0;line[i]!=0;i++)
+ {
+ if(line[i]=='|')
+ {
+ delim++;
+ continue;
+ }
+ if(delim==num)
+ {
+ result[ptr++]=line[i];
+ result[ptr]=0;
+ ret = SUCCEED;
+ }
+ }
+ return ret;
+}
+
+/******************************************************************************
+ * *
+ * Function: process_record *
+ * *
+ * Purpose: process record update *
+ * *
+ * Parameters: *
+ * *
+ * Return value: SUCCEED - processed successfully *
+ * FAIL - an error occured *
+ * *
+ * Author: Alexei Vladishev *
+ * *
+ * Comments: *
+ * *
+ ******************************************************************************/
+static int process_record(int nodeid, char *record)
+{
+ char tablename[MAX_STRING_LEN];
+ char fieldname[MAX_STRING_LEN];
+ int recid;
+ int op;
+ int valuetype;
+ char value[MAX_STRING_LEN];
+ char value_esc[MAX_STRING_LEN];
+ char tmp[MAX_STRING_LEN];
+ char sql[MAX_STRING_LEN];
+ int i;
+ char *key=NULL;
+ char fields[MAX_STRING_LEN];
+ char fields_update[MAX_STRING_LEN];
+ char values[MAX_STRING_LEN];
+ DB_RESULT result;
+ DB_ROW row;
+
+// zabbix_log( LOG_LEVEL_WARNING, "In process_record [%s]", record);
+
+ get_field(record,tablename,0);
+ get_field(record,tmp,1);
+ recid=atoi(tmp);
+ get_field(record,tmp,2);
+ op=atoi(tmp);
+
+ for(i=0;tables[i].table!=0;i++)
+ {
+ if(strcmp(tables[i].table, tablename)==0)
+ {
+ key=tables[i].recid;
+ break;
+ }
+ }
+
+ if(key == NULL)
+ {
+ zabbix_log( LOG_LEVEL_WARNING, "Cannot find key field for table [%s]",tablename);
+ return FAIL;
+ }
+ if(op==NODE_CONFIGLOG_OP_DELETE)
+ {
+ zbx_snprintf(tmp,sizeof(tmp),"delete from %s where %s=%d and nodeid=%d", tablename, key, recid, nodeid);
+ zabbix_log( LOG_LEVEL_WARNING, "SQL [%s]", sql);
+ return SUCCEED;
+ }
+
+ i=3;
+ fields[0]=0;
+ fields_update[0]=0;
+ values[0]=0;
+ while(get_field(record,fieldname,i++)==SUCCEED)
+ {
+ tmp[0]=0;
+ get_field(record,tmp,i++);
+ valuetype=atoi(tmp);
+ value[0]=0;
+ get_field(record,value,i++);
+ if(op==NODE_CONFIGLOG_OP_UPDATE || op==NODE_CONFIGLOG_OP_ADD)
+ {
+ if(strcmp(value,"NULL")==0)
+ {
+ zbx_snprintf(tmp,sizeof(tmp),"%s=NULL,", fieldname);
+ strncat(fields_update,tmp,sizeof(fields));
+
+ zbx_snprintf(tmp,sizeof(tmp),"NULL,", value);
+ }
+ else
+ {
+ DBescape_string(value, value_esc,MAX_STRING_LEN);
+
+ zbx_snprintf(tmp,sizeof(tmp),"%s='%s',", fieldname, value_esc);
+ strncat(fields_update,tmp,sizeof(fields));
+
+ zbx_snprintf(tmp,sizeof(tmp),"'%s',", value_esc);
+ }
+
+ strncat(values,tmp,sizeof(values));
+// zabbix_log( LOG_LEVEL_WARNING, "VALUES [%s]", values);
+ zbx_snprintf(tmp,sizeof(tmp),"%s,", fieldname);
+ strncat(fields,tmp,sizeof(fields));
+// zabbix_log( LOG_LEVEL_WARNING, "FIELDS [%s]", fields);
+ }
+ else
+ {
+ zabbix_log( LOG_LEVEL_WARNING, "Unknown record operation [%d]",op);
+ return FAIL;
+ }
+ }
+ if(fields[0]!=0) fields[strlen(fields)-1]=0;
+ if(fields_update[0]!=0) fields_update[strlen(fields_update)-1]=0;
+ if(values[0]!=0) values[strlen(values)-1]=0;
+
+ if(op==NODE_CONFIGLOG_OP_UPDATE)
+ {
+// zbx_snprintf(tmp,sizeof(tmp),"%s='%s',", fieldname, value);
+// strncat(fields,tmp,sizeof(fields));
+ zbx_snprintf(sql,sizeof(sql),"update %s set %s where %s=%d", tablename, fields_update, key, recid);
+ }
+ else if(op==NODE_CONFIGLOG_OP_ADD)
+ {
+ result = DBselect("select 0 from %s where %s=%d", tablename, key, recid);
+ row = DBfetch(result);
+ if(row)
+ {
+ zbx_snprintf(sql,sizeof(sql),"update %s set %s where %s=%d", tablename, fields_update, key, recid);
+ }
+ else
+ {
+ zbx_snprintf(sql,sizeof(sql),"insert into %s (%s) values(%s)", tablename, fields, values);
+ }
+ DBfree_result(result);
+ }
+// zabbix_log( LOG_LEVEL_WARNING, "SQL [%s]", sql);
+ if(FAIL == DBexecute(sql))
+ {
+ zabbix_log( LOG_LEVEL_WARNING, "Failed [%s]", record);
+ }
+
+ return SUCCEED;
+}
+/******************************************************************************
+ * *
+ * Function: node_sync *
+ * *
+ * Purpose: process configuration changes received from a node *
+ * *
+ * Parameters: *
+ * *
+ * Return value: SUCCEED - processed successfully *
+ * FAIL - an error occured *
+ * *
+ * Author: Alexei Vladishev *
+ * *
+ * Comments: *
+ * *
+ ******************************************************************************/
+int node_sync(char *data)
+{
+ char *s;
+ int firstline=1;
+ int nodeid=0;
+ int sender_nodeid=0;
+ char tmp[MAX_STRING_LEN];
+
+// zabbix_log( LOG_LEVEL_WARNING, "In node_sync(len:%d)", strlen(data));
+
+ s=(char *)strtok(data,"\n");
+ while(s!=NULL)
+ {
+ if(firstline == 1)
+ {
+// zabbix_log( LOG_LEVEL_WARNING, "First line [%s]", s);
+ get_field(s,tmp,1);
+ sender_nodeid=atoi(tmp);
+ get_field(s,tmp,2);
+ nodeid=atoi(tmp);
+ firstline=0;
+ zabbix_log( LOG_LEVEL_WARNING, "NODE %d: Received data from node %d for node %d", CONFIG_NODEID, sender_nodeid, nodeid);
+ }
+ else
+ {
+// zabbix_log( LOG_LEVEL_WARNING, "Got line [%s]", s);
+ process_record(nodeid, s);
+ }
+
+ s=(char *)strtok(NULL,"\n");
+ }
+ return SUCCEED;
+}
diff --git a/src/zabbix_server/trapper/nodesync.h b/src/zabbix_server/trapper/nodesync.h
new file mode 100644
index 00000000..ee168c31
--- /dev/null
+++ b/src/zabbix_server/trapper/nodesync.h
@@ -0,0 +1,28 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+
+#ifndef ZABBIX_NODESYNC_H
+#define ZABBIX_NODESYNC_H
+
+extern int CONFIG_NODEID;
+
+int node_sync(char *data);
+
+#endif
diff --git a/src/zabbix_server/trapper/trapper.c b/src/zabbix_server/trapper/trapper.c
index dd695ecf..86517f4e 100644
--- a/src/zabbix_server/trapper/trapper.c
+++ b/src/zabbix_server/trapper/trapper.c
@@ -50,6 +50,7 @@
#include "../expression.h"
#include "autoregister.h"
+#include "nodesync.h"
#include "trapper.h"
#include "daemon.h"
@@ -100,8 +101,23 @@ int process_trap(int sockfd,char *s, int max_len)
/* Process information sent by zabbix_sender */
else
{
+ /* Node data exchange? */
+ if(strncmp(s,"Data",4) == 0)
+ {
+// zabbix_log( LOG_LEVEL_WARNING, "Node data received [len:%d]", strlen(s));
+ if(node_sync(s) == SUCCEED)
+ {
+ zbx_snprintf(result,sizeof(result),"OK\n");
+ if( write(sockfd,result,strlen(result)) == -1)
+ {
+ zabbix_log( LOG_LEVEL_WARNING, "Error sending confirmation to node [%s]",strerror(errno));
+ zabbix_syslog("Trapper: error sending confirmation to node [%s]",strerror(errno));
+ }
+ }
+ return ret;
+ }
/* New XML protocol? */
- if(s[0]=='<')
+ else if(s[0]=='<')
{
zabbix_log( LOG_LEVEL_DEBUG, "XML received [%s]", s);
@@ -167,33 +183,39 @@ int process_trap(int sockfd,char *s, int max_len)
void process_trapper_child(int sockfd)
{
ssize_t nbytes;
- char buffer[MAX_BUF_LEN];
+ char *buffer;
static struct sigaction phan;
char *bufptr;
+#define ZBX_MAX_PACKET_LEN 8*1024*1024
+
zabbix_log( LOG_LEVEL_DEBUG, "In process_trapper_child");
+
+ buffer=malloc(ZBX_MAX_PACKET_LEN);
+
phan.sa_handler = &child_signal_handler;
sigemptyset(&phan.sa_mask);
phan.sa_flags = 0;
sigaction(SIGALRM, &phan, NULL);
- alarm(CONFIG_TIMEOUT);
+// alarm(CONFIG_TIMEOUT);
- zabbix_log( LOG_LEVEL_DEBUG, "Before read(%d)", MAX_BUF_LEN);
+ zabbix_log( LOG_LEVEL_DEBUG, "Before read(%d)", ZBX_MAX_PACKET_LEN);
/* if( (nbytes = read(sockfd, line, MAX_BUF_LEN)) < 0)*/
- memset(buffer,0,sizeof(buffer));
+ memset(buffer,0,ZBX_MAX_PACKET_LEN);
bufptr = buffer;
- while ((nbytes = read(sockfd, bufptr, buffer + sizeof(buffer) - bufptr - 1)) != -1 && nbytes != 0)
+ while ((nbytes = read(sockfd, bufptr, buffer + ZBX_MAX_PACKET_LEN - bufptr - 1)) != -1 && nbytes != 0)
{
- zabbix_log( LOG_LEVEL_DEBUG, "Read %d bytes", nbytes);
- if(nbytes < buffer + sizeof(buffer) - bufptr - 1)
+// zabbix_log( LOG_LEVEL_WARNING, "Read %d bytes", nbytes);
+ if(nbytes < buffer + ZBX_MAX_PACKET_LEN - bufptr - 1)
{
bufptr += nbytes;
break;
}
bufptr += nbytes;
}
+// zabbix_log( LOG_LEVEL_WARNING, "Read total %d bytes", nbytes);
if(nbytes < 0)
{
@@ -206,6 +228,7 @@ void process_trapper_child(int sockfd)
zabbix_log( LOG_LEVEL_WARNING, "read() failed");
}
alarm(0);
+ free(buffer);
return;
}
@@ -215,6 +238,7 @@ void process_trapper_child(int sockfd)
process_trap(sockfd,buffer, sizeof(buffer));
+ free(buffer);
alarm(0);
}
diff --git a/src/zabbix_server/zlog.c b/src/zabbix_server/zlog.c
index 783646a8..6939ce0b 100644
--- a/src/zabbix_server/zlog.c
+++ b/src/zabbix_server/zlog.c
@@ -34,6 +34,8 @@
#include "log.h"
#include "zlog.h"
+extern int CONFIG_NODEID;
+
/******************************************************************************
* *
* Function: zabbix_syslog *
@@ -62,7 +64,7 @@ void zabbix_syslog(const char *fmt, ...)
zabbix_log(LOG_LEVEL_DEBUG, "In zabbix_log()");
- result = DBselect("select %s where h.hostid=i.hostid and i.key_='%s' and i.value_type=%d", ZBX_SQL_ITEM_SELECT, SERVER_ZABBIXLOG_KEY, ITEM_VALUE_TYPE_STR);
+ result = DBselect("select %s where h.hostid=i.hostid and i.key_='%s' and i.value_type=%d and" ZBX_COND_NODEID, ZBX_SQL_ITEM_SELECT, SERVER_ZABBIXLOG_KEY, ITEM_VALUE_TYPE_STR, LOCAL_NODE("h.hostid"));
while((row=DBfetch(result)))
{
diff --git a/upgrades/dbpatches/1.1_1.3/mysql/patch.sql b/upgrades/dbpatches/1.1_1.3/mysql/patch.sql
new file mode 100644
index 00000000..81e19973
--- /dev/null
+++ b/upgrades/dbpatches/1.1_1.3/mysql/patch.sql
@@ -0,0 +1,122 @@
+--
+-- Table structure for table 'nodes'
+--
+
+CREATE TABLE nodes (
+ nodeid int(4) NOT NULL auto_increment,
+ name varchar(64) DEFAULT '' NOT NULL,
+ timezone int(4) DEFAULT '0' NOT NULL,
+ ip varchar(15) DEFAULT '' NOT NULL,
+ port int(4) DEFAULT '0' NOT NULL,
+ slave_history int(4) DEFAULT '0' NOT NULL,
+ slave_trends int(4) DEFAULT '0' NOT NULL,
+ nodetype int(4) DEFAULT '0' NOT NULL,
+ masterid int(4) DEFAULT '0' NOT NULL,
+ PRIMARY KEY (nodeid)
+) type=InnoDB;
+
+--
+-- Table structure for table 'node_cksum'
+--
+
+CREATE TABLE node_cksum (
+ cksumid int(4) NOT NULL auto_increment,
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ tablename varchar(64) DEFAULT '' NOT NULL,
+ fieldname varchar(64) DEFAULT '' NOT NULL,
+ recordid int(4) DEFAULT '0' NOT NULL,
+ cksumtype int(4) DEFAULT '0' NOT NULL,
+ cksum char(32) DEFAULT '' NOT NULL,
+ PRIMARY KEY (cksumid),
+ KEY (nodeid,tablename,fieldname,recordid,cksumtype)
+) type=InnoDB;
+
+--
+-- Table structure for table 'node_configlog'
+--
+
+CREATE TABLE node_configlog (
+ conflogid int(4) NOT NULL auto_increment,
+ nodeid int(4) DEFAULT '0' NOT NULL,
+ tablename varchar(64) DEFAULT '' NOT NULL,
+ recordid int(4) DEFAULT '0' NOT NULL,
+ operation int(4) DEFAULT '0' NOT NULL,
+ sync_master int(4) DEFAULT '0' NOT NULL,
+ sync_slave int(4) DEFAULT '0' NOT NULL,
+ PRIMARY KEY (conflogid),
+ KEY (nodeid,tablename)
+) type=InnoDB;
+
+--- Add configid to table config
+CREATE TABLE config_tmp (
+ configid int(4) NOT NULL auto_increment,
+ alert_history int(4) DEFAULT '0' NOT NULL,
+ alarm_history int(4) DEFAULT '0' NOT NULL,
+ refresh_unsupported int(4) DEFAULT '0' NOT NULL,
+ work_period varchar(100) DEFAULT '1-5,00:00-24:00' NOT NULL,
+ PRIMARY KEY (configid)
+) type=InnoDB;
+
+insert into config_tmp (select null,alert_history,alarm_history,refresh_unsupported,work_period from config);
+drop table config;
+alter table config_tmp rename config;
+
+-- Add hostgroupid to table hosts_groups
+
+CREATE TABLE hosts_groups_tmp (
+ hostgroupid int(4) NOT NULL auto_increment,
+ hostid int(4) DEFAULT '0' NOT NULL,
+ groupid int(4) DEFAULT '0' NOT NULL,
+ PRIMARY KEY (hostgroupid),
+ UNIQUE (hostid,groupid)
+) type=InnoDB;
+
+insert into hosts_groups_tmp (select null,hostid,groupid from hosts_groups);
+drop table hosts_groups;
+alter table hosts_groups_tmp rename hosts_groups;
+
+
+-- Add itemappid to table items_applications
+CREATE TABLE items_applications_tmp (
+ itemappid int(4) NOT NULL auto_increment,
+ applicationid int(4) DEFAULT '0' NOT NULL,
+ itemid int(4) DEFAULT '0' NOT NULL,
+ PRIMARY KEY (itemappid),
+ UNIQUE (applicationid,itemid)
+) type=InnoDB;
+
+insert into items_applications_tmp (select null,applicationid,itemid from items_applications);
+drop table items_applications;
+alter table items_applications_tmp rename items_applications;
+
+-- Add triggerdepid to table trigger_depends
+
+CREATE TABLE trigger_depends_tmp (
+ triggerdepid int(4) NOT NULL auto_increment,
+ triggerid_down int(4) DEFAULT '0' NOT NULL,
+ triggerid_up int(4) DEFAULT '0' NOT NULL,
+ PRIMARY KEY (triggerdepid),
+ UNIQUE (triggerid_down, triggerid_up),
+ KEY (triggerid_up)
+) type=InnoDB;
+
+insert into trigger_depends_tmp (select null,triggerid_down,triggerid_up from trigger_depends);
+drop table trigger_depends;
+alter table trigger_depends_tmp rename trigger_depends;
+
+-- Add id to table users_groups
+
+CREATE TABLE users_groups_tmp (
+ id int(4) NOT NULL auto_increment,
+ usrgrpid int(4) DEFAULT '0' NOT NULL,
+ userid int(4) DEFAULT '0' NOT NULL,
+ PRIMARY KEY (id),
+ UNIQUE (usrgrpid,userid)
+) type=InnoDB;
+
+insert into users_groups_tmp (select null,usrgrpid,userid from users_groups);
+drop table users_groups;
+alter table users_groups_tmp rename users_groups;
+
+-- Ger rid of NULLs
+alter table sysmaps_elements modify label_location int(1) DEFAULT '0' NOT NULL;
diff --git a/upgrades/dbpatches/1.1_1.3/oracle/patch.sql b/upgrades/dbpatches/1.1_1.3/oracle/patch.sql
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/upgrades/dbpatches/1.1_1.3/oracle/patch.sql
diff --git a/upgrades/dbpatches/1.1_1.3/postgresql/patch.sql b/upgrades/dbpatches/1.1_1.3/postgresql/patch.sql
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/upgrades/dbpatches/1.1_1.3/postgresql/patch.sql