/* ** 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 "config.h" #include #include #include #include /* Required for getpwuid */ #include #include #include #include /* getopt() */ #include #include #include #include #include "cfg.h" #include "pid.h" #include "db.h" #include "log.h" #include "zlog.h" #include "common.h" #include "functions.h" #include "expression.h" #include "sysinfo.h" #include "daemon.h" #include "alerter/alerter.h" #include "housekeeper/housekeeper.h" #include "pinger/pinger.h" #include "poller/poller.h" #include "poller/checks_snmp.h" #include "timer/timer.h" #include "trapper/trapper.h" #include "nodewatcher/nodewatcher.h" #include "nodesender/nodesender.h" #define LISTENQ 1024 char *progname = NULL; char title_message[] = "ZABBIX Server (daemon)"; char usage_message[] = "[-hv] [-c ]"; #ifndef HAVE_GETOPT_LONG char *help_message[] = { "Options:", " -c Specify configuration file", " -h give this help", " -v display version number", 0 /* end of text */ }; #else char *help_message[] = { "Options:", " -c --config Specify configuration file", " -h --help give this help", " -v --version display version number", 0 /* end of text */ }; #endif struct option longopts[] = { {"config", 1, 0, 'c'}, {"help", 0, 0, 'h'}, {"version", 0, 0, 'v'}, {0,0,0,0} }; pid_t *threads=NULL; int CONFIG_POLLER_FORKS = POLLER_FORKS; /* For trapper */ int CONFIG_TRAPPERD_FORKS = TRAPPERD_FORKS; int CONFIG_LISTEN_PORT = 10051; int CONFIG_TRAPPER_TIMEOUT = TRAPPER_TIMEOUT; /**/ /*int CONFIG_NOTIMEWAIT =0;*/ int CONFIG_HOUSEKEEPING_FREQUENCY = 1; int CONFIG_SENDER_FREQUENCY = 30; int CONFIG_PINGER_FREQUENCY = 60; int CONFIG_DISABLE_PINGER = 0; int CONFIG_DISABLE_HOUSEKEEPING = 0; int CONFIG_UNREACHABLE_PERIOD = 45; int CONFIG_UNREACHABLE_DELAY = 15; int CONFIG_UNAVAILABLE_DELAY = 60; int CONFIG_LOG_LEVEL = LOG_LEVEL_WARNING; char *CONFIG_ALERT_SCRIPTS_PATH = NULL; char *CONFIG_FPING_LOCATION = NULL; char *CONFIG_DBHOST = NULL; char *CONFIG_DBNAME = NULL; char *CONFIG_DBUSER = NULL; char *CONFIG_DBPASSWORD = NULL; char *CONFIG_DBSOCKET = NULL; int CONFIG_DBPORT = 3306; int CONFIG_ENABLE_REMOTE_COMMANDS = 0; int CONFIG_NODEID = 0; /* From table config */ int CONFIG_REFRESH_UNSUPPORTED = 0; /****************************************************************************** * * * Function: init_config * * * * Purpose: parse config file and update configuration parameters * * * * Parameters: * * * * Return value: * * * * Author: Alexei Vladishev * * * * Comments: will terminate process if parsing fails * * * ******************************************************************************/ void init_config(void) { static struct cfg_line cfg[]= { /* PARAMETER ,VAR ,FUNC, TYPE(0i,1s),MANDATORY,MIN,MAX */ {"StartPollers",&CONFIG_POLLER_FORKS,0,TYPE_INT,PARM_OPT,8,255}, {"HousekeepingFrequency",&CONFIG_HOUSEKEEPING_FREQUENCY,0,TYPE_INT,PARM_OPT,1,24}, {"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}, {"Timeout",&CONFIG_TIMEOUT,0,TYPE_INT,PARM_OPT,1,30}, {"StartTrappers",&CONFIG_TRAPPERD_FORKS,0,TYPE_INT,PARM_OPT,2,255}, {"TrapperTimeout",&CONFIG_TRAPPER_TIMEOUT,0,TYPE_INT,PARM_OPT,1,30}, {"UnreachablePeriod",&CONFIG_UNREACHABLE_PERIOD,0,TYPE_INT,PARM_OPT,1,3600}, {"UnreachableDelay",&CONFIG_UNREACHABLE_DELAY,0,TYPE_INT,PARM_OPT,1,3600}, {"UnavailableDelay",&CONFIG_UNAVAILABLE_DELAY,0,TYPE_INT,PARM_OPT,1,3600}, {"ListenPort",&CONFIG_LISTEN_PORT,0,TYPE_INT,PARM_OPT,1024,32768}, /* {"NoTimeWait",&CONFIG_NOTIMEWAIT,0,TYPE_INT,PARM_OPT,0,1},*/ {"DisablePinger",&CONFIG_DISABLE_PINGER,0,TYPE_INT,PARM_OPT,0,1}, {"DisableHousekeeping",&CONFIG_DISABLE_HOUSEKEEPING,0,TYPE_INT,PARM_OPT,0,1}, {"DebugLevel",&CONFIG_LOG_LEVEL,0,TYPE_INT,PARM_OPT,0,4}, {"PidFile",&APP_PID_FILE,0,TYPE_STRING,PARM_OPT,0,0}, {"LogFile",&CONFIG_LOG_FILE,0,TYPE_STRING,PARM_OPT,0,0}, {"AlertScriptsPath",&CONFIG_ALERT_SCRIPTS_PATH,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}, {"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}, {"DBPort",&CONFIG_DBPORT,0,TYPE_INT,PARM_OPT,1024,65535}, {"NodeID",&CONFIG_NODEID,0,TYPE_INT,PARM_OPT,0,65535}, {0} }; if(CONFIG_FILE == NULL) { CONFIG_FILE=strdup("/etc/zabbix/zabbix_server.conf"); } parse_cfg_file(CONFIG_FILE,cfg); if(CONFIG_DBNAME == NULL) { zabbix_log( LOG_LEVEL_CRIT, "DBName not in config file"); exit(1); } if(APP_PID_FILE == NULL) { APP_PID_FILE=strdup("/tmp/zabbix_server.pid"); } if(CONFIG_ALERT_SCRIPTS_PATH == NULL) { CONFIG_ALERT_SCRIPTS_PATH=strdup("/home/zabbix/bin"); } if(CONFIG_FPING_LOCATION == NULL) { CONFIG_FPING_LOCATION=strdup("/usr/sbin/fping"); } } /* void trend(void) { char sql[MAX_STRING_LEN]; DB_RESULT result; DB_RESULT result2; int i,j; result2 = DBselect("select itemid from items"); for(i=0;i