summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorsasha <sasha@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2008-03-11 13:34:15 +0000
committersasha <sasha@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2008-03-11 13:34:15 +0000
commit4172bff7bbc945592c4554623fd959c867eab47d (patch)
tree6f2fd8676712e2e6ebe27a4a8c04501964c07ba1 /src
parent28097f9720dd4fe6fdedc08432b7f320ec8015b7 (diff)
downloadzabbix-4172bff7bbc945592c4554623fd959c867eab47d.tar.gz
zabbix-4172bff7bbc945592c4554623fd959c867eab47d.tar.xz
zabbix-4172bff7bbc945592c4554623fd959c867eab47d.zip
- [DEV-109] Server
git-svn-id: svn://svn.zabbix.com/trunk@5473 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src')
-rw-r--r--src/zabbix_server/discoverer/discoverer.c4
-rw-r--r--src/zabbix_server/nodewatcher/nodesender.c6
-rw-r--r--src/zabbix_server/operations.c12
-rw-r--r--src/zabbix_server/pinger/pinger.c6
-rw-r--r--src/zabbix_server/poller/poller.c16
-rw-r--r--src/zabbix_server/trapper/active.c8
-rw-r--r--src/zabbix_server/trapper/nodehistory.c10
-rw-r--r--src/zabbix_server/trapper/proxyconfig.c144
-rw-r--r--src/zabbix_server/trapper/proxyconfig.h2
-rw-r--r--src/zabbix_server/trapper/proxydiscovery.c33
-rw-r--r--src/zabbix_server/trapper/trapper.c77
11 files changed, 187 insertions, 131 deletions
diff --git a/src/zabbix_server/discoverer/discoverer.c b/src/zabbix_server/discoverer/discoverer.c
index 7a839958..cfcc8b8d 100644
--- a/src/zabbix_server/discoverer/discoverer.c
+++ b/src/zabbix_server/discoverer/discoverer.c
@@ -887,7 +887,7 @@ static void process_discovery(int now)
DB_DRULE rule;
result = DBselect("select druleid,iprange,delay,nextcheck,name,status from drules"
- " where proxyid=0 and status=%d and (nextcheck<=%d or nextcheck>%d+delay)"
+ " where proxy_hostid=0 and status=%d and (nextcheck<=%d or nextcheck>%d+delay)"
" and " ZBX_SQL_MOD(druleid,%d) "=%d" DB_NODE,
DRULE_STATUS_MONITORED,
now,
@@ -921,7 +921,7 @@ static int get_minnextcheck(int now)
DB_ROW row;
int res = FAIL;
- result = DBselect("select count(*),min(nextcheck) from drules where proxyid=0 and status=%d"
+ result = DBselect("select count(*),min(nextcheck) from drules where proxy_hostid=0 and status=%d"
" and " ZBX_SQL_MOD(druleid,%d) "=%d" DB_NODE,
DRULE_STATUS_MONITORED,
CONFIG_DISCOVERER_FORKS,
diff --git a/src/zabbix_server/nodewatcher/nodesender.c b/src/zabbix_server/nodewatcher/nodesender.c
index d7cfc671..8f7b7cfa 100644
--- a/src/zabbix_server/nodewatcher/nodesender.c
+++ b/src/zabbix_server/nodewatcher/nodesender.c
@@ -245,9 +245,10 @@ char *get_config_data(int nodeid, int dest_nodetype)
}
if (DBis_null(row[4]) == FAIL)
- strcpy(sync, row[4]);
+ zbx_strlcpy(sync, row[4], sizeof(sync));
else
memset(sync, ' ', sizeof(sync));
+
s = sync;
/* Special (simpler) processing for operation DELETE */
@@ -468,9 +469,10 @@ int update_checksums(int nodeid, int synked_nodetype, int synked, const char *ta
}
if (DBis_null(row[4]) == FAIL)
- strcpy(sync, row[4]);
+ zbx_strlcpy(sync, row[4], sizeof(sync));
else
memset(sync, ' ', sizeof(sync));
+
s = sync;
ck = cksum;
*ck = '\0';
diff --git a/src/zabbix_server/operations.c b/src/zabbix_server/operations.c
index e62fb5fb..173a337b 100644
--- a/src/zabbix_server/operations.c
+++ b/src/zabbix_server/operations.c
@@ -493,20 +493,20 @@ static zbx_uint64_t add_discovered_host(zbx_uint64_t dhostid)
DB_RESULT result2;
DB_ROW row;
DB_ROW row2;
- zbx_uint64_t hostid = 0, proxyid;
+ zbx_uint64_t hostid = 0, proxy_hostid;
char *ip;
char host[MAX_STRING_LEN], host_esc[MAX_STRING_LEN];
zabbix_log(LOG_LEVEL_DEBUG, "In add_discovered_host(dhostid:" ZBX_FS_UI64 ")",
dhostid);
- result = DBselect("select dr.proxyid,dh.ip from dhosts dh, drules dr"
+ result = DBselect("select dr.proxy_hostid,dh.ip from dhosts dh, drules dr"
" where dr.druleid=dh.druleid and dh.dhostid=" ZBX_FS_UI64,
dhostid);
if (NULL != (row = DBfetch(result)) && DBis_null(row[1]) != SUCCEED) {
- proxyid = zbx_atoui64(row[0]);
- ip = row[1];
+ proxy_hostid = zbx_atoui64(row[0]);
+ ip = row[1];
alarm(CONFIG_TIMEOUT);
zbx_gethost_by_ip(ip, host, sizeof(host));
@@ -520,10 +520,10 @@ static zbx_uint64_t add_discovered_host(zbx_uint64_t dhostid)
if (NULL == (row2 = DBfetch(result2)) || DBis_null(row2[0]) == SUCCEED) {
hostid = DBget_maxid("hosts","hostid");
- DBexecute("insert into hosts (hostid,proxyid,host,useip,ip,dns)"
+ DBexecute("insert into hosts (hostid,proxy_hostid,host,useip,ip,dns)"
" values (" ZBX_FS_UI64 "," ZBX_FS_UI64 ",'%s',1,'%s','%s')",
hostid,
- proxyid,
+ proxy_hostid,
(host[0] != '\0' ? host_esc : ip), /* Use host name if exists, IP otherwise */
ip,
host_esc);
diff --git a/src/zabbix_server/pinger/pinger.c b/src/zabbix_server/pinger/pinger.c
index b83aa16a..797c649e 100644
--- a/src/zabbix_server/pinger/pinger.c
+++ b/src/zabbix_server/pinger/pinger.c
@@ -70,7 +70,7 @@ static int process_value(char *key, ZBX_FPING_HOST *host, AGENT_RESULT *value, t
host->useip ? host->ip : host->dns);
result = DBselect("select %s where " ZBX_SQL_MOD(h.hostid,%d) "=%d and h.status=%d and h.hostid=i.hostid"
- " and h.proxyid=0 and h.useip=%d and h.%s='%s' and i.key_='%s' and i.status=%d"
+ " and h.proxy_hostid=0 and h.useip=%d and h.%s='%s' and i.key_='%s' and i.status=%d"
" and i.type=%d" DB_NODE,
ZBX_SQL_ITEM_SELECT,
CONFIG_PINGER_FORKS,
@@ -130,7 +130,7 @@ static int get_pinger_hosts(ZBX_FPING_HOST **hosts, int *hosts_allocated, int *h
/* Select hosts monitored by IP */
result = DBselect("select distinct h.ip from hosts h,items i where " ZBX_SQL_MOD(h.hostid,%d) "=%d"
- " and i.hostid=h.hostid and h.proxyid=0 and h.status=%d and i.key_ in ('%s','%s')"
+ " and i.hostid=h.hostid and h.proxy_hostid=0 and h.status=%d and i.key_ in ('%s','%s')"
" and i.type=%d and i.status=%d and h.useip=1" DB_NODE,
CONFIG_PINGER_FORKS,
pinger_num - 1,
@@ -161,7 +161,7 @@ static int get_pinger_hosts(ZBX_FPING_HOST **hosts, int *hosts_allocated, int *h
/* Select hosts monitored by hostname */
result = DBselect("select distinct h.dns from hosts h,items i where " ZBX_SQL_MOD(h.hostid,%d) "=%d"
- " and i.hostid=h.hostid and h.proxyid=0 and h.status=%d and i.key_ in ('%s','%s')"
+ " and i.hostid=h.hostid and h.proxy_hostid=0 and h.status=%d and i.key_ in ('%s','%s')"
" and i.type=%d and i.status=%d and h.useip=0" DB_NODE,
CONFIG_PINGER_FORKS,
pinger_num - 1,
diff --git a/src/zabbix_server/poller/poller.c b/src/zabbix_server/poller/poller.c
index 114d166d..4d187412 100644
--- a/src/zabbix_server/poller/poller.c
+++ b/src/zabbix_server/poller/poller.c
@@ -116,7 +116,7 @@ static int get_minnextcheck(int now)
result = DBselect("select count(*),min(nextcheck) as nextcheck from items i,hosts h"
" where " ZBX_SQL_MOD(h.hostid,%d) "=%d and i.nextcheck<=%d and i.status in (%d)"
" and i.type not in (%d,%d,%d) and h.status=%d and h.disable_until<=%d"
- " and h.errors_from!=0 and h.hostid=i.hostid and h.proxyid=0"
+ " and h.errors_from!=0 and h.hostid=i.hostid and h.proxy_hostid=0"
" and i.key_ not in ('%s','%s','%s','%s')" DB_NODE " order by nextcheck",
CONFIG_UNREACHABLE_POLLER_FORKS,
poller_num-1,
@@ -134,7 +134,7 @@ static int get_minnextcheck(int now)
{
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 h.proxyid=0 and i.status in (%d,%d) and i.type not in (%d,%d,%d)"
+ " and h.hostid=i.hostid and h.proxy_hostid=0 and i.status in (%d,%d) and i.type not in (%d,%d,%d)"
" and " ZBX_SQL_MOD(i.itemid,%d) "=%d and i.key_ not in ('%s','%s','%s','%s')" DB_NODE,
HOST_STATUS_MONITORED,
now,
@@ -149,7 +149,7 @@ static int get_minnextcheck(int now)
{
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 h.proxyid=0 and i.status in (%d) and i.type not in (%d,%d,%d)"
+ " and h.hostid=i.hostid and h.proxy_hostid=0 and i.status in (%d) and i.type not in (%d,%d,%d)"
" and " ZBX_SQL_MOD(i.itemid,%d) "=%d and i.key_ not in ('%s','%s','%s','%s')" DB_NODE,
HOST_STATUS_MONITORED,
now,
@@ -201,7 +201,7 @@ static void update_key_status(zbx_uint64_t hostid, int host_status, time_t now)
hostid,
host_status);
- result = DBselect("select %s where h.hostid=i.hostid and h.proxyid=0 and h.hostid=" ZBX_FS_UI64 " and i.key_='%s'",
+ result = DBselect("select %s where h.hostid=i.hostid and h.proxy_hostid=0 and h.hostid=" ZBX_FS_UI64 " and i.key_='%s'",
ZBX_SQL_ITEM_SELECT,
hostid,
SERVER_STATUS_KEY);
@@ -330,7 +330,7 @@ int get_values(void)
result = DBselect("select h.hostid,min(i.itemid) from hosts h,items i"
" where " ZBX_SQL_MOD(h.hostid,%d) "=%d and i.nextcheck<=%d and i.status in (%d)"
" and i.type not in (%d,%d,%d) and h.status=%d and h.disable_until<=%d"
- " and h.errors_from!=0 and h.hostid=i.hostid and h.proxyid=0"
+ " and h.errors_from!=0 and h.hostid=i.hostid and h.proxy_hostid=0"
" and i.key_ not in ('%s','%s','%s','%s')" DB_NODE " group by h.hostid",
CONFIG_UNREACHABLE_POLLER_FORKS,
poller_num-1,
@@ -348,7 +348,7 @@ int get_values(void)
{
result = DBselect("select %s where i.nextcheck<=%d and i.status in (%d,%d)"
" and i.type not in (%d,%d,%d) and h.status=%d and h.disable_until<=%d"
- " and h.errors_from=0 and h.hostid=i.hostid and h.proxyid=0"
+ " and h.errors_from=0 and h.hostid=i.hostid and h.proxy_hostid=0"
" and " ZBX_SQL_MOD(i.itemid,%d) "=%d and i.key_ not in ('%s','%s','%s','%s')"
DB_NODE " order by i.nextcheck",
ZBX_SQL_ITEM_SELECT,
@@ -366,7 +366,7 @@ int get_values(void)
{
result = DBselect("select %s where i.nextcheck<=%d and i.status in (%d)"
" and i.type not in (%d,%d,%d) and h.status=%d and h.disable_until<=%d"
- " and h.errors_from=0 and h.hostid=i.hostid and h.proxyid=0"
+ " and h.errors_from=0 and h.hostid=i.hostid and h.proxy_hostid=0"
" and " ZBX_SQL_MOD(i.itemid,%d) "=%d and i.key_ not in ('%s','%s','%s','%s')"
DB_NODE " order by i.nextcheck",
ZBX_SQL_ITEM_SELECT,
@@ -392,7 +392,7 @@ int get_values(void)
/* Poller for unreachable hosts */
if(poller_type == ZBX_POLLER_TYPE_UNREACHABLE)
{
- result2 = DBselect("select %s where h.hostid=i.hostid and h.proxyid=0 and i.itemid=%s" DB_NODE,
+ result2 = DBselect("select %s where h.hostid=i.hostid and h.proxy_hostid=0 and i.itemid=%s" DB_NODE,
ZBX_SQL_ITEM_SELECT,
row[1],
DBnode_local("h.hostid"));
diff --git a/src/zabbix_server/trapper/active.c b/src/zabbix_server/trapper/active.c
index 710ea21d..7b8fac20 100644
--- a/src/zabbix_server/trapper/active.c
+++ b/src/zabbix_server/trapper/active.c
@@ -71,7 +71,7 @@ int send_list_of_active_checks(zbx_sock_t *sock, const char *host)
if (0 != CONFIG_REFRESH_UNSUPPORTED) {
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.type=%d and h.host='%s'"
- " and h.proxyid=0 and (i.status=%d or (i.status=%d and i.nextcheck<=%d))" DB_NODE,
+ " and h.proxy_hostid=0 and (i.status=%d or (i.status=%d and i.nextcheck<=%d))" DB_NODE,
HOST_STATUS_MONITORED,
ITEM_TYPE_ZABBIX_ACTIVE,
host,
@@ -80,7 +80,7 @@ int send_list_of_active_checks(zbx_sock_t *sock, const char *host)
} else {
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.type=%d and h.host='%s'"
- " and h.proxyid=0 and i.status=%d" DB_NODE,
+ " and h.proxy_hostid=0 and i.status=%d" DB_NODE,
HOST_STATUS_MONITORED,
ITEM_TYPE_ZABBIX_ACTIVE,
host,
@@ -161,7 +161,7 @@ int send_list_of_active_checks_json(zbx_sock_t *sock, struct zbx_json_parse *jso
if (0 != CONFIG_REFRESH_UNSUPPORTED) {
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.type=%d and h.host='%s'"
- " and h.proxyid=0 and (i.status=%d or (i.status=%d and i.nextcheck<=%d))" DB_NODE,
+ " and h.proxy_hostid=0 and (i.status=%d or (i.status=%d and i.nextcheck<=%d))" DB_NODE,
HOST_STATUS_MONITORED,
ITEM_TYPE_ZABBIX_ACTIVE,
host,
@@ -170,7 +170,7 @@ int send_list_of_active_checks_json(zbx_sock_t *sock, struct zbx_json_parse *jso
} else {
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.type=%d and h.host='%s'"
- " and h.proxyid=0 and i.status=%d" DB_NODE,
+ " and h.proxy_hostid=0 and i.status=%d" DB_NODE,
HOST_STATUS_MONITORED,
ITEM_TYPE_ZABBIX_ACTIVE,
host,
diff --git a/src/zabbix_server/trapper/nodehistory.c b/src/zabbix_server/trapper/nodehistory.c
index ae1f13b4..41e30225 100644
--- a/src/zabbix_server/trapper/nodehistory.c
+++ b/src/zabbix_server/trapper/nodehistory.c
@@ -77,13 +77,13 @@ int send_history_last_id(zbx_sock_t *sock, const char *data)
goto error;
zbx_get_next_field(&r, &tmp, &tmp_allocated, ZBX_DM_DELIMITER); /* table name */
- strcpy(tablename, tmp);
+ zbx_strlcpy(tablename, tmp, sizeof(tablename));
if (NULL == r)
goto error;
zbx_get_next_field(&r, &tmp, &tmp_allocated, ZBX_DM_DELIMITER); /* field name */
- strcpy(fieldname, tmp);
+ zbx_strlcpy(fieldname, tmp, sizeof(fieldname));
tmp_offset= 0;
zbx_snprintf_alloc(&tmp, &tmp_allocated, &tmp_offset, 256, "select MAX(%s) "
@@ -173,7 +173,7 @@ int send_trends_last_id(zbx_sock_t *sock, const char *data)
goto error;
zbx_get_next_field(&r, &tmp, &tmp_allocated, ZBX_DM_DELIMITER); /* table name */
- strcpy(tablename, tmp);
+ zbx_strlcpy(tablename, tmp, sizeof(tablename));
tmp_offset= 0;
zbx_snprintf_alloc(&tmp, &tmp_allocated, &tmp_offset, 256, "select itemid,clock "
@@ -351,9 +351,9 @@ static int process_record(int sender_nodeid, int nodeid, const ZBX_TABLE *table,
if (lastrecord && 0 != (table->flags & ZBX_HISTORY_SYNC)) {
if (0 == strcmp(table->fields[f].name, "clock")) {
- strcpy(lastclock, *tmp);
+ zbx_strlcpy(lastclock, *tmp, sizeof(lastclock));
} else if (0 == strcmp(table->fields[f].name, "value")) {
- strcpy(lastvalue, *tmp);
+ zbx_strlcpy(lastvalue, *tmp, sizeof(lastvalue));
lastvalue_type = table->fields[f].type;
}
}
diff --git a/src/zabbix_server/trapper/proxyconfig.c b/src/zabbix_server/trapper/proxyconfig.c
index 0a8c29cd..d850987d 100644
--- a/src/zabbix_server/trapper/proxyconfig.c
+++ b/src/zabbix_server/trapper/proxyconfig.c
@@ -20,6 +20,7 @@
#include "common.h"
#include "db.h"
#include "log.h"
+#include "zlog.h"
#include "proxyconfig.h"
@@ -39,15 +40,15 @@
* Comments: *
* *
******************************************************************************/
-static int get_proxyconfig_table(zbx_uint64_t proxyid, struct zbx_json *j, ZBX_TABLE *table, const char *reltable, const char *relfield)
+static int get_proxyconfig_table(zbx_uint64_t proxy_hostid, struct zbx_json *j, ZBX_TABLE *table, const char *reltable, const char *relfield)
{
char sql[MAX_STRING_LEN];
int offset = 0, f, fld;
DB_RESULT result;
DB_ROW row;
- zabbix_log(LOG_LEVEL_DEBUG, "In get_proxyconfig_table() [proxyid:"ZBX_FS_UI64"] [table:%s]",
- proxyid,
+ zabbix_log(LOG_LEVEL_DEBUG, "In get_proxyconfig_table() [proxy_hostid:" ZBX_FS_UI64 "] [table:%s]",
+ proxy_hostid,
table->table);
zbx_json_addobject(j, table->table);
@@ -74,13 +75,13 @@ static int get_proxyconfig_table(zbx_uint64_t proxyid, struct zbx_json *j, ZBX_T
table->table);
if (NULL == reltable)
- offset += zbx_snprintf(sql + offset, sizeof(sql) - offset, " where t.proxyid="ZBX_FS_UI64,
- proxyid);
+ offset += zbx_snprintf(sql + offset, sizeof(sql) - offset, " where t.proxy_hostid=" ZBX_FS_UI64,
+ proxy_hostid);
else
- offset += zbx_snprintf(sql + offset, sizeof(sql) - offset, ", %1$s r where t.%2$s=r.%2$s and r.proxyid="ZBX_FS_UI64_NO(3),
+ offset += zbx_snprintf(sql + offset, sizeof(sql) - offset, ", %1$s r where t.%2$s=r.%2$s and r.proxy_hostid="ZBX_FS_UI64_NO(3),
reltable,
relfield,
- proxyid);
+ proxy_hostid);
offset += zbx_snprintf(sql + offset, sizeof(sql) - offset, " order by t.%s",
table->recid);
@@ -135,7 +136,7 @@ static int get_proxyconfig_table(zbx_uint64_t proxyid, struct zbx_json *j, ZBX_T
* Comments: *
* *
******************************************************************************/
-static int get_proxyconfig_data(zbx_uint64_t proxyid, struct zbx_json *j)
+static int get_proxyconfig_data(zbx_uint64_t proxy_hostid, struct zbx_json *j)
{
struct proxytable_t {
const char *table;
@@ -144,7 +145,6 @@ static int get_proxyconfig_data(zbx_uint64_t proxyid, struct zbx_json *j)
};
static const struct proxytable_t pt[]={
- {"proxies", NULL, NULL},
{"hosts", NULL, NULL},
{"items", "hosts", "hostid"},
{"drules", NULL, NULL},
@@ -153,15 +153,15 @@ static int get_proxyconfig_data(zbx_uint64_t proxyid, struct zbx_json *j)
};
int t, p, ret = SUCCEED;
- zabbix_log(LOG_LEVEL_DEBUG, "In get_proxyconfig_data() [proxyid:"ZBX_FS_UI64"]",
- proxyid);
+ zabbix_log(LOG_LEVEL_DEBUG, "In get_proxyconfig_data() [proxy_hostid:" ZBX_FS_UI64 "]",
+ proxy_hostid);
for (t = 0; tables[t].table != 0; t++) {
for (p = 0; pt[p].table != NULL; p++) {
if (0 != strcmp(tables[t].table, pt[p].table))
continue;
- ret = get_proxyconfig_table(proxyid, j, &tables[t], pt[p].reltable, pt[p].relfield);
+ ret = get_proxyconfig_table(proxy_hostid, j, &tables[t], pt[p].reltable, pt[p].relfield);
}
}
@@ -171,9 +171,9 @@ static int get_proxyconfig_data(zbx_uint64_t proxyid, struct zbx_json *j)
/******************************************************************************
* *
- * Function: send_proxyconfig *
+ * Function: get_proxy_id *
* *
- * Purpose: send all configuration tables to the proxy *
+ * Purpose: *
* *
* Parameters: *
* *
@@ -185,47 +185,105 @@ static int get_proxyconfig_data(zbx_uint64_t proxyid, struct zbx_json *j)
* Comments: *
* *
******************************************************************************/
-int send_proxyconfig(zbx_sock_t *sock, struct zbx_json_parse *jp)
+int get_proxy_id(struct zbx_json_parse *jp, zbx_uint64_t *hostid)
{
- char hostname[MAX_STRING_LEN],
- host_esc[MAX_STRING_LEN];
DB_RESULT result;
DB_ROW row;
- zbx_uint64_t proxyid;
- struct zbx_json j;
+ char host[HOST_HOST_LEN_MAX], host_esc[MAX_STRING_LEN];
int res = FAIL;
- zabbix_log(LOG_LEVEL_DEBUG, "In send_proxyconfig()");
+ if (SUCCEED == zbx_json_value_by_name(jp, ZBX_PROTO_TAG_HOST, host, sizeof(host))) {
+ DBescape_string(host, host_esc, sizeof(host_esc));
- if (FAIL == zbx_json_value_by_name(jp, ZBX_PROTO_TAG_HOST, hostname, sizeof(hostname)))
- return res;
+ result = DBselect("select hostid from hosts where host='%s'"
+ " and status in (%d)" DB_NODE,
+ host_esc,
+ HOST_STATUS_PROXY,
+ DBnode_local("hostid"));
- DBescape_string(hostname, host_esc, MAX_STRING_LEN);
- result = DBselect("select proxyid from proxies where name='%s'" DB_NODE,
- host_esc,
- DBnode_local("proxyid"));
+ if (NULL != (row = DBfetch(result)) && FAIL == DBis_null(row[0])) {
+ *hostid = zbx_atoui64(row[0]);
+ res = SUCCEED;
+ } else
+ zabbix_log(LOG_LEVEL_WARNING, "Unknown proxy \"%s\"",
+ host);
- if (NULL != (row = DBfetch(result))) {
- proxyid = zbx_atoui64(row[0]);
-
- zbx_json_init(&j, 512*1024);
- if (SUCCEED == get_proxyconfig_data(proxyid, &j)) {
- zabbix_log(LOG_LEVEL_WARNING, "Sending configuration data to proxy \"%s\" datalen %zd",
- hostname,
- j.buffer_size);
-
- if (FAIL == zbx_tcp_send(sock, j.buffer))
- zabbix_log(LOG_LEVEL_WARNING, "Error while sending configuration to the \"%s\" [%s]",
- hostname,
- zbx_tcp_strerror());
- }
- zbx_json_free(&j);
+ DBfree_result(result);
} else {
- zabbix_log(LOG_LEVEL_WARNING, "Unknown hostname \"%s\"", hostname);
+ zabbix_log(LOG_LEVEL_WARNING, "Incorrect data. %s",
+ zbx_json_strerror());
+ zabbix_syslog("Incorrect data. %s",
+ zbx_json_strerror());
}
- DBfree_result(result);
+ return res;
+}
+
+/******************************************************************************
+ * *
+ * Function: update_proxy_lastaccess *
+ * *
+ * Purpose: *
+ * *
+ * Parameters: *
+ * *
+ * Return value: SUCCEED - processed successfully *
+ * FAIL - an error occured *
+ * *
+ * Author: Aleksander Vladishev *
+ * *
+ * Comments: *
+ * *
+ ******************************************************************************/
+void update_proxy_lastaccess(const zbx_uint64_t hostid)
+{
+ DBexecute("update hosts set lastaccess=%d where hostid=" ZBX_FS_UI64,
+ time(NULL),
+ hostid);
+}
+
+/******************************************************************************
+ * *
+ * Function: send_proxyconfig *
+ * *
+ * Purpose: send configuration tables to the proxy *
+ * *
+ * Parameters: *
+ * *
+ * Return value: SUCCEED - processed successfully *
+ * FAIL - an error occured *
+ * *
+ * Author: Aleksander Vladishev *
+ * *
+ * Comments: *
+ * *
+ ******************************************************************************/
+int send_proxyconfig(zbx_sock_t *sock, struct zbx_json_parse *jp)
+{
+ zbx_uint64_t proxy_hostid;
+ struct zbx_json j;
+ int res = FAIL;
+
+ zabbix_log(LOG_LEVEL_DEBUG, "In send_proxyconfig()");
+ if (FAIL == get_proxy_id(jp, &proxy_hostid))
+ goto exit;
+
+ update_proxy_lastaccess(proxy_hostid);
+
+ zbx_json_init(&j, 512*1024);
+ if (SUCCEED == (res = get_proxyconfig_data(proxy_hostid, &j))) {
+ zabbix_log(LOG_LEVEL_WARNING, "Sending configuration data to proxy. Datalen %d",
+ (int)j.buffer_size);
+ zabbix_log(LOG_LEVEL_DEBUG, "%s",
+ j.buffer);
+
+ if (FAIL == (res = zbx_tcp_send(sock, j.buffer)))
+ zabbix_log(LOG_LEVEL_WARNING, "Error while sending configuration. %s",
+ zbx_tcp_strerror());
+ }
+ zbx_json_free(&j);
+exit:
return res;
}
diff --git a/src/zabbix_server/trapper/proxyconfig.h b/src/zabbix_server/trapper/proxyconfig.h
index cd33281e..06b3ebd7 100644
--- a/src/zabbix_server/trapper/proxyconfig.h
+++ b/src/zabbix_server/trapper/proxyconfig.h
@@ -24,6 +24,8 @@
#include "comms.h"
#include "zbxjson.h"
+int get_proxy_id(struct zbx_json_parse *jp, zbx_uint64_t *hostid);
+void update_proxy_lastaccess(const zbx_uint64_t hostid);
int send_proxyconfig(zbx_sock_t *sock, struct zbx_json_parse *jp);
#endif
diff --git a/src/zabbix_server/trapper/proxydiscovery.c b/src/zabbix_server/trapper/proxydiscovery.c
index 9a862d4b..4a459dcf 100644
--- a/src/zabbix_server/trapper/proxydiscovery.c
+++ b/src/zabbix_server/trapper/proxydiscovery.c
@@ -23,6 +23,7 @@
#include "zlog.h"
#include "trapper.h"
+#include "proxyconfig.h"
#include "proxydiscovery.h"
#include "../discoverer/discoverer.h"
@@ -44,9 +45,7 @@
******************************************************************************/
int process_discovery_data(zbx_sock_t *sock, struct zbx_json_parse *jp)
{
- char tmp[MAX_STRING_LEN],
- host_esc[MAX_STRING_LEN];
- DB_RESULT result;
+ char tmp[MAX_STRING_LEN];
DB_DCHECK check;
DB_DHOST host;
DB_DSERVICE service;
@@ -58,39 +57,19 @@ int process_discovery_data(zbx_sock_t *sock, struct zbx_json_parse *jp)
char ip[HOST_IP_LEN_MAX],
key_[ITEM_KEY_LEN_MAX];
time_t now, hosttime, itemtime;
+ zbx_uint64_t proxy_hostid;
zabbix_log(LOG_LEVEL_DEBUG, "In process_discovery_data()");
- if (FAIL == zbx_json_value_by_name(jp, ZBX_PROTO_TAG_PROXY, tmp, sizeof(tmp))) {
- zabbix_log(LOG_LEVEL_WARNING, "Invalid discovery data. %s",
- zbx_json_strerror());
- zabbix_syslog("Invalid discovery data. %s",
- zbx_json_strerror());
-
+ if (FAIL == get_proxy_id(jp, &proxy_hostid)) {
res = FAIL;
goto exit;
}
+ update_proxy_lastaccess(proxy_hostid);
+
now = time(NULL);
- DBescape_string(tmp, host_esc, MAX_STRING_LEN);
- result = DBselect("select proxyid from proxies where name='%s'" DB_NODE,
- host_esc,
- DBnode_local("proxyid"));
-
- if (NULL == DBfetch(result)) {
- zabbix_log(LOG_LEVEL_WARNING, "Hostname \"%s\" is unknown",
- tmp);
- zabbix_syslog("Hostname \"%s\" is unknown",
- tmp);
-
- res = FAIL;
- }
- DBfree_result(result);
-
- if (FAIL == res)
- goto exit;
-
if (FAIL == zbx_json_value_by_name(jp, ZBX_PROTO_TAG_CLOCK, tmp, sizeof(tmp))) {
res = FAIL;
goto exit;
diff --git a/src/zabbix_server/trapper/trapper.c b/src/zabbix_server/trapper/trapper.c
index d97ea036..a9b895c7 100644
--- a/src/zabbix_server/trapper/trapper.c
+++ b/src/zabbix_server/trapper/trapper.c
@@ -136,7 +136,7 @@ static void calc_timestamp(char *line,int *timestamp, char *format)
* Comments: for trapper server process *
* *
******************************************************************************/
-static int process_data(zbx_sock_t *sock, zbx_uint64_t proxyid, time_t now, char *server, char *key, char *value,
+static int process_data(zbx_sock_t *sock, zbx_uint64_t proxy_hostid, time_t now, char *server, char *key, char *value,
char *lastlogsize, char *timestamp, char *source, char *severity)
{
AGENT_RESULT agent;
@@ -155,7 +155,7 @@ static int process_data(zbx_sock_t *sock, zbx_uint64_t proxyid, time_t now, char
DBescape_string(server, server_esc, MAX_STRING_LEN);
DBescape_string(key, key_esc, MAX_STRING_LEN);
- if (proxyid == 0) {
+ if (proxy_hostid == 0) {
zbx_snprintf(item_types, sizeof(item_types), "%d,%d",
ITEM_TYPE_TRAPPER,
ITEM_TYPE_ZABBIX_ACTIVE);
@@ -172,12 +172,12 @@ static int process_data(zbx_sock_t *sock, zbx_uint64_t proxyid, time_t now, char
ITEM_TYPE_EXTERNAL);
}
- result = DBselect("select %s where h.status=%d and h.hostid=i.hostid and h.host='%s' and h.proxyid=" ZBX_FS_UI64
+ result = DBselect("select %s where h.status=%d and h.hostid=i.hostid and h.host='%s' and h.proxy_hostid=" ZBX_FS_UI64
" and i.key_='%s' and i.status in (%d,%d) and i.type in (%s)" DB_NODE,
ZBX_SQL_ITEM_SELECT,
HOST_STATUS_MONITORED,
server_esc,
- proxyid,
+ proxy_hostid,
key_esc,
ITEM_STATUS_ACTIVE, ITEM_STATUS_NOTSUPPORTED,
item_types,
@@ -324,45 +324,30 @@ int send_result(zbx_sock_t *sock, int result, char *info)
* Comments: *
* *
******************************************************************************/
-static int process_new_values(zbx_sock_t *sock, struct zbx_json_parse *json)
+static int process_new_values(zbx_sock_t *sock, struct zbx_json_parse *jp, const zbx_uint64_t proxy_hostid)
{
struct zbx_json_parse jp_data, jp_row;
const char *p;
- char proxy[PROXY_NAME_LEN_MAX], host[HOST_HOST_LEN_MAX], key[ITEM_KEY_LEN_MAX],
+ char host[HOST_HOST_LEN_MAX], key[ITEM_KEY_LEN_MAX],
value[MAX_STRING_LEN], info[MAX_STRING_LEN], lastlogsize[MAX_STRING_LEN],
timestamp[MAX_STRING_LEN], source[MAX_STRING_LEN], severity[MAX_STRING_LEN],
clock[MAX_STRING_LEN];
int ret = SUCCEED;
int processed_ok = 0, processed_fail = 0;
- DB_RESULT result;
- DB_ROW row;
double sec;
- zbx_uint64_t proxyid = 0;
time_t now, hosttime = 0, itemtime;
- zabbix_log(LOG_LEVEL_DEBUG, "In process_new_values(json:%.*s)",
- json->end - json->start + 1,
- json->start);
+ zabbix_log(LOG_LEVEL_DEBUG, "In process_new_values()");
now = time(NULL);
sec = zbx_time();
- if (SUCCEED == zbx_json_value_by_name(json, ZBX_PROTO_TAG_PROXY, proxy, sizeof(proxy))) {
- result = DBselect("select proxyid from proxies where name='%s'",
- proxy);
-
- if (NULL != (row = DBfetch(result)) && FAIL == DBis_null(row[0]))
- proxyid = zbx_atoui64(row[0]);
- DBfree_result(result);
-
- }
-
- if (SUCCEED == zbx_json_value_by_name(json, ZBX_PROTO_TAG_CLOCK, clock, sizeof(clock)))
+ if (SUCCEED == zbx_json_value_by_name(jp, ZBX_PROTO_TAG_CLOCK, clock, sizeof(clock)))
hosttime = atoi(clock);
/* {"request":"ZBX_SENDER_DATA","data":[{"key":"system.cpu.num",...,...},{...},...]}
* ^
- */ if (NULL == (p = zbx_json_pair_by_name(json, ZBX_PROTO_TAG_DATA)))
+ */ if (NULL == (p = zbx_json_pair_by_name(jp, ZBX_PROTO_TAG_DATA)))
{
zabbix_log(LOG_LEVEL_WARNING, "Can't find \"data\" pair");
ret = FAIL;
@@ -422,7 +407,7 @@ static int process_new_values(zbx_sock_t *sock, struct zbx_json_parse *json)
zbx_json_value_by_name(&jp_row, ZBX_PROTO_TAG_LOGSEVERITY, severity, sizeof(severity));
DBbegin();
- if(SUCCEED == process_data(sock, proxyid, itemtime, host, key, value, lastlogsize, timestamp, source, severity))
+ if(SUCCEED == process_data(sock, proxy_hostid, itemtime, host, key, value, lastlogsize, timestamp, source, severity))
{
processed_ok ++;
}
@@ -448,7 +433,35 @@ static int process_new_values(zbx_sock_t *sock, struct zbx_json_parse *json)
return ret;
}
-static int process_trap(zbx_sock_t *sock,char *s, int max_len)
+/******************************************************************************
+ * *
+ * Function: process_proxy_values *
+ * *
+ * Purpose: process values sent by proxy servers *
+ * *
+ * Parameters: *
+ * *
+ * Return value: SUCCEED - processed successfully *
+ * FAIL - an error occured *
+ * *
+ * Author: Alksander Vladishev *
+ * *
+ * Comments: *
+ * *
+ ******************************************************************************/
+static int process_proxy_values(zbx_sock_t *sock, struct zbx_json_parse *jp)
+{
+ zbx_uint64_t proxy_hostid;
+
+ if (FAIL == get_proxy_id(jp, &proxy_hostid))
+ return FAIL;
+
+ update_proxy_lastaccess(proxy_hostid);
+
+ return process_new_values(sock, jp, proxy_hostid);
+}
+
+static int process_trap(zbx_sock_t *sock, char *s, int max_len)
{
char *line,*host;
char *server,*key,*value_string, *data;
@@ -547,13 +560,15 @@ static int process_trap(zbx_sock_t *sock,char *s, int max_len)
send_proxyconfig(sock, &jp);
}
else if (0 == strcmp(value, ZBX_PROTO_VALUE_AGENT_DATA) ||
- 0 == strcmp(value, ZBX_PROTO_VALUE_SENDER_DATA) ||
- 0 == strcmp(value, ZBX_PROTO_VALUE_HISTORY_DATA)
- )
+ 0 == strcmp(value, ZBX_PROTO_VALUE_SENDER_DATA))
+ {
+ ret = process_new_values(sock, &jp, 0);
+ }
+ else if (0 == strcmp(value, ZBX_PROTO_VALUE_HISTORY_DATA) && zbx_process == ZBX_PROCESS_SERVER)
{
- ret = process_new_values(sock, &jp);
+ ret = process_proxy_values(sock, &jp);
}
- else if (0 == strcmp(value, ZBX_PROTO_VALUE_DISCOVERY_DATA))
+ else if (0 == strcmp(value, ZBX_PROTO_VALUE_DISCOVERY_DATA) && zbx_process == ZBX_PROCESS_SERVER)
{
ret = process_discovery_data(sock, &jp);
}