summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--configure.in1
-rw-r--r--include/db.h1
-rw-r--r--src/libs/zbxdbhigh/db.c10
-rw-r--r--src/zabbix_proxy/Makefile.am5
-rw-r--r--src/zabbix_proxy/datasender/Makefile.am6
-rw-r--r--src/zabbix_proxy/datasender/datasender.c274
-rw-r--r--src/zabbix_proxy/datasender/datasender.h25
-rw-r--r--src/zabbix_proxy/proxy.c129
-rw-r--r--src/zabbix_proxy/proxyconfig/Makefile.am3
-rw-r--r--src/zabbix_proxy/proxyconfig/proxyconfig.c30
-rw-r--r--src/zabbix_proxy/proxyconfig/proxyconfig.h2
-rw-r--r--src/zabbix_proxy/servercomms.c (renamed from src/zabbix_proxy/proxyconfig/servercomms.c)49
-rw-r--r--src/zabbix_proxy/servercomms.h (renamed from src/zabbix_proxy/proxyconfig/servercomms.h)3
-rw-r--r--src/zabbix_server/pinger/pinger.c4
14 files changed, 454 insertions, 88 deletions
diff --git a/configure.in b/configure.in
index 865f9a9f..e81366b5 100644
--- a/configure.in
+++ b/configure.in
@@ -1075,6 +1075,7 @@ AC_OUTPUT([
src/zabbix_proxy/Makefile
src/zabbix_proxy/housekeeper/Makefile
src/zabbix_proxy/proxyconfig/Makefile
+ src/zabbix_proxy/datasender/Makefile
upgrades/Makefile
])
diff --git a/include/db.h b/include/db.h
index 014930f2..18113af0 100644
--- a/include/db.h
+++ b/include/db.h
@@ -496,6 +496,7 @@ void DBcommit();
void DBrollback();
const ZBX_TABLE *DBget_table(const char *tablename);
+const ZBX_FIELD *DBget_field(const ZBX_TABLE *table, const char *fieldname);
zbx_uint64_t DBget_maxid(char *table, char *field);
int DBget_function_result(char **result,char *functionid);
diff --git a/src/libs/zbxdbhigh/db.c b/src/libs/zbxdbhigh/db.c
index 2b5b70ce..97d3c5f1 100644
--- a/src/libs/zbxdbhigh/db.c
+++ b/src/libs/zbxdbhigh/db.c
@@ -1830,6 +1830,16 @@ const ZBX_TABLE *DBget_table(const char *tablename)
return NULL;
}
+const ZBX_FIELD *DBget_field(const ZBX_TABLE *table, const char *fieldname)
+{
+ int f;
+
+ for (f = 0; table->fields[f].name != 0; f++ )
+ if (0 == strcmp(table->fields[f].name, fieldname))
+ return &table->fields[f];
+ return NULL;
+}
+
zbx_uint64_t DBget_maxid(char *tablename, char *fieldname)
{
DB_RESULT result;
diff --git a/src/zabbix_proxy/Makefile.am b/src/zabbix_proxy/Makefile.am
index 61c95dd3..27dfd878 100644
--- a/src/zabbix_proxy/Makefile.am
+++ b/src/zabbix_proxy/Makefile.am
@@ -9,11 +9,13 @@ SUBDIRS = \
../zabbix_server/pinger \
../zabbix_server/poller \
../zabbix_server/trapper \
- ../zabbix_server/nodewatcher
+ ../zabbix_server/nodewatcher \
+ datasender
sbin_PROGRAMS = zabbix_proxy
zabbix_proxy_SOURCES = \
+ servercomms.c servercomms.h \
events.c events.h \
zlog.c \
proxy.c
@@ -28,6 +30,7 @@ zabbix_proxy_LDADD = \
$(top_srcdir)/src/zabbix_server/poller/libzbxpoller.a \
$(top_srcdir)/src/zabbix_server/trapper/libzbxtrapper.a \
$(top_srcdir)/src/zabbix_server/nodewatcher/libzbxnodewatcher.a \
+ datasender/libzbxdatasender.a \
$(top_srcdir)/src/libs/zbxsysinfo/libzbxserversysinfo.a \
$(top_srcdir)/src/libs/zbxsysinfo/$(ARCH)/libspecsysinfo.a \
$(top_srcdir)/src/libs/zbxsysinfo/common/libcommonsysinfo.a \
diff --git a/src/zabbix_proxy/datasender/Makefile.am b/src/zabbix_proxy/datasender/Makefile.am
new file mode 100644
index 00000000..dec22f18
--- /dev/null
+++ b/src/zabbix_proxy/datasender/Makefile.am
@@ -0,0 +1,6 @@
+## Process this file with automake to produce Makefile.in
+
+noinst_LIBRARIES = libzbxdatasender.a
+
+libzbxdatasender_a_SOURCES = \
+ datasender.c datasender.h
diff --git a/src/zabbix_proxy/datasender/datasender.c b/src/zabbix_proxy/datasender/datasender.c
new file mode 100644
index 00000000..fc5c04fd
--- /dev/null
+++ b/src/zabbix_proxy/datasender/datasender.c
@@ -0,0 +1,274 @@
+/*
+** 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 "common.h"
+#include "comms.h"
+#include "db.h"
+#include "log.h"
+#include "zbxjson.h"
+
+#include "datasender.h"
+#include "../servercomms.h"
+
+#define CONFIG_DATASENDER_FREQUENCY 3
+
+#define ZBX_HISTORY_FIELD struct history_field_t
+#define ZBX_HISTORY_TABLE struct history_table_t
+
+struct history_field_t {
+ const char *field;
+ const char *tag;
+};
+
+struct history_table_t {
+ const char *table;
+ ZBX_HISTORY_FIELD fields[ZBX_MAX_FIELDS];
+};
+
+static const ZBX_HISTORY_TABLE ht[]={
+ {"history",
+ {
+ {"clock", ZBX_PROTO_TAG_CLOCK},
+ {"value", ZBX_PROTO_TAG_VALUE},
+ {NULL}
+ }
+ },
+ {"history_uint",
+ {
+ {"clock", ZBX_PROTO_TAG_CLOCK},
+ {"value", ZBX_PROTO_TAG_VALUE},
+ {NULL}
+ }
+ },
+ {"history_text",
+ {
+ {"clock", ZBX_PROTO_TAG_CLOCK},
+ {"value", ZBX_PROTO_TAG_VALUE},
+ {NULL}
+ }
+ },
+ {"history_str",
+ {
+ {"clock", ZBX_PROTO_TAG_CLOCK},
+ {"value", ZBX_PROTO_TAG_VALUE},
+ {NULL}
+ }
+ },
+ {"history_log",
+ {
+ {"clock", ZBX_PROTO_TAG_CLOCK},
+ {"timestamp", ZBX_PROTO_TAG_TIMESTAMP},
+ {"source", ZBX_PROTO_TAG_SOURCE},
+ {"severity", ZBX_PROTO_TAG_SEVERITY},
+ {"value", ZBX_PROTO_TAG_VALUE},
+ {NULL}
+ }
+ },
+ {NULL}
+};
+
+/******************************************************************************
+ * *
+ * Function: get_history_data *
+ * *
+ * Purpose: *
+ * *
+ * Parameters: *
+ * *
+ * Return value: *
+ * *
+ * Author: Aleksander Vladishev *
+ * *
+ * Comments: never returns *
+ * *
+ ******************************************************************************/
+static int get_history_data(struct zbx_json *j, const ZBX_HISTORY_TABLE *ht, int min_clock)
+{
+ int offset = 0, f, records = 0;
+ char sql[MAX_STRING_LEN];
+ DB_RESULT result;
+ DB_ROW row;
+ const ZBX_FIELD *field;
+ const ZBX_TABLE *table;
+ zbx_json_type_t jt;
+
+ zabbix_log(LOG_LEVEL_DEBUG, "In get_history_data() [table:%s]",
+ ht->table);
+
+ offset += zbx_snprintf(sql + offset, sizeof(sql) - offset, "select h.host,i.key_");
+
+ for (f = 0; ht->fields[f].field != NULL; f ++)
+ offset += zbx_snprintf(sql + offset, sizeof(sql) - offset, ",d.%s",
+ ht->fields[f].field);
+
+ result = DBselect("%s from hosts h,items i,%s d where h.hostid=i.hostid and i.itemid=d.itemid and d.clock<%d",
+ sql,
+ ht->table,
+ min_clock + 4 * CONFIG_DATASENDER_FREQUENCY);
+
+ table = DBget_table(ht->table);
+
+ while (NULL != (row = DBfetch(result))) {
+ zbx_json_addobject(j, NULL);
+
+ zbx_json_addstring(j, ZBX_PROTO_TAG_HOST, row[0], ZBX_JSON_TYPE_STRING);
+ zbx_json_addstring(j, ZBX_PROTO_TAG_KEY, row[1], ZBX_JSON_TYPE_STRING);
+ for (f = 0; ht->fields[f].field != NULL; f ++) {
+ field = DBget_field(table, ht->fields[f].field);
+
+ switch (field->type) {
+ case ZBX_TYPE_ID:
+ case ZBX_TYPE_INT:
+ case ZBX_TYPE_UINT:
+ jt = ZBX_JSON_TYPE_INT;
+ break;
+ case ZBX_TYPE_FLOAT:
+ jt = ZBX_JSON_TYPE_FLOAT;
+ break;
+ default :
+ jt = ZBX_JSON_TYPE_STRING;
+ break;
+ }
+
+ zbx_json_addstring(j, ht->fields[f].tag, row[f + 2], jt);
+ }
+
+ records++;
+
+ zbx_json_close(j);
+ }
+
+ return records;
+}
+
+/******************************************************************************
+ * *
+ * Function: main_datasender *
+ * *
+ * Purpose: *
+ * *
+ * Parameters: *
+ * *
+ * Return value: *
+ * *
+ * Author: Aleksander Vladishev *
+ * *
+ * Comments: never returns *
+ * *
+ ******************************************************************************/
+static int main_datasender()
+{
+ struct zbx_json j;
+ int t, records = 0, clock, min_clock = 0;
+ DB_RESULT result;
+ DB_ROW row;
+ double sec;
+ zbx_sock_t sock;
+ char *answer, buf[11]; /* strlen("4294967296") + 1 */
+
+ zabbix_log(LOG_LEVEL_DEBUG, "In main_datasender()");
+
+ if (FAIL == connect_to_server(&sock))
+ return FAIL;
+
+ sec = zbx_time();
+
+ for (t = 0; ht[t].table != NULL; t ++) {
+ result = DBselect("select min(clock) from %s",
+ ht[t].table);
+
+ if(NULL != (row = DBfetch(result)) && FAIL == DBis_null(row[0])) {
+ clock = atoi(row[0]);
+ if (min_clock == 0 || min_clock > clock)
+ min_clock = clock;
+ }
+ DBfree_result(result);
+ }
+
+ zbx_json_init(&j, 512*1024);
+ zbx_json_addstring(&j, ZBX_PROTO_TAG_REQUEST, ZBX_PROTO_VALUE_SENDER_DATA, ZBX_JSON_TYPE_STRING);
+ zbx_json_addstring(&j, ZBX_PROTO_TAG_PROXY, CONFIG_HOSTNAME, ZBX_JSON_TYPE_STRING);
+ zbx_json_addarray(&j, ZBX_PROTO_TAG_DATA);
+
+ for (t = 0; ht[t].table != NULL; t ++)
+ records += get_history_data(&j, &ht[t], min_clock);
+
+ zbx_snprintf(buf, sizeof(buf), "%d", (int)time(NULL));
+
+ zbx_json_close(&j);
+
+ zbx_json_addstring(&j, ZBX_PROTO_TAG_CLOCK, buf, ZBX_JSON_TYPE_INT);
+
+ if (SUCCEED == put_data_to_server(&sock, &j, &answer))
+ ;
+
+ zabbix_log(LOG_LEVEL_DEBUG, "----- [%d] [%d] [seconds:%f]\n%s", records, j.buffer_size, zbx_time() - sec, j.buffer);
+
+ zbx_json_free(&j);
+
+ disconnect_server(&sock);
+
+ return SUCCEED;
+}
+
+/******************************************************************************
+ * *
+ * Function: main_datasender_loop *
+ * *
+ * Purpose: periodically sends history and events to the server *
+ * *
+ * Parameters: *
+ * *
+ * Return value: *
+ * *
+ * Author: Aleksander Vladishev *
+ * *
+ * Comments: never returns *
+ * *
+ ******************************************************************************/
+int main_datasender_loop()
+{
+ int start, sleeptime;
+
+ zabbix_log(LOG_LEVEL_DEBUG, "In main_datasender_loop()");
+
+ for (;;) {
+ start = time(NULL);
+
+ zbx_setproctitle("data sender [connecting to the database]");
+
+ DBconnect(ZBX_DB_CONNECT_NORMAL);
+
+ zbx_setproctitle("data sender [sending data]");
+
+ main_datasender();
+
+ DBclose();
+
+ sleeptime = CONFIG_DATASENDER_FREQUENCY - (time(NULL) - start);
+
+ if (sleeptime > 0) {
+ zbx_setproctitle("data sender [sleeping for %d seconds]",
+ sleeptime);
+ zabbix_log(LOG_LEVEL_DEBUG, "Sleeping for %d seconds",
+ sleeptime);
+ sleep(sleeptime);
+ }
+ }
+}
diff --git a/src/zabbix_proxy/datasender/datasender.h b/src/zabbix_proxy/datasender/datasender.h
new file mode 100644
index 00000000..89bbcd38
--- /dev/null
+++ b/src/zabbix_proxy/datasender/datasender.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_DATASENDER_H
+#define ZABBIX_DATASENDER_H
+
+int main_datasender_loop();
+
+#endif
diff --git a/src/zabbix_proxy/proxy.c b/src/zabbix_proxy/proxy.c
index bdccca72..4451b1c3 100644
--- a/src/zabbix_proxy/proxy.c
+++ b/src/zabbix_proxy/proxy.c
@@ -48,6 +48,7 @@
#include "../zabbix_server/poller/poller.h"
#include "../zabbix_server/trapper/trapper.h"
#include "proxyconfig/proxyconfig.h"
+#include "datasender/datasender.h"
/*
#define LISTENQ 1024
@@ -110,10 +111,10 @@ static char shortopts[] =
pid_t *threads=NULL;
+int CONFIG_DATASENDER_FORKS = 1;
int CONFIG_DBSYNCER_FORKS = 0;//1;
int CONFIG_DISCOVERER_FORKS = 1;
int CONFIG_HOUSEKEEPER_FORKS = 1;
-/*int CONFIG_NODEWATCHER_FORKS = 1;*/
int CONFIG_PINGER_FORKS = 1;
int CONFIG_POLLER_FORKS = 5;
int CONFIG_HTTPPOLLER_FORKS = 5;
@@ -452,49 +453,54 @@ int MAIN_ZABBIX_ENTRY(void)
exit(FAIL);
}*/
- threads = calloc(1+CONFIG_POLLER_FORKS+CONFIG_TRAPPERD_FORKS+CONFIG_PINGER_FORKS
- +CONFIG_HOUSEKEEPER_FORKS+CONFIG_UNREACHABLE_POLLER_FORKS
- +/*CONFIG_NODEWATCHER_FORKS+*/CONFIG_HTTPPOLLER_FORKS+CONFIG_DISCOVERER_FORKS,
- sizeof(pid_t));
+ threads = calloc(1 + CONFIG_DATASENDER_FORKS + CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS
+ + CONFIG_PINGER_FORKS + CONFIG_HOUSEKEEPER_FORKS + CONFIG_UNREACHABLE_POLLER_FORKS
+ + CONFIG_HTTPPOLLER_FORKS + CONFIG_DISCOVERER_FORKS,
+ sizeof(pid_t));
- if(CONFIG_TRAPPERD_FORKS > 0)
- {
- if( FAIL == zbx_tcp_listen(&listen_sock, CONFIG_LISTEN_IP, (unsigned short)CONFIG_LISTEN_PORT) )
- {
+ if (CONFIG_TRAPPERD_FORKS > 0) {
+ if (FAIL == zbx_tcp_listen(&listen_sock, CONFIG_LISTEN_IP, (unsigned short)CONFIG_LISTEN_PORT)) {
zabbix_log(LOG_LEVEL_CRIT, "Listener failed with error: %s.", zbx_tcp_strerror());
exit(1);
}
}
- for( i=1;
- i<=CONFIG_POLLER_FORKS+CONFIG_TRAPPERD_FORKS+CONFIG_PINGER_FORKS+CONFIG_HOUSEKEEPER_FORKS+CONFIG_UNREACHABLE_POLLER_FORKS+/*CONFIG_NODEWATCHER_FORKS+*/CONFIG_HTTPPOLLER_FORKS+CONFIG_DISCOVERER_FORKS+CONFIG_DBSYNCER_FORKS;
+ for ( i = 1;
+ i <= CONFIG_DATASENDER_FORKS + CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS + CONFIG_PINGER_FORKS
+ + CONFIG_HOUSEKEEPER_FORKS + CONFIG_UNREACHABLE_POLLER_FORKS + CONFIG_HTTPPOLLER_FORKS
+ + CONFIG_DISCOVERER_FORKS + CONFIG_DBSYNCER_FORKS;
i++)
{
- if((pid = zbx_fork()) == 0)
- {
+ if ((pid = zbx_fork()) == 0) {
server_num = i;
break;
- }
- else
- {
- threads[i]=pid;
- }
+ } else
+ threads[i] = pid;
}
-/* zabbix_log( LOG_LEVEL_WARNING, "zabbix_server #%d started",server_num); */
/* Main process */
- if(server_num == 0)
- {
+ if (server_num == 0) {
init_main_process();
+
+ zabbix_log(LOG_LEVEL_WARNING, "server #%d started [Configuration syncer]",
+ server_num);
+
main_proxyconfig_loop(server_num);
-/* zabbix_log( LOG_LEVEL_WARNING, "server #%d started [Watchdog]",
- server_num);
- main_watchdog_loop();*/
- for(;;) zbx_sleep(3600);
+
+ for (;;)
+ zbx_sleep(3600);
}
- if (server_num <= CONFIG_POLLER_FORKS) {
+ if (server_num <= CONFIG_DATASENDER_FORKS)
+ {
+ zabbix_log(LOG_LEVEL_WARNING, "server #%d started [Datasender]",
+ server_num);
+
+ main_datasender_loop();
+ }
+ else if (server_num <= CONFIG_DATASENDER_FORKS + CONFIG_POLLER_FORKS)
+ {
#ifdef HAVE_SNMP
init_snmp("zabbix_server");
#endif /* HAVE_SNMP */
@@ -502,36 +508,34 @@ int MAIN_ZABBIX_ENTRY(void)
zabbix_log(LOG_LEVEL_WARNING, "server #%d started [Poller. SNMP:"SNMP_FEATURE_STATUS"]",
server_num);
- main_poller_loop(ZBX_PROCESS_PROXY, ZBX_POLLER_TYPE_NORMAL, server_num);
+ main_poller_loop(ZBX_PROCESS_PROXY, ZBX_POLLER_TYPE_NORMAL, server_num - CONFIG_DATASENDER_FORKS);
}
- else if (server_num <= CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS)
+ else if (server_num <= CONFIG_DATASENDER_FORKS + CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS)
{
zabbix_log(LOG_LEVEL_WARNING, "server #%d started [Trapper]",
server_num);
-/* Run trapper processes then do housekeeping */
child_trapper_main(ZBX_PROCESS_PROXY, &listen_sock);
-
-/* threads[i] = child_trapper_make(i, listenfd, addrlen); */
-/* child_trapper_make(server_num, listenfd, addrlen); */
}
- else if(server_num <= CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS + CONFIG_PINGER_FORKS)
+ else if(server_num <= CONFIG_DATASENDER_FORKS + CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS
+ + CONFIG_PINGER_FORKS)
{
zabbix_log(LOG_LEVEL_WARNING, "server #%d started [ICMP pinger]",
server_num);
- main_pinger_loop(ZBX_PROCESS_PROXY, server_num - (CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS));
+ main_pinger_loop(ZBX_PROCESS_PROXY, server_num - (CONFIG_DATASENDER_FORKS + CONFIG_POLLER_FORKS
+ + CONFIG_TRAPPERD_FORKS));
}
- else if(server_num <= CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS + CONFIG_PINGER_FORKS
- + CONFIG_HOUSEKEEPER_FORKS)
+ else if(server_num <= CONFIG_DATASENDER_FORKS + CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS
+ + CONFIG_PINGER_FORKS + CONFIG_HOUSEKEEPER_FORKS)
{
- zabbix_log( LOG_LEVEL_WARNING, "server #%d started [Housekeeper]",
+ zabbix_log(LOG_LEVEL_WARNING, "server #%d started [Housekeeper]",
server_num);
main_housekeeper_loop();
}
- else if(server_num <= CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS + CONFIG_PINGER_FORKS + CONFIG_HOUSEKEEPER_FORKS
- + CONFIG_UNREACHABLE_POLLER_FORKS)
+ else if(server_num <= CONFIG_DATASENDER_FORKS + CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS
+ + CONFIG_PINGER_FORKS + CONFIG_HOUSEKEEPER_FORKS + CONFIG_UNREACHABLE_POLLER_FORKS)
{
#ifdef HAVE_SNMP
init_snmp("zabbix_server");
@@ -540,34 +544,39 @@ int MAIN_ZABBIX_ENTRY(void)
zabbix_log(LOG_LEVEL_WARNING, "server #%d started [Poller for unreachable hosts. SNMP:"SNMP_FEATURE_STATUS"]",
server_num);
- main_poller_loop(ZBX_PROCESS_PROXY, ZBX_POLLER_TYPE_UNREACHABLE, server_num - (CONFIG_POLLER_FORKS
- + CONFIG_TRAPPERD_FORKS + CONFIG_PINGER_FORKS + CONFIG_HOUSEKEEPER_FORKS));
+ main_poller_loop(ZBX_PROCESS_PROXY, ZBX_POLLER_TYPE_UNREACHABLE, server_num
+ - (CONFIG_DATASENDER_FORKS + CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS
+ + CONFIG_PINGER_FORKS + CONFIG_HOUSEKEEPER_FORKS));
}
- else if (server_num <= CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS + CONFIG_PINGER_FORKS + CONFIG_HOUSEKEEPER_FORKS
- + CONFIG_UNREACHABLE_POLLER_FORKS + CONFIG_HTTPPOLLER_FORKS)
+ else if (server_num <= CONFIG_DATASENDER_FORKS + CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS
+ + CONFIG_PINGER_FORKS + CONFIG_HOUSEKEEPER_FORKS + CONFIG_UNREACHABLE_POLLER_FORKS
+ + CONFIG_HTTPPOLLER_FORKS)
{
- zabbix_log( LOG_LEVEL_WARNING, "server #%d started [HTTP Poller]",
+ zabbix_log(LOG_LEVEL_WARNING, "server #%d started [HTTP Poller]",
server_num);
- main_httppoller_loop(ZBX_PROCESS_PROXY, server_num - CONFIG_POLLER_FORKS - CONFIG_TRAPPERD_FORKS
- - CONFIG_PINGER_FORKS - CONFIG_HOUSEKEEPER_FORKS - CONFIG_UNREACHABLE_POLLER_FORKS);
+ main_httppoller_loop(ZBX_PROCESS_PROXY, server_num - (CONFIG_DATASENDER_FORKS
+ + CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS + CONFIG_PINGER_FORKS
+ + CONFIG_HOUSEKEEPER_FORKS + CONFIG_UNREACHABLE_POLLER_FORKS));
}
- else if (server_num <= CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS + CONFIG_PINGER_FORKS + CONFIG_HOUSEKEEPER_FORKS
- + CONFIG_UNREACHABLE_POLLER_FORKS + CONFIG_HTTPPOLLER_FORKS + CONFIG_DISCOVERER_FORKS)
+ else if (server_num <= CONFIG_DATASENDER_FORKS + CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS
+ + CONFIG_PINGER_FORKS + CONFIG_HOUSEKEEPER_FORKS + CONFIG_UNREACHABLE_POLLER_FORKS
+ + CONFIG_HTTPPOLLER_FORKS + CONFIG_DISCOVERER_FORKS)
{
#ifdef HAVE_SNMP
init_snmp("zabbix_server");
#endif /* HAVE_SNMP */
- zabbix_log( LOG_LEVEL_WARNING, "server #%d started [Discoverer. SNMP:"SNMP_FEATURE_STATUS"]",
+ zabbix_log(LOG_LEVEL_WARNING, "server #%d started [Discoverer. SNMP:"SNMP_FEATURE_STATUS"]",
server_num);
- main_discoverer_loop(server_num - CONFIG_POLLER_FORKS - CONFIG_TRAPPERD_FORKS - CONFIG_PINGER_FORKS
- - CONFIG_HOUSEKEEPER_FORKS - CONFIG_UNREACHABLE_POLLER_FORKS - CONFIG_HTTPPOLLER_FORKS);
+ main_discoverer_loop(server_num - (CONFIG_DATASENDER_FORKS + CONFIG_POLLER_FORKS
+ + CONFIG_TRAPPERD_FORKS + CONFIG_PINGER_FORKS + CONFIG_HOUSEKEEPER_FORKS
+ + CONFIG_UNREACHABLE_POLLER_FORKS + CONFIG_HTTPPOLLER_FORKS));
}
- else if (server_num <= CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS + CONFIG_PINGER_FORKS + CONFIG_HOUSEKEEPER_FORKS
- + CONFIG_UNREACHABLE_POLLER_FORKS + CONFIG_HTTPPOLLER_FORKS + CONFIG_DISCOVERER_FORKS
- + CONFIG_DBSYNCER_FORKS)
+ else if (server_num <= CONFIG_DATASENDER_FORKS + CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS
+ + CONFIG_PINGER_FORKS + CONFIG_HOUSEKEEPER_FORKS + CONFIG_UNREACHABLE_POLLER_FORKS
+ + CONFIG_HTTPPOLLER_FORKS + CONFIG_DISCOVERER_FORKS + CONFIG_DBSYNCER_FORKS)
{
zabbix_log(LOG_LEVEL_WARNING, "server #%d started [DB Syncer]",
server_num);
@@ -584,12 +593,14 @@ void zbx_on_exit()
int i = 0;
- if(threads != NULL)
- {
- for(i = 1; i <= CONFIG_POLLER_FORKS+CONFIG_TRAPPERD_FORKS+CONFIG_PINGER_FORKS+CONFIG_HOUSEKEEPER_FORKS+CONFIG_UNREACHABLE_POLLER_FORKS+/*CONFIG_NODEWATCHER_FORKS+*/CONFIG_HTTPPOLLER_FORKS+CONFIG_DISCOVERER_FORKS+CONFIG_DBSYNCER_FORKS; i++)
+ if (threads != NULL) {
+ for ( i = 1;
+ i <= CONFIG_DATASENDER_FORKS + CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS + CONFIG_PINGER_FORKS
+ + CONFIG_HOUSEKEEPER_FORKS + CONFIG_UNREACHABLE_POLLER_FORKS + CONFIG_HTTPPOLLER_FORKS
+ + CONFIG_DISCOVERER_FORKS + CONFIG_DBSYNCER_FORKS; i ++)
{
- if(threads[i]) {
- kill(threads[i],SIGTERM);
+ if (threads[i]) {
+ kill(threads[i], SIGTERM);
threads[i] = (ZBX_THREAD_HANDLE)NULL;
}
}
diff --git a/src/zabbix_proxy/proxyconfig/Makefile.am b/src/zabbix_proxy/proxyconfig/Makefile.am
index 81625631..343f3142 100644
--- a/src/zabbix_proxy/proxyconfig/Makefile.am
+++ b/src/zabbix_proxy/proxyconfig/Makefile.am
@@ -3,5 +3,4 @@
noinst_LIBRARIES = libzbxproxyconfig.a
libzbxproxyconfig_a_SOURCES = \
- proxyconfig.c proxyconfig.h \
- servercomms.c servercomms.h
+ proxyconfig.c proxyconfig.h
diff --git a/src/zabbix_proxy/proxyconfig/proxyconfig.c b/src/zabbix_proxy/proxyconfig/proxyconfig.c
index fcd2f12d..c11097dc 100644
--- a/src/zabbix_proxy/proxyconfig/proxyconfig.c
+++ b/src/zabbix_proxy/proxyconfig/proxyconfig.c
@@ -23,7 +23,7 @@
#include "zbxjson.h"
#include "proxyconfig.h"
-#include "servercomms.h"
+#include "../servercomms.h"
/******************************************************************************
* *
@@ -302,7 +302,7 @@ static void process_configuration_sync()
if (FAIL == connect_to_server(&sock))
return;
- if (FAIL == get_data_from_server(&sock, "configuration data", "ZBX_PROXY_CONFIG", &data))
+ if (FAIL == get_data_from_server(&sock, ZBX_PROTO_VALUE_PROXY_CONFIG, &data))
goto exit;
if (FAIL == zbx_json_open(data, &jp))
@@ -331,34 +331,34 @@ exit:
* Comments: never returns *
* *
******************************************************************************/
-void main_proxyconfig_loop(int server_num)
+void main_proxyconfig_loop()
{
- int start, end, sleeptime = 10;
+#define CONFIG_PROXYCONFIG_FREQUENCY 10
+ int start, sleeptime;
- zabbix_log(LOG_LEVEL_DEBUG, "In main_nodewatcher_loop()");
-
- zabbix_log(LOG_LEVEL_WARNING, "server #%d started [Configuration syncer]",
- server_num);
+ zabbix_log(LOG_LEVEL_DEBUG, "In main_proxyconfig_loop()");
for (;;) {
start = time(NULL);
- zbx_setproctitle("Configuration syncer [load configuration]");
+ zbx_setproctitle("configuration syncer [connecting to the database]]");
DBconnect(ZBX_DB_CONNECT_NORMAL);
+ zbx_setproctitle("configuration syncer [load configuration]");
+
process_configuration_sync();
DBclose();
- end = time(NULL);
+ sleeptime = CONFIG_PROXYCONFIG_FREQUENCY - (time(NULL) - start);
- if (end - start < sleeptime) {
- zbx_setproctitle("Configuration syncer [sleeping for %d seconds]",
- sleeptime - (end - start));
+ if (sleeptime > 0) {
+ zbx_setproctitle("configuration syncer [sleeping for %d seconds]",
+ sleeptime);
zabbix_log (LOG_LEVEL_DEBUG, "Sleeping %d seconds",
- sleeptime - (end - start));
- sleep(sleeptime - (end - start));
+ sleeptime);
+ sleep(sleeptime);
}
}
}
diff --git a/src/zabbix_proxy/proxyconfig/proxyconfig.h b/src/zabbix_proxy/proxyconfig/proxyconfig.h
index 77cb2a29..15ab3fd8 100644
--- a/src/zabbix_proxy/proxyconfig/proxyconfig.h
+++ b/src/zabbix_proxy/proxyconfig/proxyconfig.h
@@ -20,6 +20,6 @@
#ifndef ZABBIX_PROXYCONFIG_H
#define ZABBIX_PROXYCONFIG_H
-void main_proxyconfig_loop(int server_num);
+void main_proxyconfig_loop();
#endif
diff --git a/src/zabbix_proxy/proxyconfig/servercomms.c b/src/zabbix_proxy/servercomms.c
index f33bd999..d43a4a53 100644
--- a/src/zabbix_proxy/proxyconfig/servercomms.c
+++ b/src/zabbix_proxy/servercomms.c
@@ -80,7 +80,7 @@ void disconnect_server(zbx_sock_t *sock)
/******************************************************************************
* *
- * Function: get_server_data *
+ * Function: get_data_from_server *
* *
* Purpose: get configuration and othed data from server *
* *
@@ -94,14 +94,13 @@ void disconnect_server(zbx_sock_t *sock)
* Comments: *
* *
******************************************************************************/
-int get_data_from_server(zbx_sock_t *sock, const char *name, const char *request, char **data)
+int get_data_from_server(zbx_sock_t *sock, /*const char *name, */const char *request, char **data)
{
int ret = FAIL;
struct zbx_json j;
- zabbix_log (LOG_LEVEL_DEBUG, "In get_server_data() [name:%s] [request:%s]",
- name,
- request);
+ zabbix_log(LOG_LEVEL_DEBUG, "In get_data_from_server() [request:%s]",
+ request);
zbx_json_init(&j, 128);
zbx_json_addstring(&j, "request", request, ZBX_JSON_TYPE_STRING);
@@ -113,8 +112,8 @@ int get_data_from_server(zbx_sock_t *sock, const char *name, const char *request
if (FAIL == recv_data_from_server(sock, data))
goto exit;
- zabbix_log (LOG_LEVEL_WARNING, "Received %s from server",
- name);
+/* zabbix_log (LOG_LEVEL_WARNING, "Received %s from server",
+ name);*/
ret = SUCCEED;
exit:
@@ -123,3 +122,39 @@ exit:
return ret;
}
+/******************************************************************************
+ * *
+ * Function: put_data_to_server *
+ * *
+ * Purpose: send data from server *
+ * *
+ * Parameters: *
+ * *
+ * Return value: SUCCESS - processed succesfully *
+ * FAIL - an error occured *
+ * *
+ * Author: Alksander Vladishev *
+ * *
+ * Comments: *
+ * *
+ ******************************************************************************/
+int put_data_to_server(zbx_sock_t *sock, /*const char *name, */struct zbx_json *j, char **answer)
+{
+ int ret = FAIL;
+
+ zabbix_log(LOG_LEVEL_DEBUG, "In put_data_to_server() [datalen:%zd]",
+ j->buffer_size);
+
+ if (FAIL == send_data_to_server(sock, j->buffer))
+ goto exit;
+
+ if (FAIL == recv_data_from_server(sock, answer))
+ goto exit;
+
+/* zabbix_log(LOG_LEVEL_WARNING, "Received %s from server",
+ name);*/
+
+ ret = SUCCEED;
+exit:
+ return ret;
+}
diff --git a/src/zabbix_proxy/proxyconfig/servercomms.h b/src/zabbix_proxy/servercomms.h
index 3a9b213a..bc6c634f 100644
--- a/src/zabbix_proxy/proxyconfig/servercomms.h
+++ b/src/zabbix_proxy/servercomms.h
@@ -31,6 +31,7 @@ int connect_to_server(zbx_sock_t *sock);
int recv_data_from_server(zbx_sock_t *sock, char **data);*/
void disconnect_server(zbx_sock_t *sock);
-int get_data_from_server(zbx_sock_t *sock, const char *name, const char *request, char **data);
+int get_data_from_server(zbx_sock_t *sock, /*const char *name, */const char *request, char **data);
+int put_data_to_server(zbx_sock_t *sock, /*const char *name, */struct zbx_json *j, char **answer);
#endif
diff --git a/src/zabbix_server/pinger/pinger.c b/src/zabbix_server/pinger/pinger.c
index c8585209..06960d43 100644
--- a/src/zabbix_server/pinger/pinger.c
+++ b/src/zabbix_server/pinger/pinger.c
@@ -353,13 +353,13 @@ void main_pinger_loop(zbx_process_t p, int num)
for(;;) {
start = time(NULL);
- zbx_setproctitle("connecting to the database");
+ zbx_setproctitle("pinger [connecting to the database]");
DBconnect(ZBX_DB_CONNECT_NORMAL);
hosts_count = 0;
if (SUCCEED == get_pinger_hosts(&hosts, &hosts_allocated, &hosts_count)) {
- zbx_setproctitle("pinging hosts");
+ zbx_setproctitle("pinger [pinging hosts]");
do_ping(hosts, hosts_count);
}