workertest
This commit is contained in:
parent
4419684028
commit
5ff162d145
@ -1,8 +1,10 @@
|
||||
noinst_HEADERS = containers.h snmp_subagent.h
|
||||
sysconf_DATA = smmapd.ini
|
||||
bin_PROGRAMS = smmapd
|
||||
bin_PROGRAMS = smmapd workertest
|
||||
smmapd_SOURCES = smmapd.c containers.c snmp_subagent.c
|
||||
smmapd_LDADD = ../libsmmapdfw/libsmmapdfw.la
|
||||
workertest_SOURCES = workertest.c containers.c
|
||||
workertest_LDADD = ../libsmmapdfw/libsmmapdfw.la
|
||||
|
||||
INCLUDES = -I../libsmmapdfw
|
||||
CPPFLAGS = -DDEFAULT_SMMAPD_INI=\"$(sysconfdir)/smmapd.ini\" @CPPFLAGS@
|
||||
|
@ -89,9 +89,11 @@ VERSION = @VERSION@
|
||||
|
||||
noinst_HEADERS = containers.h snmp_subagent.h
|
||||
sysconf_DATA = smmapd.ini
|
||||
bin_PROGRAMS = smmapd
|
||||
bin_PROGRAMS = smmapd workertest
|
||||
smmapd_SOURCES = smmapd.c containers.c snmp_subagent.c
|
||||
smmapd_LDADD = ../libsmmapdfw/libsmmapdfw.la
|
||||
workertest_SOURCES = workertest.c containers.c
|
||||
workertest_LDADD = ../libsmmapdfw/libsmmapdfw.la
|
||||
|
||||
INCLUDES = -I../libsmmapdfw
|
||||
CPPFLAGS = -DDEFAULT_SMMAPD_INI=\"$(sysconfdir)/smmapd.ini\" @CPPFLAGS@
|
||||
@ -100,7 +102,7 @@ EXTRA_DIST = smmapd.ini
|
||||
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
|
||||
CONFIG_HEADER = ../config.h
|
||||
CONFIG_CLEAN_FILES =
|
||||
bin_PROGRAMS = smmapd$(EXEEXT)
|
||||
bin_PROGRAMS = smmapd$(EXEEXT) workertest$(EXEEXT)
|
||||
PROGRAMS = $(bin_PROGRAMS)
|
||||
|
||||
|
||||
@ -111,6 +113,9 @@ smmapd_OBJECTS = smmapd.$(OBJEXT) containers.$(OBJEXT) \
|
||||
snmp_subagent.$(OBJEXT)
|
||||
smmapd_DEPENDENCIES = ../libsmmapdfw/libsmmapdfw.la
|
||||
smmapd_LDFLAGS =
|
||||
workertest_OBJECTS = workertest.$(OBJEXT) containers.$(OBJEXT)
|
||||
workertest_DEPENDENCIES = ../libsmmapdfw/libsmmapdfw.la
|
||||
workertest_LDFLAGS =
|
||||
CFLAGS = @CFLAGS@
|
||||
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
|
||||
@ -127,9 +132,10 @@ DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)
|
||||
|
||||
TAR = tar
|
||||
GZIP_ENV = --best
|
||||
DEP_FILES = .deps/containers.P .deps/smmapd.P .deps/snmp_subagent.P
|
||||
SOURCES = $(smmapd_SOURCES)
|
||||
OBJECTS = $(smmapd_OBJECTS)
|
||||
DEP_FILES = .deps/containers.P .deps/smmapd.P .deps/snmp_subagent.P \
|
||||
.deps/workertest.P
|
||||
SOURCES = $(smmapd_SOURCES) $(workertest_SOURCES)
|
||||
OBJECTS = $(smmapd_OBJECTS) $(workertest_OBJECTS)
|
||||
|
||||
all: all-redirect
|
||||
.SUFFIXES:
|
||||
@ -209,6 +215,10 @@ smmapd$(EXEEXT): $(smmapd_OBJECTS) $(smmapd_DEPENDENCIES)
|
||||
@rm -f smmapd$(EXEEXT)
|
||||
$(LINK) $(smmapd_LDFLAGS) $(smmapd_OBJECTS) $(smmapd_LDADD) $(LIBS)
|
||||
|
||||
workertest$(EXEEXT): $(workertest_OBJECTS) $(workertest_DEPENDENCIES)
|
||||
@rm -f workertest$(EXEEXT)
|
||||
$(LINK) $(workertest_LDFLAGS) $(workertest_OBJECTS) $(workertest_LDADD) $(LIBS)
|
||||
|
||||
install-sysconfDATA: $(sysconf_DATA)
|
||||
@$(NORMAL_INSTALL)
|
||||
$(mkinstalldirs) $(DESTDIR)$(sysconfdir)
|
||||
|
@ -228,8 +228,11 @@ int unregister_all() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
int register_all() {
|
||||
return register_worker(NULL);
|
||||
}
|
||||
|
||||
int register_worker(char *worker_name) {
|
||||
void *dl_handle;
|
||||
class_descriptor_t * class_descriptor;
|
||||
char *cfg_plugin_dir, *cfg_plugins, *cfg_plugin, *cfg_obj;
|
||||
@ -250,6 +253,9 @@ int register_all() {
|
||||
cfg_plugins = NULL; /* this is for subsequence calls of strtok */
|
||||
dlerror(); /* this is to clear old errors */
|
||||
|
||||
if ((NULL != worker_name) && strcmp(cfg_plugin, worker_name))
|
||||
continue;
|
||||
|
||||
cfg_obj = findcfg(cfg, cfg_plugin, CFG_NAME_OBJ);
|
||||
if (NULL == cfg_obj) {
|
||||
syslog(LOG_ERR, "register_all: obj for plugin %s not configured", cfg_plugin);
|
||||
|
129
smmapdfw/smmapd/workertest.c
Normal file
129
smmapdfw/smmapd/workertest.c
Normal file
@ -0,0 +1,129 @@
|
||||
/*
|
||||
Copyright (C) 2005, Wolfgang Hottgenroth
|
||||
|
||||
This file is part of smmapdfw.
|
||||
|
||||
smmapdfw 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.
|
||||
|
||||
smmapdfw 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 smmapdfw. If not, write to the Free Software Foundation, 59
|
||||
Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#define CVS_ID "$Id$"
|
||||
#define RELEASE_ID "0.1"
|
||||
|
||||
|
||||
#if HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include <syslog.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "htbuffer.h"
|
||||
#include "containers.h"
|
||||
#include "cfg.h"
|
||||
|
||||
#define _SMMAPD_C_
|
||||
#include "smmapd.h"
|
||||
|
||||
|
||||
cfg_t *cfg;
|
||||
|
||||
|
||||
void usage() {
|
||||
printf("workertest -f cfgfile [-h] -w worker -q query\n");
|
||||
printf(" -f cfgfile\n");
|
||||
printf(" -h print this help\n");
|
||||
printf(" -w worker to use\n");
|
||||
printf(" -q query parameters\n\n");
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int c, res, dispatcher_result;
|
||||
char *cfg_file=NULL, *worker=NULL, *query=NULL;
|
||||
void *handle;
|
||||
container_handle_t *container_handle;
|
||||
htbuffer_t *answer, *input;
|
||||
|
||||
|
||||
|
||||
while ((c = getopt(argc, argv,"w:q:f:hv")) != -1)
|
||||
switch (c) {
|
||||
case 'f':
|
||||
cfg_file = htstrdup(optarg);
|
||||
break;
|
||||
case 'w':
|
||||
worker = htstrdup(optarg);
|
||||
break;
|
||||
case 'q':
|
||||
query = htstrdup(optarg);
|
||||
break;
|
||||
case 'v':
|
||||
printf("\nworkertest - Wolfgang Hottgenroth <woho@hottis.de>\n");
|
||||
printf(" cvs_id: %s\n", CVS_ID);
|
||||
printf(" release_id: %s\n\n", RELEASE_ID);
|
||||
exit(1);
|
||||
case 'h':
|
||||
default:
|
||||
usage();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (NULL == cfg_file) {
|
||||
usage();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
openlog("workertest", LOG_PID, LOG_LOCAL2);
|
||||
syslog(LOG_INFO, "main: started");
|
||||
|
||||
cfg = readcfg((cfg_file == NULL) ? DEFAULT_SMMAPD_INI : cfg_file);
|
||||
|
||||
syslog(LOG_INFO, "main: load worker");
|
||||
res = register_worker(worker);
|
||||
if (0 != res) {
|
||||
syslog(LOG_INFO, "main: unable to load worker");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
syslog(LOG_INFO, "main: setup containers");
|
||||
res = containers_setup(&container_handle);
|
||||
if (0 != res) {
|
||||
syslog(LOG_INFO, "main: unable to setup containers");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
answer = htbuffer_init(512);
|
||||
input = htbuffer_init(512);
|
||||
|
||||
htbuffer_strcpy(input, worker);
|
||||
htbuffer_strcat(input, " ");
|
||||
htbuffer_strcat(input, query);
|
||||
|
||||
syslog(LOG_INFO, "main: querying worker {%s} with {%s}", worker, query);
|
||||
dispatcher_result = containers_dispatcher(container_handle, input->buf, answer);
|
||||
syslog(LOG_INFO, "main: result {%d}, answer {%s}", dispatcher_result, answer->buf);
|
||||
printf("result {%d}, answer {%s}\n", dispatcher_result, answer->buf);
|
||||
|
||||
htbuffer_free(input);
|
||||
htbuffer_free(answer);
|
||||
syslog(LOG_INFO, "main: buffers freed");
|
||||
|
||||
containers_destroy(container_handle);
|
||||
syslog(LOG_INFO, "main: containers destroyed");
|
||||
|
||||
syslog(LOG_INFO, "main: finished");
|
||||
closelog();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user