summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsasha <sasha@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2008-03-03 11:59:35 +0000
committersasha <sasha@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2008-03-03 11:59:35 +0000
commit14356f30977c7c2c81741f9d640efe05c442f070 (patch)
treee448d23ac96d174a01161dfec9919702a01a16bd
parent9adc9aedaf9d9d1130ac1ae7cbc59d8da84697db (diff)
downloadzabbix-14356f30977c7c2c81741f9d640efe05c442f070.tar.gz
zabbix-14356f30977c7c2c81741f9d640efe05c442f070.tar.xz
zabbix-14356f30977c7c2c81741f9d640efe05c442f070.zip
- [DEV-110] Proxy
git-svn-id: svn://svn.zabbix.com/trunk@5435 97f52cf1-0a1b-0410-bd0e-c28be96e8082
-rw-r--r--misc/conf/zabbix_proxy.conf7
-rw-r--r--src/libs/zbxsysinfo/Makefile.am1
-rw-r--r--src/zabbix_proxy/datasender/datasender.c128
-rw-r--r--src/zabbix_proxy/events.c4
-rw-r--r--src/zabbix_proxy/proxy.c40
-rw-r--r--src/zabbix_proxy/servercomms.c26
-rw-r--r--src/zabbix_proxy/servercomms.h6
7 files changed, 148 insertions, 64 deletions
diff --git a/misc/conf/zabbix_proxy.conf b/misc/conf/zabbix_proxy.conf
index d32ebb2f..1db9d08e 100644
--- a/misc/conf/zabbix_proxy.conf
+++ b/misc/conf/zabbix_proxy.conf
@@ -67,17 +67,14 @@ Hostname=proxy
# Default value is 30 seconds
#SenderFrequency=30
-# Uncomment this line to disable housekeeping procedure
-#DisableHousekeeping=1
-
# Local bufer size in hours. Proxy will keep collected data N hours.
# Default value is 0 hours
#ProxyLocalBuffer=0
# Offline buffer size in hours. It is used when server is not available.
# Older data is removed.
-# Default value is 0 hours
-#ProxyOfflineBuffer=0
+# Default value is 1 hours
+#ProxyOfflineBuffer=1
# Specifies debug level
# 0 - debug is not created
diff --git a/src/libs/zbxsysinfo/Makefile.am b/src/libs/zbxsysinfo/Makefile.am
index db577c33..63ec8190 100644
--- a/src/libs/zbxsysinfo/Makefile.am
+++ b/src/libs/zbxsysinfo/Makefile.am
@@ -48,6 +48,7 @@ libzbxagentsysinfo_a_SOURCES = \
# SERVER version of sysinfo library
libzbxserversysinfo_a_CFLAGS = \
+ -DWITH_COMMON_METRICS \
-DWITH_SIMPLE_METRICS
libzbxserversysinfo_a_SOURCES = \
diff --git a/src/zabbix_proxy/datasender/datasender.c b/src/zabbix_proxy/datasender/datasender.c
index 55c7afdb..e6fbce22 100644
--- a/src/zabbix_proxy/datasender/datasender.c
+++ b/src/zabbix_proxy/datasender/datasender.c
@@ -40,7 +40,12 @@ struct history_table_t {
ZBX_HISTORY_FIELD fields[ZBX_MAX_FIELDS];
};
-ZBX_HISTORY_TABLE ht[]={
+struct last_ids {
+ const char *lastfieldname;
+ zbx_uint64_t lastid;
+};
+
+static ZBX_HISTORY_TABLE ht[]={
{"history_sync", "history_lastid",
{
{"clock", ZBX_PROTO_TAG_CLOCK},
@@ -82,7 +87,7 @@ ZBX_HISTORY_TABLE ht[]={
{NULL}
};
-ZBX_HISTORY_TABLE dht[]={
+static ZBX_HISTORY_TABLE dht[]={
{"proxy_dhistory", "dhistory_lastid",
{
{"clock", ZBX_PROTO_TAG_CLOCK},
@@ -99,11 +104,6 @@ ZBX_HISTORY_TABLE dht[]={
{NULL}
};
-struct last_ids {
- const char *lastfieldname;
- zbx_uint64_t lastid;
-};
-
#define ZBX_SENDER_TABLE_COUNT 6
/******************************************************************************
@@ -214,6 +214,8 @@ static int get_history_data(struct zbx_json *j, const ZBX_HISTORY_TABLE *ht, zbx
zbx_json_close(j);
}
+ DBfree_result(result);
+
return records;
}
@@ -292,12 +294,14 @@ static int get_dhistory_data(struct zbx_json *j, const ZBX_HISTORY_TABLE *ht, zb
zbx_json_close(j);
}
+ DBfree_result(result);
+
return records;
}
/******************************************************************************
* *
- * Function: main_datasender *
+ * Function: history_sender *
* *
* Purpose: *
* *
@@ -310,28 +314,27 @@ static int get_dhistory_data(struct zbx_json *j, const ZBX_HISTORY_TABLE *ht, zb
* Comments: never returns *
* *
******************************************************************************/
-static int main_datasender()
+static int history_sender(struct zbx_json *j)
{
- struct zbx_json j;
int i, r, records = 0;
zbx_sock_t sock;
- char *answer, buf[11]; /* strlen("4294967296") + 1 */
+ char buf[11]; /* strlen("4294967296") + 1 */
zbx_uint64_t lastid;
struct last_ids li[ZBX_SENDER_TABLE_COUNT];
int li_no = 0;
- zabbix_log(LOG_LEVEL_DEBUG, "In main_datasender()");
+ zabbix_log(LOG_LEVEL_DEBUG, "In history_sender()");
- if (FAIL == connect_to_server(&sock, 60)) /* alarm !!! */
+ if (FAIL == connect_to_server(&sock, 600)) /* alarm !!! */
return FAIL;
- 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_clean(j);
+ zbx_json_addstring(j, ZBX_PROTO_TAG_REQUEST, ZBX_PROTO_VALUE_HISTORY_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);
+ zbx_json_addarray(j, ZBX_PROTO_TAG_DATA);
for (i = 0; ht[i].table != NULL; i ++) {
- if (0 == (r = get_history_data(&j, &ht[i], &lastid)))
+ if (0 == (r = get_history_data(j, &ht[i], &lastid)))
continue;
li[li_no].lastfieldname = ht[i].lastfieldname;
@@ -340,11 +343,64 @@ static int main_datasender()
records += r;
}
- zbx_json_close(&j); /* array */
+ zbx_json_close(j);
+
+ zbx_snprintf(buf, sizeof(buf), "%d", (int)time(NULL));
+
+ zbx_json_addstring(j, ZBX_PROTO_TAG_CLOCK, buf, ZBX_JSON_TYPE_INT);
+
+ if (SUCCEED == put_data_to_server(&sock, j)) {
+ DBbegin();
+
+ for (i = 0; i < li_no; i++) {
+ DBexecute("update proxies set %s=" ZBX_FS_UI64,
+ li[i].lastfieldname,
+ li[i].lastid);
+ }
+ DBcommit();
+ }
+
+ disconnect_server(&sock);
+
+ return records;
+}
+
+/******************************************************************************
+ * *
+ * Function: dhistory_sender *
+ * *
+ * Purpose: *
+ * *
+ * Parameters: *
+ * *
+ * Return value: *
+ * *
+ * Author: Aleksander Vladishev *
+ * *
+ * Comments: never returns *
+ * *
+ ******************************************************************************/
+static int dhistory_sender(struct zbx_json *j)
+{
+ int i, r, records = 0;
+ zbx_sock_t sock;
+ char buf[11]; /* strlen("4294967296") + 1 */
+ zbx_uint64_t lastid;
+ struct last_ids li[ZBX_SENDER_TABLE_COUNT];
+ int li_no = 0;
- zbx_json_addarray(&j, ZBX_PROTO_TAG_DISCOVERY_DATA);
+ zabbix_log(LOG_LEVEL_DEBUG, "In dhistory_sender()");
+
+ if (FAIL == connect_to_server(&sock, 600)) /* alarm !!! */
+ return FAIL;
+
+ zbx_json_clean(j);
+ zbx_json_addstring(j, ZBX_PROTO_TAG_REQUEST, ZBX_PROTO_VALUE_DISCOVERY_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 (i = 0; dht[i].table != NULL; i ++) {
- if (0 == (r = get_dhistory_data(&j, &dht[i], &lastid)))
+ if (0 == (r = get_dhistory_data(j, &dht[i], &lastid)))
continue;
li[li_no].lastfieldname = dht[i].lastfieldname;
@@ -353,13 +409,13 @@ static int main_datasender()
records += r;
}
- zbx_json_close(&j); /* array */
+ zbx_json_close(j);
zbx_snprintf(buf, sizeof(buf), "%d", (int)time(NULL));
- zbx_json_addstring(&j, ZBX_PROTO_TAG_CLOCK, buf, ZBX_JSON_TYPE_INT);
+ zbx_json_addstring(j, ZBX_PROTO_TAG_CLOCK, buf, ZBX_JSON_TYPE_INT);
- if (SUCCEED == put_data_to_server(&sock, &j, &answer)) {
+ if (SUCCEED == put_data_to_server(&sock, j)) {
DBbegin();
for (i = 0; i < li_no; i++) {
@@ -367,12 +423,9 @@ static int main_datasender()
li[i].lastfieldname,
li[i].lastid);
}
-
DBcommit();
}
- zbx_json_free(&j);
-
disconnect_server(&sock);
return records;
@@ -399,6 +452,7 @@ int main_datasender_loop()
int now, sleeptime,
records;
double sec;
+ struct zbx_json j;
zabbix_log(LOG_LEVEL_DEBUG, "In main_datasender_loop()");
@@ -407,24 +461,26 @@ int main_datasender_loop()
phan.sa_flags = 0;
sigaction(SIGALRM, &phan, NULL);
+ zbx_setproctitle("data sender [connecting to the database]");
+
+ DBconnect(ZBX_DB_CONNECT_NORMAL);
+
+ zbx_json_init(&j, 16*1024);
+
for (;;) {
now = time(NULL);
sec = zbx_time();
- zbx_setproctitle("data sender [connecting to the database]");
-
- DBconnect(ZBX_DB_CONNECT_NORMAL);
-
zbx_setproctitle("data sender [sending data]");
- records = main_datasender();
+ records = 0;
+ records += history_sender(&j);
+ records += dhistory_sender(&j);
zabbix_log(LOG_LEVEL_DEBUG, "Datasender spent " ZBX_FS_DBL " seconds while processing %3d values.",
zbx_time() - sec,
records);
- DBclose();
-
sleeptime = CONFIG_DATASENDER_FREQUENCY - (time(NULL) - now);
if (sleeptime > 0) {
@@ -435,4 +491,8 @@ int main_datasender_loop()
sleep(sleeptime);
}
}
+
+ zbx_json_free(&j);
+
+ DBclose();
}
diff --git a/src/zabbix_proxy/events.c b/src/zabbix_proxy/events.c
index 20c2c90a..febaa962 100644
--- a/src/zabbix_proxy/events.c
+++ b/src/zabbix_proxy/events.c
@@ -39,7 +39,7 @@
******************************************************************************/
int process_event(DB_EVENT *event)
{
- zabbix_log(LOG_LEVEL_DEBUG,"In [proxy]process_event(eventid:" ZBX_FS_UI64 ",object:%d,objectid:" ZBX_FS_UI64 ")",
+/* zabbix_log(LOG_LEVEL_DEBUG,"In [proxy]process_event(eventid:" ZBX_FS_UI64 ",object:%d,objectid:" ZBX_FS_UI64 ")",
event->eventid,
event->object,
event->objectid);
@@ -57,6 +57,6 @@ int process_event(DB_EVENT *event)
event->value);
zabbix_log(LOG_LEVEL_DEBUG, "End of [proxy]process_event()");
-
+*/
return SUCCEED;
}
diff --git a/src/zabbix_proxy/proxy.c b/src/zabbix_proxy/proxy.c
index 080a8b77..d3d1ba95 100644
--- a/src/zabbix_proxy/proxy.c
+++ b/src/zabbix_proxy/proxy.c
@@ -128,8 +128,8 @@ int CONFIG_TRAPPER_TIMEOUT = TRAPPER_TIMEOUT;
/*int CONFIG_NOTIMEWAIT = 0;*/
int CONFIG_DISABLE_HOUSEKEEPING = 0;
int CONFIG_HOUSEKEEPING_FREQUENCY = 1; /* h */
-int CONFIG_PROXY_LOCAL_BUFFER = 24; /* 24h */
-int CONFIG_PROXY_OFFLINE_BUFFER = 720; /* 720h */
+int CONFIG_PROXY_LOCAL_BUFFER = 0; /* 24h */
+int CONFIG_PROXY_OFFLINE_BUFFER = 1; /* 720h */
int CONFIG_PROXYCONFIG_FREQUENCY = 120;
@@ -157,7 +157,7 @@ int CONFIG_DBPORT = 0;
int CONFIG_ENABLE_REMOTE_COMMANDS = 0;
char *CONFIG_SERVER = NULL;
-int CONFIG_SERVER_PORT = 10050;
+int CONFIG_SERVER_PORT = 10051;
char *CONFIG_HOSTNAME = NULL;
int CONFIG_NODEID = -1;
int CONFIG_MASTER_NODEID = 0;
@@ -192,12 +192,15 @@ ZBX_MUTEX node_sync_access;
******************************************************************************/
void init_config(void)
{
+ AGENT_RESULT result;
+ char **value = NULL;
+
static struct cfg_line cfg[]=
{
/* PARAMETER ,VAR ,FUNC, TYPE(0i,1s),MANDATORY,MIN,MAX */
{"Server",&CONFIG_SERVER,0,TYPE_STRING,PARM_MAND,0,0},
- {"ServerPort",&CONFIG_SERVER_PORT,0,TYPE_INT,PARM_MAND,1024,32768},
- {"Hostname",&CONFIG_HOSTNAME,0,TYPE_STRING,PARM_MAND,0,0},
+ {"ServerPort",&CONFIG_SERVER_PORT,0,TYPE_INT,PARM_OPT,1024,32768},
+ {"Hostname",&CONFIG_HOSTNAME,0,TYPE_STRING,PARM_OPT,0,0},
{"StartDiscoverers",&CONFIG_DISCOVERER_FORKS,0,TYPE_INT,PARM_OPT,0,255},
{"StartHTTPPollers",&CONFIG_HTTPPOLLER_FORKS,0,TYPE_INT,PARM_OPT,0,255},
@@ -206,12 +209,13 @@ void init_config(void)
{"StartPollersUnreachable",&CONFIG_UNREACHABLE_POLLER_FORKS,0,TYPE_INT,PARM_OPT,0,255},
{"StartTrappers",&CONFIG_TRAPPERD_FORKS,0,TYPE_INT,PARM_OPT,0,255},
- {"DisableHousekeeping",&CONFIG_DISABLE_HOUSEKEEPING,0,TYPE_INT,PARM_OPT,0,1},
{"HousekeepingFrequency",&CONFIG_HOUSEKEEPING_FREQUENCY,0,TYPE_INT,PARM_OPT,1,24},
- {"ProxyLocalBuffer",&CONFIG_PROXY_LOCAL_BUFFER,0,TYPE_INT,PARM_OPT,1,720},
+ {"ProxyLocalBuffer",&CONFIG_PROXY_LOCAL_BUFFER,0,TYPE_INT,PARM_OPT,0,720},
{"ProxyOfflineBuffer",&CONFIG_PROXY_OFFLINE_BUFFER,0,TYPE_INT,PARM_OPT,1,720},
- {"SenderFrequency",&CONFIG_SENDER_FREQUENCY,0,TYPE_INT,PARM_OPT,5,3600},
+ {"DataSenderFrequency",&CONFIG_DATASENDER_FREQUENCY,0,TYPE_INT,PARM_OPT,1,3600},
+
+/* {"SenderFrequency",&CONFIG_SENDER_FREQUENCY,0,TYPE_INT,PARM_OPT,5,3600},*/
{"PingerFrequency",&CONFIG_PINGER_FREQUENCY,0,TYPE_INT,PARM_OPT,1,3600},
{"FpingLocation",&CONFIG_FPING_LOCATION,0,TYPE_STRING,PARM_OPT,0,0},
#ifdef HAVE_IPV6
@@ -230,7 +234,7 @@ void init_config(void)
{"PidFile",&APP_PID_FILE,0,TYPE_STRING,PARM_OPT,0,0},
{"LogFile",&CONFIG_LOG_FILE,0,TYPE_STRING,PARM_OPT,0,0},
{"LogFileSize",&CONFIG_LOG_FILE_SIZE,0,TYPE_INT,PARM_OPT,0,1024},
- {"AlertScriptsPath",&CONFIG_ALERT_SCRIPTS_PATH,0,TYPE_STRING,PARM_OPT,0,0},
+/* {"AlertScriptsPath",&CONFIG_ALERT_SCRIPTS_PATH,0,TYPE_STRING,PARM_OPT,0,0},*/
{"ExternalScripts",&CONFIG_EXTERNALSCRIPTS,0,TYPE_STRING,PARM_OPT,0,0},
{"DBHost",&CONFIG_DBHOST,0,TYPE_STRING,PARM_OPT,0,0},
{"DBName",&CONFIG_DBNAME,0,TYPE_STRING,PARM_MAND,0,0},
@@ -243,9 +247,25 @@ void init_config(void)
CONFIG_SERVER_STARTUP_TIME = time(NULL);
-
parse_cfg_file(CONFIG_FILE,cfg);
+ if(CONFIG_HOSTNAME == NULL)
+ {
+ if(SUCCEED == process("system.hostname", 0, &result))
+ {
+ if( NULL != (value = GET_STR_RESULT(&result)) )
+ {
+ CONFIG_HOSTNAME = strdup(*value);
+ }
+ }
+ free_result(&result);
+
+ if(CONFIG_HOSTNAME == NULL)
+ {
+ zabbix_log( LOG_LEVEL_CRIT, "Hostname is not defined");
+ exit(1);
+ }
+ }
if(CONFIG_DBNAME == NULL)
{
zabbix_log( LOG_LEVEL_CRIT, "DBName not in config file");
diff --git a/src/zabbix_proxy/servercomms.c b/src/zabbix_proxy/servercomms.c
index 2adee6fa..e0651bfa 100644
--- a/src/zabbix_proxy/servercomms.c
+++ b/src/zabbix_proxy/servercomms.c
@@ -95,7 +95,7 @@ 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 *request, char **data)
{
int ret = FAIL;
struct zbx_json j;
@@ -113,9 +113,6 @@ int get_data_from_server(zbx_sock_t *sock, /*const char *name, */const char *req
if (FAIL == recv_data_from_server(sock, data))
goto exit;
-/* zabbix_log (LOG_LEVEL_WARNING, "Received %s from server",
- name);*/
-
ret = SUCCEED;
exit:
zbx_json_free(&j);
@@ -139,9 +136,11 @@ exit:
* Comments: *
* *
******************************************************************************/
-int put_data_to_server(zbx_sock_t *sock, /*const char *name, */struct zbx_json *j, char **answer)
+int put_data_to_server(zbx_sock_t *sock, struct zbx_json *j)
{
- int ret = FAIL;
+ struct zbx_json_parse jp;
+ int ret = FAIL;
+ char *answer, value[MAX_STRING_LEN];
zabbix_log(LOG_LEVEL_DEBUG, "In put_data_to_server() [datalen:%zd]",
j->buffer_size);
@@ -149,13 +148,22 @@ int put_data_to_server(zbx_sock_t *sock, /*const char *name, */struct zbx_json *
if (FAIL == send_data_to_server(sock, j->buffer))
goto exit;
- if (FAIL == recv_data_from_server(sock, answer))
+ if (FAIL == recv_data_from_server(sock, &answer))
+ goto exit;
+
+ if (FAIL == zbx_json_open(answer, &jp))
goto exit;
-/* zabbix_log(LOG_LEVEL_WARNING, "Received %s from server",
- name);*/
+ if (FAIL == zbx_json_value_by_name(&jp, ZBX_PROTO_TAG_RESPONSE, value, sizeof(value)))
+ goto exit;
+
+ if (0 != strcmp(value, ZBX_PROTO_VALUE_SUCCESS))
+ goto exit;
ret = SUCCEED;
exit:
+ zabbix_log(LOG_LEVEL_DEBUG, "End of put_data_to_server():%s",
+ ret == SUCCEED ? "SUCCEED" : "FAIL");
+
return ret;
}
diff --git a/src/zabbix_proxy/servercomms.h b/src/zabbix_proxy/servercomms.h
index 04cc72f1..10974fb5 100644
--- a/src/zabbix_proxy/servercomms.h
+++ b/src/zabbix_proxy/servercomms.h
@@ -27,11 +27,9 @@ extern char *CONFIG_HOSTNAME;
#include "comms.h"
int connect_to_server(zbx_sock_t *sock, int timeout);
-/*int send_data_to_server(zbx_sock_t *sock, const char *data);
-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 put_data_to_server(zbx_sock_t *sock, /*const char *name, */struct zbx_json *j, char **answer);
+int get_data_from_server(zbx_sock_t *sock, const char *request, char **data);
+int put_data_to_server(zbx_sock_t *sock, struct zbx_json *j);
#endif