diff options
author | osmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2005-11-24 13:31:39 +0000 |
---|---|---|
committer | osmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2005-11-24 13:31:39 +0000 |
commit | 2f4787ab7dbef66ea0175dc79aea200d43d8628b (patch) | |
tree | 49d8e38b063889386f7ce44ae80e8d69e0b31374 | |
parent | 70d2cd50abf74c0347875986e2cb53152a0de089 (diff) | |
download | zabbix-2f4787ab7dbef66ea0175dc79aea200d43d8628b.tar.gz zabbix-2f4787ab7dbef66ea0175dc79aea200d43d8628b.tar.xz zabbix-2f4787ab7dbef66ea0175dc79aea200d43d8628b.zip |
- new W32 un/install floppy. (Eugene)
- fixed W32 agent service installation (Eugene)
git-svn-id: svn://svn.zabbix.com/trunk@2354 97f52cf1-0a1b-0410-bd0e-c28be96e8082
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | misc/win32floppy/README | 70 | ||||
-rw-r--r-- | misc/win32floppy/install.bat | 278 | ||||
-rwxr-xr-x | misc/win32floppy/uninstall.bat | 77 | ||||
-rwxr-xr-x | src/zabbix_agent_win32/Debug/ZabbixW32.exe | bin | 360536 -> 360536 bytes | |||
-rwxr-xr-x | src/zabbix_agent_win32/Release/ZabbixW32.exe | bin | 114688 -> 114688 bytes | |||
-rw-r--r-- | src/zabbix_agent_win32/main.cpp | 2 | ||||
-rw-r--r-- | src/zabbix_agent_win32/service.cpp | 52 | ||||
-rw-r--r-- | src/zabbix_agent_win32/sysinfo.cpp | 10 | ||||
-rw-r--r-- | src/zabbix_agent_win32/util.cpp | 52 | ||||
-rw-r--r-- | src/zabbix_agent_win32/zabbixw32.h | 13 |
11 files changed, 445 insertions, 110 deletions
@@ -1,5 +1,6 @@ Changes for 1.1beta3: + - new W32 un/install floppy. (Eugene) - added script for GUI regression testing (Alexei) - reverted multiple server patch (Alexei) - fixed autoregistration (Alexei) diff --git a/misc/win32floppy/README b/misc/win32floppy/README index e03cd6dc..0a31104e 100644 --- a/misc/win32floppy/README +++ b/misc/win32floppy/README @@ -1,13 +1,65 @@ -This are small contribution to Zabbix 1.0 [http://www.zabbix.org] -I thought it could make it more useful. +/* +** 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. +**/ - Fabricio Ferrari, Jan 2004 - Porto Alegre, Brasil - [fabricio@ferrari.pro.br] +SYNOPSIS + install.bat "host name" "server IP" [ "install dir" ] [ "config dir" ] -HOWTO: + uninstall.bat [ "install dir" ] - - format a floppy - - copy install.bat, ZabbixW32.exe, and zabbix_agentd.conf to the floppy +DESCRIPTION + install.bat - installation script, which copy executiable file to + "install dir", create configureation file in "config dir" with + default parameters, install ZABBIX Agent as service and start service. + + uninstall.bat - uninstallation script, which stop ZABBIX Agent service + and remove servise from system. uninstall.bat DON'T remove files, you + must manualy remove all files. + + NOTE: For installation scrip using file 'ZabbixW32.exe' must bee + accessiable from current '.' directory. + For example: You may copy 'install.bat' 'uninstall.bat' and 'ZabbixW32.exe' + in to the one directory and start intallation. + +OPTIONS + "host name" + ZABBIX Agent hostname which be used for active checks. + + "server IP" + ZABBIX Server ip address + + "install dir" + installation directory for bynary files. + Default value is %PROGRAMFILES%/zabbix + + "config dir" + directory for configuration file. + Default value is "install dir" + +USAGE + install.bat localhost 127.0.0.1 c:/zabbix + uninstall.bat c:/zabbix + + install.bat "My Host Name" 192.168.5.1 d:/programs/zabbix_bin d:/programs/zabbix_conf + uninstall.bat d:/programs/zabbix_bin + +AUTHOR + Eugene Grigorjev, Nov 2005 + eugene.grigorjev@zabbix.com + http://www.zabbix.com -Use the floppy to quickly install W32 agent! diff --git a/misc/win32floppy/install.bat b/misc/win32floppy/install.bat index 7ac90840..6a8203cc 100644 --- a/misc/win32floppy/install.bat +++ b/misc/win32floppy/install.bat @@ -1,45 +1,235 @@ @echo off -rem -rem Installs Zabbix in Windows -rem directory c:\zabbix -rem -rem Fabricio Ferrari, jan 2004 -rem fabricio@ferrari.pro.br - -echo. -echo. -echo Installing ZabbixW32 -echo. - -echo Creating directory c:\zabbix ... -mkdir c:\zabbix -echo. - -echo Copying ZabbixW32.exe ... -copy a:\ZabbixW32.exe c:\zabbix -echo. - -echo Copying zabbix_agentd.conf ... -copy a:\zabbix_agentd.conf c:\zabbix -echo. - -echo. -echo Agent configured to server 127.0.0.1 -echo Modify your c:\zabbix\zabbix_agentd.conf to your needs. -echo. - -echo Configuring ZabbixW32 as a system service - -c: -cd zabbix -ZabbixW32.exe --config c:\zabbix\zabbix_agentd.conf install - -echo. -echo Should be working. Verify in the system services! -echo. - -echo. -echo Zabbix [www.zabbix.org] -echo. -echo. -echo. +REM Installation script for Windows ZABBIX Agent +REM Version 1 +REM +REM Written by Eugene Grigorjev, Nov 2005 +REM email: eugene.grigorjev@zabbix.com + +ECHO Installation script for Windows ZABBIX Agent [ http://www.zabbix.com ] +ECHO. +ECHO Welcome to ZABBIX Agent installation! +ECHO. + +SET srcbindir=. +SET config_name=zabbix_agentd.conf +SET log_name=zabbix_agentd.log +SET pid_name=zabbix_agentd.pid +SET zabbix_agent=ZabbixW32.exe + +SET def_install_dir=%PROGRAMFILES%/zabbix +SET def_config_dir=%def_install_dir% + +SET Configfile=%def_config_dir%/%config_name% + +if "%1"=="" GOTO Err_param +if "%2"=="" GOTO Err_param + +:Install + +REM default active parameters + +SET Hostname=%1 +SET serverip=%2 +SET serverport=10051 +SET listenport=10050 +SET startagents=5 +SET debuglevel=3 +SET timeout=3 + +REM default hidden parameters, to enable this parameters +REM You can remove '#' symbol from line with this +REM parameters to enable it. + +SET listenip=127.0.0.1 +SET refAC=120 +SET disableAC=1 +SET notimewait=1 + +REM Check parameters and create needed direcoryes. + +IF NOT "%3"=="" SET install_dir=%3 +IF "%3"=="" SET install_dir=%def_install_dir% +IF NOT EXIST "%install_dir%" MKDIR "%install_dir%" +IF NOT EXIST "%install_dir%" GOTO Err_install_dir + +IF NOT "%4"=="" SET config_dir=%4 +IF "%4"=="" SET config_dir=%install_dir% +IF NOT EXIST "%config_dir%" MKDIR "%config_dir%" +IF NOT EXIST "%config_dir%" GOTO Err_config_dir + +SET logfile=%install_dir%/%log_name% +SET pidfile=%install_dir%/%pid_name% + +SET Configfile=%config_dir%/%config_name% + +ECHO Creating ZABBIX Agent configuration file "%Configfile%" + +REM ============================================================================= +REM =================== START OF CONFIGURATION FILE ============================= +REM ============================================================================= +ECHO # This is config file for zabbix_agentd > "%Configfile%" +ECHO # To get more information about ZABBIX, go http://www.zabbix.com >> "%Configfile%" +ECHO. >> "%Configfile%" +ECHO ############ GENERAL PARAMETERS ################# >> "%Configfile%" +ECHO. >> "%Configfile%" +ECHO # List of comma delimited IP addresses (or hostnames) of ZABBIX Servers. >> "%Configfile%" +ECHO # No spaces allowed. First entry is used for sending active checks. >> "%Configfile%" +ECHO # Note that hostnames must resolve hostname - IP address and >> "%Configfile%" +ECHO # IP address - hostname. >> "%Configfile%" +ECHO. >> "%Configfile%" +ECHO Server=%serverip% >> "%Configfile%" +ECHO. >> "%Configfile%" +ECHO # Server port for sending active checks >> "%Configfile%" +ECHO. >> "%Configfile%" +ECHO ServerPort=%serverport% >> "%Configfile%" +ECHO. >> "%Configfile%" +ECHO # Unique hostname. Required for active checks. >> "%Configfile%" +ECHO. >> "%Configfile%" +ECHO Hostname=%Hostname% >> "%Configfile%" +ECHO. >> "%Configfile%" +ECHO # Listen port. Default is 10050 >> "%Configfile%" +ECHO. >> "%Configfile%" +ECHO ListenPort=%listenport%>> "%Configfile%" +ECHO. >> "%Configfile%" +ECHO # IP address to bind agent >> "%Configfile%" +ECHO # If missing, bind to all available IPs >> "%Configfile%" +ECHO. >> "%Configfile%" +ECHO #ListenIP=%listenip%>> "%Configfile%" +ECHO. >> "%Configfile%" +ECHO # Number of pre-forked instances of zabbix_agentd. >> "%Configfile%" +ECHO # Default value is 5 >> "%Configfile%" +ECHO # This parameter must be between 1 and 16 >> "%Configfile%" +ECHO. >> "%Configfile%" +ECHO StartAgents=%startagents% >> "%Configfile%" +ECHO. >> "%Configfile%" +ECHO # How often refresh list of active checks. 2 minutes by default. >> "%Configfile%" +ECHO. >> "%Configfile%" +ECHO #RefreshActiveChecks=%refAC% >> "%Configfile%" +ECHO. >> "%Configfile%" +ECHO # Disable active checks. The agent will work in passive mode listening server. >> "%Configfile%" +ECHO. >> "%Configfile%" +ECHO #DisableActive=%disableAC% >> "%Configfile%" +ECHO. >> "%Configfile%" +ECHO # Specifies debug level >> "%Configfile%" +ECHO # 0 - debug is not created >> "%Configfile%" +ECHO # 1 - critical information >> "%Configfile%" +ECHO # 2 - error information >> "%Configfile%" +ECHO # 3 - warnings (default) >> "%Configfile%" +ECHO # 4 - for debugging (produces lots of information) >> "%Configfile%" +ECHO. >> "%Configfile%" +ECHO DebugLevel=%debuglevel% >> "%Configfile%" +ECHO. >> "%Configfile%" +ECHO # Name of PID file >> "%Configfile%" +ECHO. >> "%Configfile%" +ECHO #PidFile=%pidfile%>> "%Configfile%" +ECHO. >> "%Configfile%" +ECHO # Name of log file. >> "%Configfile%" +ECHO # If not set, syslog will be used >> "%Configfile%" +ECHO. >> "%Configfile%" +ECHO LogFile=%logfile% >> "%Configfile%" +ECHO. >> "%Configfile%" +ECHO # Spend no more than Timeout seconds on processing >> "%Configfile%" +ECHO # Must be between 1 and 30 >> "%Configfile%" +ECHO. >> "%Configfile%" +ECHO Timeout=%timeout% >> "%Configfile%" +ECHO. >> "%Configfile%" +ECHO ##### Experimental options. Use with care ! ##### >> "%Configfile%" +ECHO. >> "%Configfile%" +ECHO # Get rid of sockets in TIME_WAIT state >> "%Configfile%" +ECHO # This will set socket option SO_LINGER >> "%Configfile%" +ECHO. >> "%Configfile%" +ECHO # NoTimeWait=%notimewait% >> "%Configfile%" +ECHO. >> "%Configfile%" +ECHO ##### End of experimental options >> "%Configfile%" +ECHO. >> "%Configfile%" +ECHO ####### USER-DEFINED MONITORED PARAMETERS ####### >> "%Configfile%" +ECHO # Format: "UserParameter='key','shell command'" >> "%Configfile%" +ECHO # Note that shell command must not return empty string or EOL only >> "%Configfile%" +ECHO. >> "%Configfile%" +ECHO UserParameter=mysql.version,mysql -V >> "%Configfile%" +REM ============================================================================= +REM ==================== END OF CONFIGURATION FILE ============================== +REM ============================================================================= + +ECHO Installing ZABBIX Agent files... + +COPY "%srcbindir%/%zabbix_agent%" "%install_dir%/%zabbix_agent%" > NULL +IF ERRORLEVEL 1 GOTO Err_copy + +ECHO Creating ZABBIX Agent srvice... + +CALL "%install_dir%/%zabbix_agent%" --config "%Configfile%" install +IF ERRORLEVEL 1 GOTO Err_install + +ECHO Starting ZABBIX Agent srvice... + +CALL "%install_dir%/%zabbix_agent%" start +IF ERRORLEVEL 1 GOTO Err_start + +ECHO. +ECHO ############################################################# +ECHO Congratulations! +ECHO ZABBIX agent for Windows successfuly instaled on Your PC! +ECHO. +ECHO Installation directory: %install_dir% +ECHO Configureation file: %Configfile% +ECHO. +ECHO ZABBIX agent have next configuration: +ECHO Agent hostname for ZABBIX Server: %Hostname% +ECHO ZABBIX Server IP: %serverip% +ECHO ZABBIX Server port: %serverport% +ECHO ZABBIX Agent listen port: %listenport% +ECHO Connection timeout: %timeout% +ECHO Start Agent count: %startagents% +ECHO Debug level: %debuglevel% +ECHO Log file: %logfile% +ECHO. +ECHO IF You want change configurations or more detailed configure +ECHO ZABBIX Agent, you can manualy change configureation file and +ECHO restart ZABBIX Agent service. +ECHO. +ECHO Now You can configure ZABBIX Server to monitore this PC. +ECHO. +ECHO Thank You for using ZABBIX software. +ECHO http://www.zabbix.com +ECHO ############################################################# +ECHO. + +GOTO End + +:Err_param +ECHO INSTALL ERROR: Please use script with required parameters! +GOTO Syntax + +:Err_start +ECHO INSTALL ERROR: Can't start ZABBIX Agent service! +GOTO Syntax + +:Err_install +ECHO INSTALL ERROR: Can't install ZABBIX Agent as service! +GOTO Syntax + +:Err_copy +ECHO INSTALL ERROR: Can't copy file "%srcbindir%.%zabbix_agent%" in to "%install_dir%"! +GOTO Syntax + +:Err_install_dir +ECHO INSTALL ERROR: Can't create installation directory "%install_dir%"! +GOTO Syntax + +:Err_config_dir +ECHO INSTALL ERROR: Can't create directory "%config_dir%" for configuretion file! +GOTO Syntax + +:Syntax +ECHO. +ECHO ------------------------------------------------------------- +ECHO Usage: +ECHO %0 "hostname" "srver ip" ["install path]" ["config file dir"] +ECHO. +ECHO Default installation path is "%def_install_dir%" +ECHO Default configureation file is "%Configfile%" +ECHO ------------------------------------------------------------- + +:End +@echo on diff --git a/misc/win32floppy/uninstall.bat b/misc/win32floppy/uninstall.bat new file mode 100755 index 00000000..b64ba750 --- /dev/null +++ b/misc/win32floppy/uninstall.bat @@ -0,0 +1,77 @@ +@echo off +REM Uninstallation script for Windows ZABBIX Agent +REM Version 1 +REM +REM Written by Eugene Grigorjev, Nov 2005 +REM email: eugene.grigorjev@zabbix.com + +ECHO Uninstallation script for Windows ZABBIX Agent [ http://www.zabbix.com ] +ECHO. +ECHO Welcome to ZABBIX Agent uninstallation! +ECHO. + +SET def_install_dir=%PROGRAMFILES%/zabbix + +IF "%1"=="help" GOTO Syntax +IF "%1"=="/help" GOTO Syntax +IF "%1"=="--help" GOTO Syntax +IF "%1"=="-help" GOTO Syntax +IF "%1"=="-h" GOTO Syntax +IF "%1"=="/h" GOTO Syntax + +IF NOT "%1"=="" SET install_dir=%1 +IF "%1"=="" SET install_dir=%def_install_dir% + +IF NOT EXIST "%install_dir%" GOTO Err_path + +SET zabbix_agent=%install_dir%/ZabbixW32.exe +IF NOT EXIST "%zabbix_agent%" GOTO Err_agent + +ECHO Stoping ZABBIX Agent srvice... + +CALL "%zabbix_agent%" stop +IF ERRORLEVEL 1 ECHO UNINSTALL WARNING: Can't stop ZABBIX Agent service! + +ECHO Removing ZABBIX Agent srvice... + +CALL "%zabbix_agent%" remove +IF ERRORLEVEL 1 GOTO Err_remove + +ECHO. +ECHO ############################################################# +ECHO. +ECHO ZABBIX agent for Windows successfuly uninstaled from Your PC. +ECHO. +ECHO Now you can remove: +ECHO ZABBIX Agent binary file +ECHO ZABBIX Agent log file (see config file) +ECHO ZABBIX Agent config file +ECHO. +ECHO http://www.zabbix.com +ECHO. +ECHO ############################################################# +ECHO. + +GOTO End + +:Err_agent +ECHO UNINSTAL ERROR: Can't find ZABBIX Agent binary file 'ZabbixW32.exe'! +:Err_path +ECHO UNINSTAL ERROR: Please set the correct installation directory! +GOTO Syntax + +:Err_remove +ECHO UNINSTALL ERROR: Can't remove ZABBIX Agent service"! +GOTO Syntax + +:Syntax +ECHO. +ECHO ------------------------------------------------------------- +ECHO Usage: +ECHO %0 ["install path]" +ECHO. +ECHO Default installation path is "%def_install_dir%" +ECHO ------------------------------------------------------------- + +:End +@echo on diff --git a/src/zabbix_agent_win32/Debug/ZabbixW32.exe b/src/zabbix_agent_win32/Debug/ZabbixW32.exe Binary files differindex 46b8bc04..9a0a34b2 100755 --- a/src/zabbix_agent_win32/Debug/ZabbixW32.exe +++ b/src/zabbix_agent_win32/Debug/ZabbixW32.exe diff --git a/src/zabbix_agent_win32/Release/ZabbixW32.exe b/src/zabbix_agent_win32/Release/ZabbixW32.exe Binary files differindex 69b0b875..76387eec 100755 --- a/src/zabbix_agent_win32/Release/ZabbixW32.exe +++ b/src/zabbix_agent_win32/Release/ZabbixW32.exe diff --git a/src/zabbix_agent_win32/main.cpp b/src/zabbix_agent_win32/main.cpp index fb539e2a..af36a4a3 100644 --- a/src/zabbix_agent_win32/main.cpp +++ b/src/zabbix_agent_win32/main.cpp @@ -263,7 +263,7 @@ void Main(void) int ch; printf("\n*** Zabbix Win32 agent operational. Press ESC to terminate. ***\n"); - while(1) + for(;;) { ch=getch(); if (ch==0) diff --git a/src/zabbix_agent_win32/service.cpp b/src/zabbix_agent_win32/service.cpp index bdceb2f6..0e19b10a 100644 --- a/src/zabbix_agent_win32/service.cpp +++ b/src/zabbix_agent_win32/service.cpp @@ -132,10 +132,11 @@ CHECK_MEMORY(main,"InitService","end"); // Create service // -void ZabbixCreateService(char *execName) +int ZabbixCreateService(char *execName) { SC_HANDLE mgr,service; char cmdLine[MAX_PATH*2]; + int ret = 0; INIT_CHECK_MEMORY(main); @@ -143,7 +144,7 @@ INIT_CHECK_MEMORY(main); if (mgr==NULL) { printf("ERROR: Cannot connect to Service Manager (%s)\n",GetSystemErrorText(GetLastError())); - return; + return 1; } sprintf(cmdLine,"\"%s\" --config \"%s\"",execName,confFile); @@ -157,6 +158,7 @@ INIT_CHECK_MEMORY(main); printf("ERROR: Service named '" ZABBIX_SERVICE_NAME "' already exist\n"); else printf("ERROR: Cannot create service (%s)\n",GetSystemErrorText(code)); + ret = 1; } else { @@ -166,9 +168,11 @@ INIT_CHECK_MEMORY(main); CloseServiceHandle(mgr); - ZabbixInstallEventSource(execName); + if(ret == 0) + ret = ZabbixInstallEventSource(execName); CHECK_MEMORY(main,"ZabbixCreateService","end"); + return ret; } @@ -176,9 +180,10 @@ CHECK_MEMORY(main,"ZabbixCreateService","end"); // Remove service // -void ZabbixRemoveService(void) +int ZabbixRemoveService(void) { SC_HANDLE mgr,service; + int ret = 0; INIT_CHECK_MEMORY(main); @@ -187,7 +192,7 @@ INIT_CHECK_MEMORY(main); { printf("ERROR: Cannot connect to Service Manager (%s)\n",GetSystemErrorText(GetLastError())); CHECK_MEMORY(main,"ZabbixCreateService","OpenSCManager"); - return; + return 1; } service=OpenService(mgr,ZABBIX_SERVICE_NAME,DELETE); @@ -195,23 +200,29 @@ CHECK_MEMORY(main,"ZabbixCreateService","OpenSCManager"); { printf("ERROR: Cannot open service named '" ZABBIX_SERVICE_NAME "' (%s)\n", GetSystemErrorText(GetLastError())); + ret = 1; } else { if (DeleteService(service)) printf("Zabbix Win32 Agent service deleted successfully\n"); else + { printf("ERROR: Cannot remove service named '" ZABBIX_SERVICE_NAME "' (%s)\n", GetSystemErrorText(GetLastError())); + ret = 1; + } CloseServiceHandle(service); } CloseServiceHandle(mgr); - ZabbixRemoveEventSource(); + if(ret == 0) + ret = ZabbixRemoveEventSource(); CHECK_MEMORY(main,"ZabbixCreateService","end"); + return ret; } @@ -219,9 +230,10 @@ CHECK_MEMORY(main,"ZabbixCreateService","end"); // Start service // -void ZabbixStartService(void) +int ZabbixStartService(void) { SC_HANDLE mgr,service; + int ret = 0; INIT_CHECK_MEMORY(main); @@ -230,7 +242,7 @@ INIT_CHECK_MEMORY(main); { printf("ERROR: Cannot connect to Service Manager (%s)\n",GetSystemErrorText(GetLastError())); CHECK_MEMORY(main,"ZabbixStartService","OpenSCManager"); - return; + return 1; } service=OpenService(mgr,ZABBIX_SERVICE_NAME,SERVICE_START); @@ -238,20 +250,25 @@ CHECK_MEMORY(main,"ZabbixStartService","OpenSCManager"); { printf("ERROR: Cannot open service named '" ZABBIX_SERVICE_NAME "' (%s)\n", GetSystemErrorText(GetLastError())); + ret=1; } else { if (StartService(service,0,NULL)) printf("Zabbix Win32 Agent service started successfully\n"); else + { printf("ERROR: Cannot start service named '" ZABBIX_SERVICE_NAME "' (%s)\n", GetSystemErrorText(GetLastError())); + ret = 1; + } CloseServiceHandle(service); } CloseServiceHandle(mgr); CHECK_MEMORY(main,"ZabbixStartService","end"); + return ret; } @@ -259,9 +276,10 @@ CHECK_MEMORY(main,"ZabbixStartService","end"); // Stop service // -void ZabbixStopService(void) +int ZabbixStopService(void) { SC_HANDLE mgr,service; + int ret = 0; INIT_CHECK_MEMORY(main); @@ -270,7 +288,7 @@ INIT_CHECK_MEMORY(main); { printf("ERROR: Cannot connect to Service Manager (%s)\n",GetSystemErrorText(GetLastError())); CHECK_MEMORY(main,"ZabbixStopService","OpenSCManager"); - return; + return 1; } service=OpenService(mgr,ZABBIX_SERVICE_NAME,SERVICE_STOP); @@ -278,6 +296,7 @@ CHECK_MEMORY(main,"ZabbixStopService","OpenSCManager"); { printf("ERROR: Cannot open service named '" ZABBIX_SERVICE_NAME "' (%s)\n", GetSystemErrorText(GetLastError())); + ret = 1; } else { @@ -286,14 +305,18 @@ CHECK_MEMORY(main,"ZabbixStopService","OpenSCManager"); if (ControlService(service,SERVICE_CONTROL_STOP,&status)) printf("Zabbix Win32 Agent service stopped successfully\n"); else + { printf("ERROR: Cannot stop service named '" ZABBIX_SERVICE_NAME "' (%s)\n", GetSystemErrorText(GetLastError())); + ret = 1; + } CloseServiceHandle(service); } CloseServiceHandle(mgr); CHECK_MEMORY(main,"ZabbixStopService","end"); + return ret; } @@ -301,7 +324,7 @@ CHECK_MEMORY(main,"ZabbixStopService","end"); // Install event source // -void ZabbixInstallEventSource(char *path) +int ZabbixInstallEventSource(char *path) { HKEY hKey; DWORD dwTypes=EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE; @@ -314,7 +337,7 @@ INIT_CHECK_MEMORY(main); { printf("Unable to create registry key: %s\n",GetSystemErrorText(GetLastError())); CHECK_MEMORY(main,"ZabbixInstallEventSource","RegCreateKeyEx"); - return; + return 1; } RegSetValueEx(hKey,"TypesSupported",0,REG_DWORD,(BYTE *)&dwTypes,sizeof(DWORD)); @@ -324,6 +347,7 @@ CHECK_MEMORY(main,"ZabbixInstallEventSource","RegCreateKeyEx"); printf("Event source \"" ZABBIX_EVENT_SOURCE "\" installed successfully\n"); CHECK_MEMORY(main,"ZabbixInstallEventSource","end"); + return 0; } @@ -331,7 +355,7 @@ CHECK_MEMORY(main,"ZabbixInstallEventSource","end"); // Remove event source // -void ZabbixRemoveEventSource(void) +int ZabbixRemoveEventSource(void) { INIT_CHECK_MEMORY(main); @@ -345,6 +369,8 @@ INIT_CHECK_MEMORY(main); { printf("Unable to uninstall event source \"" ZABBIX_EVENT_SOURCE "\": %s\n", GetSystemErrorText(GetLastError())); + return 1; } CHECK_MEMORY(main,"ZabbixRemoveEventSource","end"); + return 0; } diff --git a/src/zabbix_agent_win32/sysinfo.cpp b/src/zabbix_agent_win32/sysinfo.cpp index ef979d4a..f935c03b 100644 --- a/src/zabbix_agent_win32/sysinfo.cpp +++ b/src/zabbix_agent_win32/sysinfo.cpp @@ -437,11 +437,11 @@ static LONG H_UserCounter(char *cmd,char *arg,double *value) static LONG H_MD5Hash(char *cmd,char *arg,char **value) { - char fileName[MAX_PATH],hashText[MD5_DIGEST_SIZE*2+1]; - unsigned char *data,hash[MD5_DIGEST_SIZE]; - HANDLE hFile,hFileMapping; - DWORD dwSize,dwSizeHigh; - int i; + char fileName[MAX_PATH], hashText[MD5_DIGEST_SIZE*2+1]; + unsigned char *data=NULL, hash[MD5_DIGEST_SIZE]; + HANDLE hFile=NULL,hFileMapping=NULL; + DWORD dwSize=0, dwSizeHigh=0; + int i=0; diff --git a/src/zabbix_agent_win32/util.cpp b/src/zabbix_agent_win32/util.cpp index 241cc530..56bd01fe 100644 --- a/src/zabbix_agent_win32/util.cpp +++ b/src/zabbix_agent_win32/util.cpp @@ -45,7 +45,7 @@ static void Help(void) " version : Display version information\n\n" "And possible options are:\n" " --config <file> : Specify alternate configuration file\n" - " (default is C:\\zabbix_agentd.conf)\n\n"); + " (default is %s)\n\n", confFile); } @@ -56,10 +56,11 @@ static void Help(void) // FALSE otherwise // -BOOL ParseCommandLine(int argc,char *argv[]) +int ParseCommandLine(int argc,char *argv[]) { int i; - BOOL ret = TRUE; + int ret = TRUE; + char path[MAX_PATH]; INIT_CHECK_MEMORY(main); @@ -68,13 +69,13 @@ INIT_CHECK_MEMORY(main); if (!strcmp(argv[i],"help")) // Display help and exit { Help(); - ret = FALSE; + exit(0); goto lbl_end; } else if (!strcmp(argv[i],"version")) // Display version and exit { printf("Zabbix Win32 Agent Version " AGENT_VERSION " Build of " __DATE__ "\n"); - ret = FALSE; + exit(0); goto lbl_end; } else if (!strcmp(argv[i],"--config")) // Config file @@ -91,63 +92,52 @@ INIT_CHECK_MEMORY(main); else if ((!strcmp(argv[i],"install"))|| (!strcmp(argv[i],"install-events"))) { - char path[MAX_PATH],*ptr; - - ptr=strrchr(argv[0],'\\'); - if (ptr!=NULL) - ptr++; - else - ptr=argv[0]; - - _fullpath(path,ptr,255); - - if (stricmp(&path[strlen(path)-4],".exe")) - strcat(path,".exe"); + _fullpath(path,argv[0],MAX_PATH); if (!strcmp(argv[i],"install")) - ZabbixCreateService(path); + ret = ZabbixCreateService(path); else - ZabbixInstallEventSource(path); - ret = FALSE; + ret = ZabbixInstallEventSource(path); + exit(ret); goto lbl_end; } else if (!strcmp(argv[i],"remove")) { - ZabbixRemoveService(); - ret = FALSE; + ret = ZabbixRemoveService(); + exit(ret); goto lbl_end; } else if (!strcmp(argv[i],"remove-events")) { - ZabbixRemoveEventSource(); - ret = FALSE; + ret = ZabbixRemoveEventSource(); + exit(ret); goto lbl_end; } else if (!strcmp(argv[i],"start")) { - ZabbixStartService(); - ret = FALSE; + ret = ZabbixStartService(); + exit(ret); goto lbl_end; } else if (!strcmp(argv[i],"stop")) { - ZabbixStopService(); - ret = FALSE; + ret = ZabbixStopService(); + exit(ret); goto lbl_end; } else if (!strcmp(argv[i],"check-config")) { dwFlags|=AF_STANDALONE; printf("Checking configuration file:\n\n"); - ReadConfig(); - ret = FALSE; + ret = ReadConfig(); + exit(ret); goto lbl_end; } else { printf("ERROR: Invalid command line argument\n\n"); Help(); - ret = FALSE; + exit(1); goto lbl_end; } } diff --git a/src/zabbix_agent_win32/zabbixw32.h b/src/zabbix_agent_win32/zabbixw32.h index 2d4bde9f..54f559f2 100644 --- a/src/zabbix_agent_win32/zabbixw32.h +++ b/src/zabbix_agent_win32/zabbixw32.h @@ -81,7 +81,6 @@ #define IsStandalone() (dwFlags & AF_STANDALONE) - // // Parameter definition structure // @@ -182,13 +181,13 @@ void CalculateMD5Hash(const unsigned char *data,int nbytes,unsigned char *hash); DWORD CalculateCRC32(const unsigned char *data,DWORD nbytes); void InitService(void); -void ZabbixCreateService(char *execName); -void ZabbixRemoveService(void); -void ZabbixStartService(void); -void ZabbixStopService(void); +int ZabbixCreateService(char *execName); +int ZabbixRemoveService(void); +int ZabbixStartService(void); +int ZabbixStopService(void); -void ZabbixInstallEventSource(char *path); -void ZabbixRemoveEventSource(void); +int ZabbixInstallEventSource(char *path); +int ZabbixRemoveEventSource(void); char *GetCounterName(DWORD index); |