summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorsasha <sasha@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2008-01-02 12:33:05 +0000
committersasha <sasha@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2008-01-02 12:33:05 +0000
commit47dd5d05f5a65efb65c9c674d23eb6aa88aaa42e (patch)
tree0854bf902030cea22a6de25c8a1e61180448c762 /src
parent214f5afd22f1f8cb4cc15532f48710730ade2316 (diff)
- [DEV-92] added supprt of multiple windows agents, service description
[svn merge svn://svn.zabbix.com/branches/1.4.j -r5208:5211] git-svn-id: svn://svn.zabbix.com/trunk@5212 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src')
-rw-r--r--src/libs/zbxcommon/comms.c5
-rw-r--r--src/libs/zbxwin32/service.c67
-rw-r--r--src/zabbix_agent/zabbix_agentd.c99
3 files changed, 100 insertions, 71 deletions
diff --git a/src/libs/zbxcommon/comms.c b/src/libs/zbxcommon/comms.c
index bc7f9bac..8156e718 100644
--- a/src/libs/zbxcommon/comms.c
+++ b/src/libs/zbxcommon/comms.c
@@ -21,6 +21,11 @@
#include "log.h"
#include "base64.h"
+#if defined (_WINDOWS)
+char ZABBIX_SERVICE_NAME[64] = {APPLICATION_NAME};
+char ZABBIX_EVENT_SOURCE[64] = {APPLICATION_NAME};
+#endif /* _WINDOWS */
+
/******************************************************************************
* *
* Function: comms_create_request *
diff --git a/src/libs/zbxwin32/service.c b/src/libs/zbxwin32/service.c
index 86ba2c2a..7a868394 100644
--- a/src/libs/zbxwin32/service.c
+++ b/src/libs/zbxwin32/service.c
@@ -163,11 +163,13 @@ int ZabbixCreateService(char *path)
{
#define MAX_CMD_LEN MAX_PATH*2
- SC_HANDLE mgr,service;
- char execName[MAX_PATH];
- char configFile[MAX_PATH];
- char cmdLine[MAX_CMD_LEN];
- int ret = SUCCEED;
+ SC_HANDLE mgr,service;
+ SERVICE_DESCRIPTION sd;
+ LPTSTR szDesc = TEXT("Provides system monitoring");
+ char execName[MAX_PATH];
+ char configFile[MAX_PATH];
+ char cmdLine[MAX_CMD_LEN];
+ int ret = SUCCEED;
_fullpath(execName, path, MAX_PATH);
@@ -206,20 +208,26 @@ int ZabbixCreateService(char *path)
if (ERROR_SERVICE_EXISTS == code)
{
- zbx_error("ERROR: Service named '" ZABBIX_SERVICE_NAME "' already exist");
+ zbx_error("ERROR: Service named '%s' already exist", ZABBIX_SERVICE_NAME);
}
else
{
- zbx_error("ERROR: Cannot create service [%s]",strerror_from_system(code));
+ zbx_error("ERROR: Cannot create service named '%s' [%s]", ZABBIX_SERVICE_NAME, strerror_from_system(code));
}
ret = FAIL;
}
else
{
- zbx_error(ZABBIX_SERVICE_NAME " service created successfully.");
+ zbx_error("Service \"%s\" installed successfully.", ZABBIX_SERVICE_NAME);
+ CloseServiceHandle(service);
+
+ /* Updates the service description */
+ service = OpenService(mgr, ZABBIX_SERVICE_NAME, SERVICE_CHANGE_CONFIG);
+ sd.lpDescription = szDesc;
+ if (0 == ChangeServiceConfig2(service, SERVICE_CONFIG_DESCRIPTION, &sd))
+ zbx_error("Service description update failed. %x", GetLastError());
CloseServiceHandle(service);
}
-
CloseServiceHandle(mgr);
if(ret != SUCCEED)
@@ -250,18 +258,18 @@ int ZabbixRemoveService(void)
service=OpenService(mgr,ZABBIX_SERVICE_NAME,DELETE);
if (service==NULL)
{
- zbx_error("ERROR: Cannot open service named '" ZABBIX_SERVICE_NAME "' [%s]", strerror_from_system(GetLastError()));
+ zbx_error("ERROR: Cannot open service named '%s' [%s]", ZABBIX_SERVICE_NAME, strerror_from_system(GetLastError()));
ret = FAIL;
}
else
{
if (DeleteService(service))
{
- zbx_error(ZABBIX_EVENT_SOURCE " service deleted successfully");
+ zbx_error("Service \"%s\" uninstalled successfully", ZABBIX_SERVICE_NAME);
}
else
{
- zbx_error("ERROR: Cannot remove service named '" ZABBIX_SERVICE_NAME "' [%s]", strerror_from_system(GetLastError()));
+ zbx_error("ERROR: Cannot remove service named '%s' [%s]", ZABBIX_SERVICE_NAME, strerror_from_system(GetLastError()));
ret = FAIL;
}
@@ -300,18 +308,18 @@ int ZabbixStartService(void)
if (service==NULL)
{
- zbx_error("ERROR: Cannot open service named '" ZABBIX_SERVICE_NAME "' [%s]", strerror_from_system(GetLastError()));
+ zbx_error("ERROR: Cannot open service named '%s' [%s]", ZABBIX_SERVICE_NAME, strerror_from_system(GetLastError()));
ret = FAIL;
}
else
{
if (StartService(service,0,NULL))
{
- zbx_error(ZABBIX_SERVICE_NAME " service started successfully.");
+ zbx_error("Service \"%s\" started successfully.", ZABBIX_SERVICE_NAME);
}
else
{
- zbx_error("ERROR: Cannot start service named '" ZABBIX_SERVICE_NAME "' [%s]", strerror_from_system(GetLastError()));
+ zbx_error("ERROR: Cannot start service named '%s' [%s]", ZABBIX_SERVICE_NAME, strerror_from_system(GetLastError()));
ret = FAIL;
}
@@ -342,7 +350,7 @@ int ZabbixStopService(void)
service=OpenService(mgr,ZABBIX_SERVICE_NAME,SERVICE_STOP);
if (service==NULL)
{
- zbx_error("ERROR: Cannot open service named '" ZABBIX_SERVICE_NAME "' [%s]", strerror_from_system(GetLastError()));
+ zbx_error("ERROR: Cannot open service named '%s' [%s]", ZABBIX_SERVICE_NAME, strerror_from_system(GetLastError()));
ret = FAIL;
}
else
@@ -351,11 +359,11 @@ int ZabbixStopService(void)
if (ControlService(service,SERVICE_CONTROL_STOP,&status))
{
- zbx_error(ZABBIX_SERVICE_NAME " service stopped successfully.");
+ zbx_error("Service \"%s\" stopped successfully.", ZABBIX_SERVICE_NAME);
}
else
{
- zbx_error("ERROR: Cannot stop service named '" ZABBIX_SERVICE_NAME "' [%s]", strerror_from_system(GetLastError()));
+ zbx_error("ERROR: Cannot stop service named '%s' [%s]", ZABBIX_SERVICE_NAME, strerror_from_system(GetLastError()));
ret = FAIL;
}
@@ -372,14 +380,17 @@ int ZabbixStopService(void)
*/
static int ZabbixInstallEventSource(char *path)
{
- HKEY hKey;
- DWORD dwTypes = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE;
- char execName[MAX_PATH];
+ HKEY hKey;
+ DWORD dwTypes = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE;
+ char execName[MAX_PATH];
+ char regkey[MAX_STRING_LEN];
_fullpath(execName, path, MAX_PATH);
+ zbx_snprintf(regkey, sizeof(regkey), "System\\CurrentControlSet\\Services\\EventLog\\System\\%s", ZABBIX_EVENT_SOURCE);
+
if (ERROR_SUCCESS != RegCreateKeyEx(HKEY_LOCAL_MACHINE,
- "System\\CurrentControlSet\\Services\\EventLog\\System\\" ZABBIX_EVENT_SOURCE,
+ regkey,
0,
NULL,
REG_OPTION_NON_VOLATILE,
@@ -396,7 +407,7 @@ static int ZabbixInstallEventSource(char *path)
RegSetValueEx(hKey,"EventMessageFile",0,REG_EXPAND_SZ,(BYTE *)execName,(DWORD)strlen(execName)+1);
RegCloseKey(hKey);
- zbx_error("Event source \"" ZABBIX_EVENT_SOURCE "\" installed successfully.");
+ zbx_error("Event source \"%s\" installed successfully.", ZABBIX_EVENT_SOURCE);
return SUCCEED;
}
@@ -408,15 +419,17 @@ static int ZabbixInstallEventSource(char *path)
static int ZabbixRemoveEventSource(void)
{
+ char regkey[MAX_STRING_LEN];
+
+ zbx_snprintf(regkey, sizeof(regkey), "System\\CurrentControlSet\\Services\\EventLog\\System\\%s", ZABBIX_EVENT_SOURCE);
- if (ERROR_SUCCESS == RegDeleteKey(HKEY_LOCAL_MACHINE,
- "System\\CurrentControlSet\\Services\\EventLog\\System\\" ZABBIX_EVENT_SOURCE))
+ if (ERROR_SUCCESS == RegDeleteKey(HKEY_LOCAL_MACHINE, regkey))
{
- zbx_error("Event source \"" ZABBIX_EVENT_SOURCE "\" uninstalled successfully.");
+ zbx_error("Event source \"%s\" uninstalled successfully.", ZABBIX_EVENT_SOURCE);
}
else
{
- zbx_error("Unable to uninstall event source \"" ZABBIX_EVENT_SOURCE "\": [%s]", strerror_from_system(GetLastError()));
+ zbx_error("Unable to uninstall event source \"%s\": [%s]", ZABBIX_EVENT_SOURCE, strerror_from_system(GetLastError()));
return FAIL;
}
diff --git a/src/zabbix_agent/zabbix_agentd.c b/src/zabbix_agent/zabbix_agentd.c
index cbb1b63a..0ee8b88b 100644
--- a/src/zabbix_agent/zabbix_agentd.c
+++ b/src/zabbix_agent/zabbix_agentd.c
@@ -75,7 +75,7 @@ char title_message[] = APPLICATION_NAME
char usage_message[] =
"[-Vhp]"
#if defined(_WINDOWS)
- " [-idsx]"
+ " [-idsx] [-m]"
#endif /* _WINDOWS */
" [-c <file>] [-t <metric>]";
@@ -88,11 +88,11 @@ char usage_message[] =
char *help_message[] = {
"Options:",
"",
- " -c --config <file> Specify configuration file",
- " -h --help give this help",
- " -V --version display version number",
- " -p --print print supported metrics and exit",
- " -t --test <metric> test specified metric and exit",
+ " -c --config <file> Specify configuration file",
+ " -h --help give this help",
+ " -V --version display version number",
+ " -p --print print supported metrics and exit",
+ " -t --test <metric> test specified metric and exit",
/* " -u --usage <metric> test specified metric and exit", */ /* !!! TODO - print metric usage !!! */
#if defined (_WINDOWS)
@@ -100,11 +100,13 @@ char *help_message[] = {
"",
"Functions:",
"",
- " -i --install install ZABIX agent as service",
- " -d --uninstall uninstall ZABIX agent from service",
-
- " -s --start start ZABIX agent service",
- " -x --stop stop ZABIX agent service",
+ " -i --install install ZABBIX agent as service",
+ " -d --uninstall uninstall ZABBIX agent from service",
+
+ " -s --start start ZABBIX agent service",
+ " -x --stop stop ZABBIX agent service",
+
+ " -m --multiple-agents service name will include hostname",
#endif /* _WINDOWS */
@@ -121,19 +123,21 @@ char *help_message[] = {
static struct zbx_option longopts[] =
{
- {"config", 1, 0, 'c'},
- {"help", 0, 0, 'h'},
- {"version", 0, 0, 'V'},
- {"print", 0, 0, 'p'},
- {"test", 1, 0, 't'},
+ {"config", 1, 0, 'c'},
+ {"help", 0, 0, 'h'},
+ {"version", 0, 0, 'V'},
+ {"print", 0, 0, 'p'},
+ {"test", 1, 0, 't'},
#if defined (_WINDOWS)
- {"install", 0, 0, 'i'},
- {"uninstall", 0, 0, 'd'},
+ {"install", 0, 0, 'i'},
+ {"uninstall", 0, 0, 'd'},
- {"start", 0, 0, 's'},
- {"stop", 0, 0, 'x'},
+ {"start", 0, 0, 's'},
+ {"stop", 0, 0, 'x'},
+
+ {"multiple-agents", 0, 0, 'm'},
#endif /* _WINDOWS */
@@ -145,7 +149,7 @@ static struct zbx_option longopts[] =
static char shortopts[] =
"c:hVpt:"
#if defined (_WINDOWS)
- "idsx"
+ "idsxm"
#endif /* _WINDOWS */
;
@@ -157,11 +161,12 @@ static char *TEST_METRIC = NULL;
static ZBX_THREAD_HANDLE *threads = NULL;
-static zbx_task_t parse_commandline(int argc, char **argv)
+static void parse_commandline(int argc, char **argv, ZBX_TASK_EX *t)
{
- zbx_task_t task = ZBX_TASK_START;
char ch = '\0';
+ t->task = ZBX_TASK_START;
+
/* Parse the command-line. */
while ((ch = (char)zbx_getopt_long(argc, argv, shortopts, longopts, NULL)) != (char)EOF)
switch (ch) {
@@ -177,44 +182,42 @@ static zbx_task_t parse_commandline(int argc, char **argv)
exit(-1);
break;
case 'p':
- if(task == ZBX_TASK_START)
- task = ZBX_TASK_PRINT_SUPPORTED;
+ if(t->task == ZBX_TASK_START)
+ t->task = ZBX_TASK_PRINT_SUPPORTED;
break;
case 't':
- if(task == ZBX_TASK_START)
+ if(t->task == ZBX_TASK_START)
{
- task = ZBX_TASK_TEST_METRIC;
+ t->task = ZBX_TASK_TEST_METRIC;
TEST_METRIC = strdup(zbx_optarg);
}
break;
-
#if defined (_WINDOWS)
case 'i':
- task = ZBX_TASK_INSTALL_SERVICE;
+ t->task = ZBX_TASK_INSTALL_SERVICE;
break;
case 'd':
- task = ZBX_TASK_UNINSTALL_SERVICE;
+ t->task = ZBX_TASK_UNINSTALL_SERVICE;
break;
case 's':
- task = ZBX_TASK_START_SERVICE;
+ t->task = ZBX_TASK_START_SERVICE;
break;
case 'x':
- task = ZBX_TASK_STOP_SERVICE;
+ t->task = ZBX_TASK_STOP_SERVICE;
+ break;
+ case 'm':
+ t->flags = ZBX_TASK_FLAG_MULTIPLE_AGENTS;
break;
-
#endif /* _WINDOWS */
-
default:
- task = ZBX_TASK_SHOW_USAGE;
+ t->task = ZBX_TASK_SHOW_USAGE;
break;
- }
+ }
if(CONFIG_FILE == NULL)
{
CONFIG_FILE = DEFAULT_CONFIG_FILE;
}
-
- return task;
}
int MAIN_ZABBIX_ENTRY(void)
@@ -337,24 +340,32 @@ void zbx_on_exit()
int main(int argc, char **argv)
{
- int task = ZBX_TASK_START;
+ ZBX_TASK_EX t;
+
+ memset(&t, 0, sizeof(t));
+ t.task = ZBX_TASK_START;
progname = get_programm_name(argv[0]);
- task = parse_commandline(argc, argv);
+ parse_commandline(argc, argv, &t);
import_symbols();
init_metrics(); /* Must be before load_config(). load_config - use metrics!!! */
- if( ZBX_TASK_START == task )
+ if (ZBX_TASK_START == t.task || ZBX_TASK_INSTALL_SERVICE == t.task || ZBX_TASK_UNINSTALL_SERVICE == t.task || ZBX_TASK_START_SERVICE == t.task || ZBX_TASK_STOP_SERVICE == t.task)
load_config();
- load_user_parameters();
+#if defined (_WINDOWS)
+ if (t.flags & ZBX_TASK_FLAG_MULTIPLE_AGENTS) {
+ zbx_snprintf(ZABBIX_SERVICE_NAME, sizeof(ZABBIX_SERVICE_NAME), "%s [%s]", APPLICATION_NAME, CONFIG_HOSTNAME);
+ zbx_snprintf(ZABBIX_EVENT_SOURCE, sizeof(ZABBIX_EVENT_SOURCE), "%s [%s]", APPLICATION_NAME, CONFIG_HOSTNAME);
+ }
+#endif /* _WINDOWS */
- switch(task)
- {
+ load_user_parameters();
+ switch (t.task) {
#if defined (_WINDOWS)
case ZBX_TASK_INSTALL_SERVICE:
exit(ZabbixCreateService(argv[0]));