summaryrefslogtreecommitdiffstats
path: root/src/zabbix_proxy
diff options
context:
space:
mode:
authorsasha <sasha@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2008-02-15 18:08:13 +0000
committersasha <sasha@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2008-02-15 18:08:13 +0000
commita108856b0ce83183ef5a13429f377ea0caf5e6fe (patch)
tree521c9be51b5d829ac903b9d44abe9d43ef47c1cc /src/zabbix_proxy
parent7b92c6ee9986e74742de2ca2196fadab18e0ad7e (diff)
downloadzabbix-a108856b0ce83183ef5a13429f377ea0caf5e6fe.tar.gz
zabbix-a108856b0ce83183ef5a13429f377ea0caf5e6fe.tar.xz
zabbix-a108856b0ce83183ef5a13429f377ea0caf5e6fe.zip
- [DEV-110] Proxy changes
git-svn-id: svn://svn.zabbix.com/trunk@5356 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src/zabbix_proxy')
-rw-r--r--src/zabbix_proxy/Makefile.am4
-rw-r--r--src/zabbix_proxy/proxy.c14
-rw-r--r--src/zabbix_proxy/trapper/Makefile.am7
-rw-r--r--src/zabbix_proxy/trapper/active.c120
-rw-r--r--src/zabbix_proxy/trapper/active.h30
-rw-r--r--src/zabbix_proxy/trapper/trapper.c188
-rw-r--r--src/zabbix_proxy/trapper/trapper.h31
7 files changed, 12 insertions, 382 deletions
diff --git a/src/zabbix_proxy/Makefile.am b/src/zabbix_proxy/Makefile.am
index afbc902a..d624e038 100644
--- a/src/zabbix_proxy/Makefile.am
+++ b/src/zabbix_proxy/Makefile.am
@@ -8,7 +8,7 @@ SUBDIRS = \
proxyconfig \
../zabbix_server/pinger \
poller \
- trapper
+ ../zabbix_server/trapper
sbin_PROGRAMS = zabbix_proxy
@@ -29,7 +29,7 @@ zabbix_proxy_LDADD = \
proxyconfig/libzbxproxyconfig.a \
$(top_srcdir)/src/zabbix_server/pinger/libzbxpinger.a \
poller/libzbxpoller.a \
- trapper/libzbxtrapper.a \
+ $(top_srcdir)/src/zabbix_server/trapper/libzbxtrapper.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/proxy.c b/src/zabbix_proxy/proxy.c
index d43b42e7..c029db19 100644
--- a/src/zabbix_proxy/proxy.c
+++ b/src/zabbix_proxy/proxy.c
@@ -47,7 +47,7 @@
#include "../zabbix_server/pinger/pinger.h"
#include "poller/poller.h"
#include "poller/checks_snmp.h"
-#include "trapper/trapper.h"
+#include "../zabbix_server/trapper/trapper.h"
#include "proxyconfig/proxyconfig.h"
/*
@@ -487,13 +487,19 @@ int MAIN_ZABBIX_ENTRY(void)
server_num,
SNMP_FEATURE_STATUS);
main_poller_loop(ZBX_POLLER_TYPE_NORMAL, server_num);
- } else if (server_num <= CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS) {
+ }
+ else if (server_num <= 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(server_num, &listen_sock);
+ 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_POLLER_FORKS + CONFIG_TRAPPERD_FORKS + CONFIG_PINGER_FORKS)
{
main_pinger_loop(server_num, server_num - (CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS));
}
diff --git a/src/zabbix_proxy/trapper/Makefile.am b/src/zabbix_proxy/trapper/Makefile.am
deleted file mode 100644
index 9bd56edd..00000000
--- a/src/zabbix_proxy/trapper/Makefile.am
+++ /dev/null
@@ -1,7 +0,0 @@
-## Process this file with automake to produce Makefile.in
-
-noinst_LIBRARIES = libzbxtrapper.a
-
-libzbxtrapper_a_SOURCES = \
- active.c active.h \
- trapper.c trapper.h
diff --git a/src/zabbix_proxy/trapper/active.c b/src/zabbix_proxy/trapper/active.c
deleted file mode 100644
index 0500e81d..00000000
--- a/src/zabbix_proxy/trapper/active.c
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
-** 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 "active.h"
-
-/******************************************************************************
- * *
- * Function: send_list_of_active_checks *
- * *
- * Purpose: send list of active checks to the host *
- * *
- * Parameters: sockfd - open socket of server-agent connection *
- * host - hostname *
- * *
- * Return value: SUCCEED - list of active checks sent succesfully *
- * FAIL - an error occured *
- * *
- * Author: Alexei Vladishev *
- * *
- * Comments: format of the list: key:delay:last_log_size *
- * *
- ******************************************************************************/
-int send_list_of_active_checks(zbx_sock_t *sock, const char *host)
-{
- char s[MAX_STRING_LEN];
- DB_RESULT result;
- DB_ROW row;
-
- zabbix_log( LOG_LEVEL_DEBUG, "In send_list_of_active_checks()");
-
- 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 (i.status=%d or (i.status=%d and i.nextcheck<=%d)) and"ZBX_COND_NODEID,
- HOST_STATUS_MONITORED,
- ITEM_TYPE_ZABBIX_ACTIVE,
- host,
- ITEM_STATUS_ACTIVE, ITEM_STATUS_NOTSUPPORTED, time(NULL),
- LOCAL_NODE("h.hostid"));
- } 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 i.status=%d and"ZBX_COND_NODEID,
- HOST_STATUS_MONITORED,
- ITEM_TYPE_ZABBIX_ACTIVE,
- host,
- ITEM_STATUS_ACTIVE,
- LOCAL_NODE("h.hostid"));
- }
-
- while((row=DBfetch(result)))
- {
- zbx_snprintf(s,sizeof(s),"%s:%s:%s\n",
- row[0],
- row[1],
- row[2]);
- zabbix_log( LOG_LEVEL_DEBUG, "Sending [%s]",
- s);
-
- if( zbx_tcp_send_raw(sock,s) != SUCCEED )
- {
- zabbix_log( LOG_LEVEL_WARNING, "Error while sending list of active checks");
- return FAIL;
- }
- }
- DBfree_result(result);
-
- zbx_snprintf(s,sizeof(s),"%s\n",
- "ZBX_EOF");
- zabbix_log( LOG_LEVEL_DEBUG, "Sending [%s]",
- s);
-
- if( zbx_tcp_send_raw(sock,s) != SUCCEED )
- {
- zabbix_log( LOG_LEVEL_WARNING, "Error while sending list of active checks");
- return FAIL;
- }
-
- return SUCCEED;
-}
diff --git a/src/zabbix_proxy/trapper/active.h b/src/zabbix_proxy/trapper/active.h
deleted file mode 100644
index 3b31ea74..00000000
--- a/src/zabbix_proxy/trapper/active.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
-** 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_TRAPPER_ACTIVE_H
-#define ZABBIX_TRAPPER_ACTIVE_H
-
-#include "common.h"
-#include "db.h"
-#include "comms.h"
-
-int send_list_of_active_checks(zbx_sock_t *sock, const char *host);
-
-#endif
diff --git a/src/zabbix_proxy/trapper/trapper.c b/src/zabbix_proxy/trapper/trapper.c
deleted file mode 100644
index 65a5fb02..00000000
--- a/src/zabbix_proxy/trapper/trapper.c
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
-** 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 "common.h"
-
-#include "cfg.h"
-#include "comms.h"
-#include "pid.h"
-#include "db.h"
-#include "log.h"
-#include "zlog.h"
-
-#include "../functions.h"
-#include "../expression.h"
-
-#include "trapper.h"
-#include "active.h"
-
-#include "daemon.h"
-
-static int process_trap(zbx_sock_t *sock,char *s, int max_len)
-{
- char *line,*host;
- char *server,*key,*value_string;
- char copy[MAX_STRING_LEN];
- char host_dec[MAX_STRING_LEN],key_dec[MAX_STRING_LEN],value_dec[MAX_STRING_LEN];
- char lastlogsize[MAX_STRING_LEN];
- char timestamp[MAX_STRING_LEN];
- char source[MAX_STRING_LEN];
- char severity[MAX_STRING_LEN];
-
- int ret=SUCCEED;
- size_t datalen;
-
- zbx_rtrim(s, " \r\n\0");
-
- datalen = strlen(s);
- zabbix_log( LOG_LEVEL_DEBUG, "Trapper got [%s] len %zd",
- s,
- datalen);
-/* Request for list of active checks */
- if (strncmp(s,"ZBX_GET_ACTIVE_CHECKS", 21) == 0) {
- line=strtok(s,"\n");
- host=strtok(NULL,"\n");
- if(host == NULL)
- {
- zabbix_log( LOG_LEVEL_WARNING, "ZBX_GET_ACTIVE_CHECKS: host is null. Ignoring.");
- }
- else
- {
- ret = send_list_of_active_checks(sock, host);
- }
-/* Process information sent by zabbix_sender */
- } else {
- /* New XML protocol? */
- if(s[0]=='<')
- {
- zabbix_log( LOG_LEVEL_DEBUG, "XML received [%s]", s);
-
- comms_parse_response(s,host_dec,key_dec,value_dec,lastlogsize,timestamp,source,severity,sizeof(host_dec)-1);
-
- server=host_dec;
- value_string=value_dec;
- key=key_dec;
- }
- else
- {
- strscpy(copy,s);
-
- server=(char *)strtok(s,":");
- if(NULL == server)
- {
- return FAIL;
- }
-
- key=(char *)strtok(NULL,":");
- if(NULL == key)
- {
- return FAIL;
- }
-
- value_string=strchr(copy,':');
- value_string=strchr(value_string+1,':');
-
- if(NULL == value_string)
- {
- return FAIL;
- }
- /* It points to ':', so have to increment */
- value_string++;
- lastlogsize[0]=0;
- timestamp[0]=0;
- source[0]=0;
- severity[0]=0;
- }
- zabbix_log( LOG_LEVEL_DEBUG, "Value [%s]", value_string);
-
- DBbegin();
- ret=process_data(sock,server,key,value_string,lastlogsize,timestamp,source,severity);
- DBcommit();
-
- if( zbx_tcp_send_raw(sock, SUCCEED == ret ? "OK" : "NOT OK") != SUCCEED)
- {
- zabbix_log( LOG_LEVEL_WARNING, "Error sending result back");
- zabbix_syslog("Trapper: error sending result back");
- }
- zabbix_log( LOG_LEVEL_DEBUG, "After write()");
- }
- return ret;
-}
-
-void process_trapper_child(zbx_sock_t *sock)
-{
- char *data;
-
-/* suseconds_t is not defined under HP-UX */
-/* struct timeval tv;
- suseconds_t msec;
- gettimeofday(&tv, NULL);
- msec = tv.tv_usec;*/
-
-/* alarm(CONFIG_TIMEOUT);*/
-
- if(zbx_tcp_recv(sock, &data) != SUCCEED)
- {
-/* alarm(0);*/
- return;
- }
-
- process_trap(sock, data, sizeof(data));
-/* alarm(0);*/
-
-/* gettimeofday(&tv, NULL);
- zabbix_log( LOG_LEVEL_DEBUG, "Trap processed in " ZBX_FS_DBL " seconds",
- (double)(tv.tv_usec-msec)/1000000 );*/
-}
-
-void child_trapper_main(int i, zbx_sock_t *s)
-{
- zabbix_log( LOG_LEVEL_DEBUG, "In child_trapper_main()");
-
- zabbix_log( LOG_LEVEL_WARNING, "server #%d started [Trapper]", i);
-
- DBconnect(ZBX_DB_CONNECT_NORMAL);
-
- for(;;)
- {
- zbx_setproctitle("waiting for connection");
- zbx_tcp_accept(s);
-
- zbx_setproctitle("processing data");
- process_trapper_child(s);
-
- zbx_tcp_unaccept(s);
- }
- DBclose();
-}
-
-/*
-pid_t child_trapper_make(int i,int listenfd, int addrlen)
-{
- pid_t pid;
-
- if((pid = zbx_fork()) >0)
- {
- return (pid);
- }
-
- child_trapper_main(i, listenfd, addrlen);
-
- return 0;
-}*/
diff --git a/src/zabbix_proxy/trapper/trapper.h b/src/zabbix_proxy/trapper/trapper.h
deleted file mode 100644
index 3e3b543d..00000000
--- a/src/zabbix_proxy/trapper/trapper.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
-** 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_TRAPPER_H
-#define ZABBIX_TRAPPER_H
-
-extern int server_num;
-
-extern int CONFIG_TIMEOUT;
-
-extern void signal_handler( int sig );
-
-void child_trapper_main(int i, zbx_sock_t *s);
-
-#endif