summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralex <alex@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2006-12-01 14:36:26 +0000
committeralex <alex@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2006-12-01 14:36:26 +0000
commit13fc8c698700cf8d53226e623cf36b9dd13a312c (patch)
tree7b0d36e7745d15289a50895ed3ca864d381d4bf1
parent0603b32cc923505d14e2e88a1af0bc01ac533e08 (diff)
downloadzabbix-13fc8c698700cf8d53226e623cf36b9dd13a312c.tar.gz
zabbix-13fc8c698700cf8d53226e623cf36b9dd13a312c.tar.xz
zabbix-13fc8c698700cf8d53226e623cf36b9dd13a312c.zip
Support of node change in ZABBIX server.
git-svn-id: svn://svn.zabbix.com/trunk@3552 97f52cf1-0a1b-0410-bd0e-c28be96e8082
-rw-r--r--configure.in2
-rwxr-xr-xcreate/data/change_nodeid.sh39
-rwxr-xr-xcreate/schema/gen.pl2
-rwxr-xr-xgo4
-rw-r--r--include/common.h1
-rw-r--r--src/zabbix_server/Makefile.am4
-rw-r--r--src/zabbix_server/server.c19
-rw-r--r--src/zabbix_server/trapper/nodesync.c2
-rw-r--r--src/zabbix_server/utils/Makefile.am4
-rw-r--r--src/zabbix_server/utils/nodechange.c90
-rw-r--r--src/zabbix_server/utils/nodechange.h25
11 files changed, 142 insertions, 50 deletions
diff --git a/configure.in b/configure.in
index a49a00ad..c9e7f7dd 100644
--- a/configure.in
+++ b/configure.in
@@ -1034,7 +1034,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/nodewatcher/Makefile src/zabbix_server/utils/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/change_nodeid.sh b/create/data/change_nodeid.sh
deleted file mode 100755
index 17ed77d7..00000000
--- a/create/data/change_nodeid.sh
+++ /dev/null
@@ -1,39 +0,0 @@
-password=""
-user="root"
-dbname="zabbix"
-nodeid=$1
-
-echo "update config set configid=configid+0000100000000000000*$nodeid"|mysql --user="$user" --password="$password" $dbname
-echo "update media_type set mediatypeid=mediatypeid+0000100000000000000*$nodeid"|mysql --user="$user" --password="$password" $dbname
-echo "update users set userid=userid+0000100000000000000*$nodeid"|mysql --user="$user" --password="$password" $dbname
-echo "update usrgrp set usrgrpid=usrgrpid+0000100000000000000*$nodeid"|mysql --user="$user" --password="$password" $dbname
-echo "update rights set rightid=rightid+0000100000000000000*$nodeid"|mysql --user="$user" --password="$password" $dbname
-echo "update rights set groupid=groupid+0000100000000000000*$nodeid"|mysql --user="$user" --password="$password" $dbname
-echo "update hosts set hostid=hostid+0000100000000000000*$nodeid"|mysql --user="$user" --password="$password" $dbname
-echo "update groups set groupid=groupid+0000100000000000000*$nodeid"|mysql --user="$user" --password="$password" $dbname
-echo "update hosts_groups set hostgroupid=hostgroupid+0000100000000000000*$nodeid"|mysql --user="$user" --password="$password" $dbname
-echo "update hosts_groups set hostid=hostid+0000100000000000000*$nodeid"|mysql --user="$user" --password="$password" $dbname
-echo "update hosts_groups set groupid=groupid+0000100000000000000*$nodeid"|mysql --user="$user" --password="$password" $dbname
-echo "update items set itemid=itemid+0000100000000000000*$nodeid"|mysql --user="$user" --password="$password" $dbname
-echo "update items set hostid=hostid+0000100000000000000*$nodeid"|mysql --user="$user" --password="$password" $dbname
-echo "update functions set functionid=functionid+0000100000000000000*$nodeid"|mysql --user="$user" --password="$password" $dbname
-echo "update functions set itemid=itemid+0000100000000000000*$nodeid"|mysql --user="$user" --password="$password" $dbname
-echo "update functions set triggerid=triggerid+0000100000000000000*$nodeid"|mysql --user="$user" --password="$password" $dbname
-echo "update triggers set triggerid=triggerid+0000100000000000000*$nodeid"|mysql --user="$user" --password="$password" $dbname
-echo "update actions set actionid=actionid+0000100000000000000*$nodeid"|mysql --user="$user" --password="$password" $dbname
-echo "update actions set userid=userid+0000100000000000000*$nodeid"|mysql --user="$user" --password="$password" $dbname
-echo "update media set mediaid=mediaid+0000100000000000000*$nodeid"|mysql --user="$user" --password="$password" $dbname
-echo "update media set userid=userid+0000100000000000000*$nodeid"|mysql --user="$user" --password="$password" $dbname
-echo "update media set mediatypeid=mediatypeid+0000100000000000000*$nodeid"|mysql --user="$user" --password="$password" $dbname
-echo "update images set imageid=imageid+0000100000000000000*$nodeid"|mysql --user="$user" --password="$password" $dbname
-
-echo "select concat(triggerid,'_',expression) from triggers"|mysql --user="$user" --password="$password" $dbname|grep -v concat >tmp
-for i in `cat tmp`; do
- expression=`echo $i|cut -f2 -d"_"`
- recid=`echo $i|cut -f1 -d"_"`
- id=`echo $i|cut -f2 -d"{"|cut -f1 -d "}"`
- newid=`echo "$id+0000100000000000000*$nodeid"|bc`
- newexpression=`echo $expression|sed "s/{$id}/{$newid}/g"`
- echo "update triggers set expression='$newexpression' where triggerid=$recid"|mysql --user="$user" $dbname --password="$password"
-done
-rm tmp
diff --git a/create/schema/gen.pl b/create/schema/gen.pl
index 17847ac0..b3c14fca 100755
--- a/create/schema/gen.pl
+++ b/create/schema/gen.pl
@@ -46,7 +46,7 @@ local $output;
%c=( "type" => "code",
"after" => "\t{0}\n};\n",
"t_bigint" => "ZBX_TYPE_UINT",
- "t_id" => "ZBX_TYPE_UINT",
+ "t_id" => "ZBX_TYPE_ID",
"t_integer" => "ZBX_TYPE_INT",
"t_time" => "ZBX_TYPE_INT",
"t_serial" => "ZBX_TYPE_UINT",
diff --git a/go b/go
index 57c78164..df1cb842 100755
--- a/go
+++ b/go
@@ -29,8 +29,8 @@ echo Configuring...
export CFLAGS="-Wall"
#export CFLAGS="-Wall -pedantic"
#./configure --enable-agent --enable-server --with-sqlite3 --with-net-snmp --prefix=`pwd` 2>>WARNINGS >/dev/null
-#./configure --enable-agent --enable-server --with-pgsql --with-net-snmp --prefix=`pwd` 2>>WARNINGS >/dev/null
-./configure --enable-agent --enable-server --with-mysql --with-net-snmp --prefix=`pwd` 2>>WARNINGS >/dev/null
+./configure --enable-agent --enable-server --with-pgsql --with-net-snmp --prefix=`pwd` 2>>WARNINGS >/dev/null
+#./configure --enable-agent --enable-server --with-mysql --with-net-snmp --prefix=`pwd` 2>>WARNINGS >/dev/null
#./configure --enable-agent --enable-server --with-oracle=/home/zabbix/sqlora8 --with-net-snmp --prefix=`pwd` 2>>WARNINGS >/dev/null
echo Cleaning...
make clean 2>>WARNINGS >/dev/null
diff --git a/include/common.h b/include/common.h
index 8bbbe890..79945953 100644
--- a/include/common.h
+++ b/include/common.h
@@ -221,6 +221,7 @@
#define ZBX_TYPE_BLOB 3
#define ZBX_TYPE_TEXT 4
#define ZBX_TYPE_UINT 5
+#define ZBX_TYPE_ID 6
/* Flags for node history exchange */
#define ZBX_TABLE_HISTORY 0
diff --git a/src/zabbix_server/Makefile.am b/src/zabbix_server/Makefile.am
index d29e0433..8307a404 100644
--- a/src/zabbix_server/Makefile.am
+++ b/src/zabbix_server/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = alerter housekeeper pinger poller timer trapper nodewatcher
+SUBDIRS = alerter housekeeper pinger poller timer trapper nodewatcher utils
INCLUDES=-I@top_srcdir@/include @MYSQL_INCLUDE@ @ORACLE_INCLUDE@ @SNMP_INCLUDE@ @PGSQL_INCLUDE@ @SQLITE3_INCLUDE@
bin_PROGRAMS = zabbix_server
@@ -8,7 +8,7 @@ zabbix_server_LDADD = ../libs/zbxsysinfo/libzbxsysinfo.a ../libs/zbxsysinfo/@ARC
../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 nodewatcher/libzbxnodewatcher.a \
-../libs/zbxemail/libzbxemail.a \
+../libs/zbxemail/libzbxemail.a utils/libzbxutils.a \
../libs/zbxsms/libzbxsms.a ../libs/zbxdbhigh/libzbxdbhigh.a ../libs/zbxcommon/libzbxcommon.a \
../libs/zbxcrypto/libzbxcrypto.a @MYSQL_LIBS@ @PGSQL_LIBS@ @ORACLE_LIBS@ @SQLITE3_LIBS@ @LDAP_LIBS@ @SNMP_LIBS@
zabbix_server_LDFLAGS=@MYSQL_LFLAGS@ @PGSQL_LFLAGS@ @ORACLE_LFLAGS@ @SQLITE3_LFLAGS@ @LDAP_LFLAGS@ @SNMP_LFLAGS@
diff --git a/src/zabbix_server/server.c b/src/zabbix_server/server.c
index bdd4844c..38e3e715 100644
--- a/src/zabbix_server/server.c
+++ b/src/zabbix_server/server.c
@@ -73,15 +73,17 @@ char *help_message[] = {
"Options:",
" -c <file> Specify configuration file",
" -h give this help",
+ " -n <nodeid> covert database data to new nodeid",
" -v display version number",
0 /* end of text */
};
#else
char *help_message[] = {
"Options:",
- " -c --config <file> Specify configuration file",
- " -h --help give this help",
- " -v --version display version number",
+ " -c --config <file> Specify configuration file",
+ " -h --help give this help",
+ " -n --new-nodeid <nodeid> covert database data to new nodeid",
+ " -v --version display version number",
0 /* end of text */
};
#endif
@@ -90,6 +92,7 @@ struct option longopts[] =
{
{"config", 1, 0, 'c'},
{"help", 0, 0, 'h'},
+ {"new-nodeid", 0, 0, 'n'},
{"version", 0, 0, 'v'},
{0,0,0,0}
};
@@ -351,6 +354,8 @@ int main(int argc, char **argv)
{
int ch;
+ zbx_uint64_t nodeid;
+
#ifdef HAVE_ZZZ
DB_RESULT result;
DB_ROW row;
@@ -393,7 +398,7 @@ int main(int argc, char **argv)
progname = argv[0];
/* Parse the command-line. */
- while ((ch = getopt_long(argc, argv, "c:hv",longopts,NULL)) != EOF)
+ while ((ch = getopt_long(argc, argv, "cn:hv",longopts,NULL)) != EOF)
switch ((char) ch) {
case 'c':
CONFIG_FILE = optarg;
@@ -402,6 +407,12 @@ int main(int argc, char **argv)
help();
exit(-1);
break;
+ case 'n':
+ printf("[%s]\n", optarg);
+ ZBX_STR2UINT64(nodeid,optarg);
+ change_nodeid(0,nodeid);
+ exit(-1);
+ break;
case 'v':
version();
exit(-1);
diff --git a/src/zabbix_server/trapper/nodesync.c b/src/zabbix_server/trapper/nodesync.c
index 74a164f0..becdd2ac 100644
--- a/src/zabbix_server/trapper/nodesync.c
+++ b/src/zabbix_server/trapper/nodesync.c
@@ -130,7 +130,7 @@ static int process_record(int nodeid, char *record)
}
else
{
- if(valuetype == ZBX_TYPE_INT || valuetype == ZBX_TYPE_UINT)
+ if(valuetype == ZBX_TYPE_INT || valuetype == ZBX_TYPE_UINT || ZBX_TYPE_ID)
{
zbx_snprintf(tmp,sizeof(tmp),"%s=%s,", fieldname, value);
zbx_strlcat(fields_update,tmp,sizeof(fields));
diff --git a/src/zabbix_server/utils/Makefile.am b/src/zabbix_server/utils/Makefile.am
new file mode 100644
index 00000000..c0e8882c
--- /dev/null
+++ b/src/zabbix_server/utils/Makefile.am
@@ -0,0 +1,4 @@
+SUBDIRS=
+INCLUDES=-I@top_srcdir@/include @MYSQL_INCLUDE@ @ORACLE_INCLUDE@ @PGSQL_INCLUDE@
+lib_LIBRARIES=libzbxutils.a
+libzbxutils_a_SOURCES=nodechange.c
diff --git a/src/zabbix_server/utils/nodechange.c b/src/zabbix_server/utils/nodechange.c
new file mode 100644
index 00000000..49c7a5f8
--- /dev/null
+++ b/src/zabbix_server/utils/nodechange.c
@@ -0,0 +1,90 @@
+/*
+** 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 <string.h>
+
+/* Required for getpwuid */
+#include <pwd.h>
+
+#include <time.h>
+
+#include "common.h"
+#include "cfg.h"
+#include "db.h"
+#include "log.h"
+#include "zlog.h"
+
+#include "dbsync.h"
+
+/******************************************************************************
+ * *
+ * Function: change_nodeid *
+ * *
+ * Purpose: convert database data to new node ID *
+ * *
+ * Parameters: old_id - old id, new_id - new node id *
+ * *
+ * Return value: SUCCESS - converted succesfully *
+ * FAIL - an error occured *
+ * *
+ * Author: Alexei Vladishev *
+ * *
+ * Comments: *
+ * *
+ ******************************************************************************/
+int change_nodeid(zbx_uint64_t old_id, zbx_uint64_t new_id)
+{
+ int i,j;
+
+ if(old_id!=0)
+ {
+ printf("Conversion from non-zero node id is not supported.\n");
+ return FAIL;
+ }
+
+ zabbix_set_log_level(LOG_LEVEL_WARNING);
+
+ DBconnect();
+
+ for(i=0;tables[i].table!=0;i++)
+ {
+ printf("Converting table %s...\n", tables[i].table);
+
+ j=0;
+ while(tables[i].fields[j].name != 0)
+ {
+ if(tables[i].fields[j].type == ZBX_TYPE_ID)
+ {
+ DBexecute("update %s set %s=%s+" ZBX_FS_UI64 "\n",
+ tables[i].table, tables[i].fields[j].name, tables[i].fields[j].name,
+ (zbx_uint64_t)__UINT64_C(100000000000000)*(zbx_uint64_t)new_id);
+ }
+ j++;
+ }
+ }
+ DBclose();
+ printf("Done.\n");
+
+ return SUCCEED;
+}
diff --git a/src/zabbix_server/utils/nodechange.h b/src/zabbix_server/utils/nodechange.h
new file mode 100644
index 00000000..ea4ca409
--- /dev/null
+++ b/src/zabbix_server/utils/nodechange.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