diff options
author | hugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2002-03-22 19:05:33 +0000 |
---|---|---|
committer | hugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2002-03-22 19:05:33 +0000 |
commit | 2df01e808f9caf6847dbab29214135b532ea82b0 (patch) | |
tree | dd2a3594327708c5d37d311eb262ff5af01fedb4 /src/zabbix_trapper | |
parent | 5c6297d5fc9e9ee39c32bab2a7e12dc08e907d62 (diff) | |
download | zabbix-2df01e808f9caf6847dbab29214135b532ea82b0.tar.gz zabbix-2df01e808f9caf6847dbab29214135b532ea82b0.tar.xz zabbix-2df01e808f9caf6847dbab29214135b532ea82b0.zip |
- parameter Server can consist of list of Zabbix servers (Alexei)
- SO_LINGER is default socket option for zabbix_sender (Alexei)
- added support of NoTimeWait for zabbix_trapperd (Alexei)
- fixed schema for PostgreSQL, column disable_until (Alexei)
git-svn-id: svn://svn.zabbix.com/trunk@340 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src/zabbix_trapper')
-rw-r--r-- | src/zabbix_trapper/Makefile.in | 4 | ||||
-rw-r--r-- | src/zabbix_trapper/zabbix_trapper.c | 27 | ||||
-rw-r--r-- | src/zabbix_trapper/zabbix_trapperd.c | 48 |
3 files changed, 75 insertions, 4 deletions
diff --git a/src/zabbix_trapper/Makefile.in b/src/zabbix_trapper/Makefile.in index 5af74e5d..c100817a 100644 --- a/src/zabbix_trapper/Makefile.in +++ b/src/zabbix_trapper/Makefile.in @@ -5,8 +5,8 @@ LIBS = @LIBS@ @MYSQL_LFLAGS@ @PGSQL_LFLAGS@ all: - @CC@ -o ../../bin/zabbix_trapper @CFLAGS@ $(INCLUDE) -I../../include zabbix_trapper.c ../../include/db.c ../../include/functions.c ../../include/expression.c ../../include/log.c -Wall $(LIBS) - @CC@ -o ../../bin/zabbix_trapperd @CFLAGS@ $(INCLUDE) -I../../include zabbix_trapperd.c ../../include/db.c ../../include/functions.c ../../include/expression.c ../../include/log.c -Wall $(LIBS) + @CC@ -o ../../bin/zabbix_trapper @CFLAGS@ $(INCLUDE) -I../../include zabbix_trapper.c ../../include/db.c ../../include/functions.c ../../include/expression.c ../../include/log.c ../../include/cfg.c -Wall $(LIBS) + @CC@ -o ../../bin/zabbix_trapperd @CFLAGS@ $(INCLUDE) -I../../include zabbix_trapperd.c ../../include/db.c ../../include/functions.c ../../include/expression.c ../../include/log.c ../../include/cfg.c -Wall $(LIBS) clean: rm -fv *.o diff --git a/src/zabbix_trapper/zabbix_trapper.c b/src/zabbix_trapper/zabbix_trapper.c index ab21ef7b..bd801348 100644 --- a/src/zabbix_trapper/zabbix_trapper.c +++ b/src/zabbix_trapper/zabbix_trapper.c @@ -24,6 +24,7 @@ #include "common.h" #include "db.h" #include "log.h" +#include "cfg.h" #include "functions.h" int CONFIG_TIMEOUT = TRAPPER_TIMEOUT; @@ -50,7 +51,30 @@ void signal_handler( int sig ) exit( FAIL ); } +void init_config(void) +{ + static struct cfg_line cfg[]= + { +/* PARAMETER ,VAR ,FUNC, TYPE(0i,1s),MANDATORY,MIN,MAX +*/ + {"Timeout",&CONFIG_TIMEOUT,0,TYPE_INT,PARM_OPT,1,30}, + {"DebugLevel",&CONFIG_LOG_LEVEL,0,TYPE_INT,PARM_OPT,1,3}, + {"LogFile",&CONFIG_LOG_FILE,0,TYPE_STRING,PARM_OPT,0,0}, + {"DBName",&CONFIG_DBNAME,0,TYPE_STRING,PARM_MAND,0,0}, + {"DBUser",&CONFIG_DBUSER,0,TYPE_STRING,PARM_OPT,0,0}, + {"DBPassword",&CONFIG_DBPASSWORD,0,TYPE_STRING,PARM_OPT,0,0}, + {"DBSocket",&CONFIG_DBSOCKET,0,TYPE_STRING,PARM_OPT,0,0}, + {0} + }; + parse_cfg_file("/etc/zabbix/zabbix_trapper.conf",cfg); + if(CONFIG_DBNAME == NULL) + { + zabbix_log( LOG_LEVEL_CRIT, "DBName not in config file"); + exit(1); + } +} + void process_config_file(void) { FILE *file; @@ -185,7 +209,8 @@ int main() zabbix_open_log(LOG_TYPE_FILE,CONFIG_LOG_LEVEL,CONFIG_LOG_FILE); } - process_config_file(); +/* process_config_file();*/ + init_config(); fgets(s,MAX_STRING_LEN,stdin); for( p=s+strlen(s)-1; p>s && ( *p=='\r' || *p =='\n' || *p == ' ' ); --p ); diff --git a/src/zabbix_trapper/zabbix_trapperd.c b/src/zabbix_trapper/zabbix_trapperd.c index 24643df8..dd2bbd31 100644 --- a/src/zabbix_trapper/zabbix_trapperd.c +++ b/src/zabbix_trapper/zabbix_trapperd.c @@ -27,6 +27,7 @@ #include "common.h" #include "db.h" #include "log.h" +#include "cfg.h" #include "functions.h" #define LISTENQ 1024 @@ -39,6 +40,7 @@ int CONFIG_TRAPPERD_FORKS = TRAPPERD_FORKS; int CONFIG_LISTEN_PORT = 10001; int CONFIG_TIMEOUT = TRAPPER_TIMEOUT; int CONFIG_LOG_LEVEL = LOG_LEVEL_WARNING; +int CONFIG_NOTIMEWAIT = 0; char *CONFIG_PID_FILE = NULL; char *CONFIG_LOG_FILE = NULL; char *CONFIG_DBNAME = NULL; @@ -121,6 +123,38 @@ void signal_handler( int sig ) } } +void init_config(void) +{ + static struct cfg_line cfg[]= + { +/* PARAMETER ,VAR ,FUNC, TYPE(0i,1s),MANDATORY,MIN,MAX +*/ + {"StartTrappers",&CONFIG_TRAPPERD_FORKS,0,TYPE_INT,PARM_OPT,2,255}, + {"Timeout",&CONFIG_TIMEOUT,0,TYPE_INT,PARM_OPT,1,30}, + {"ListenPort",&CONFIG_LISTEN_PORT,0,TYPE_INT,PARM_OPT,1024,32768}, + {"DebugLevel",&CONFIG_LOG_LEVEL,0,TYPE_INT,PARM_OPT,1,3}, + {"PidFile",&CONFIG_PID_FILE,0,TYPE_STRING,PARM_OPT,0,0}, + {"LogFile",&CONFIG_LOG_FILE,0,TYPE_STRING,PARM_OPT,0,0}, + {"DBName",&CONFIG_DBNAME,0,TYPE_STRING,PARM_MAND,0,0}, + {"DBUser",&CONFIG_DBUSER,0,TYPE_STRING,PARM_OPT,0,0}, + {"DBPassword",&CONFIG_DBPASSWORD,0,TYPE_STRING,PARM_OPT,0,0}, + {"DBSocket",&CONFIG_DBSOCKET,0,TYPE_STRING,PARM_OPT,0,0}, + {"NoTimeWait",&CONFIG_NOTIMEWAIT,0,TYPE_INT,PARM_OPT,0,1}, + {0} + }; + + parse_cfg_file("/etc/zabbix/zabbix_trapperd.conf",cfg); + if(CONFIG_DBNAME == NULL) + { + zabbix_log( LOG_LEVEL_CRIT, "DBName not in config file"); + exit(1); + } + if(CONFIG_PID_FILE == NULL) + { + CONFIG_PID_FILE=strdup("/tmp/zabbix_trapperd.pid"); + } +} + void process_config_file(void) { FILE *file; @@ -412,6 +446,7 @@ int tcp_listen(const char *host, int port, socklen_t *addrlenp) { int sockfd; struct sockaddr_in serv_addr; + struct linger ling; if ( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) { @@ -419,6 +454,16 @@ int tcp_listen(const char *host, int port, socklen_t *addrlenp) exit(1); } + if(CONFIG_NOTIMEWAIT == 1) + { + ling.l_onoff=1; + ling.l_linger=0; + if(setsockopt(sockfd,SOL_SOCKET,SO_LINGER,&ling,sizeof(ling))==-1) + { + zabbix_log(LOG_LEVEL_WARNING, "Cannot setsockopt SO_LINGER [%s]", strerror(errno)); + } + } + bzero((char *) &serv_addr, sizeof(serv_addr)); serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); @@ -498,7 +543,8 @@ int main() daemon_init(); - process_config_file(); +/* process_config_file(); */ + init_config(); if(CONFIG_LOG_FILE == NULL) { |