move config parsing to init() functions

This commit is contained in:
Olaf Rempel 2009-05-01 21:24:12 +02:00
parent 22958bb820
commit d09c70d2aa
6 changed files with 55 additions and 22 deletions

View File

@ -28,6 +28,7 @@ ifeq ("$(WITH_RRD)", "yes")
LDFLAGS += -lrrd
TARGET = sammler
else
SRC += rrdtool-fake.c
TARGET = sammler_norrd
endif
@ -36,7 +37,7 @@ endif
all: $(TARGET) plugins
$(TARGET): $(SRC:%.c=%.o)
@echo " Linking file: $@"
@echo " Linking file: $@"
@$(CC) $(LDFLAGS) $^ -o $@
%.o: %.c
@ -47,19 +48,19 @@ $(TARGET): $(SRC:%.c=%.o)
plugins: $(PLUGINS:%=plugins/%.o) $(PLUGINS:%=plugins/%.so)
plugins/%.so: plugins/%.o
@echo " Linking file: $@"
@echo " Linking file: $@"
@$(CC) $(LDFLAGS) -shared -o $@ $<
plugins/apache.so: plugins/apache.o
@echo " Linking file: $@"
@echo " Linking file: $@"
@$(CC) $(LDFLAGS) -shared -o -lcurl -o $@ $<
plugins/conntrack.so: plugins/conntrack.o
@echo " Linking file: $@"
@echo " Linking file: $@"
@$(CC) $(LDFLAGS) -shared -o -lnfnetlink -lnetfilter_conntrack -o $@ $<
plugins/mysql.so: plugins/mysql.o plugins/mysql_helper.o
@echo " Linking file: $@"
@echo " Linking file: $@"
@$(CC) $(LDFLAGS) -shared -o -lmysqlclient -o $@ $<
install: all

View File

@ -1,10 +1,7 @@
#ifndef _RRDTOOL_H_
#define _RRDTOOL_H_
#ifdef WITH_RRD
int rrd_init(void);
int rrd_submit(const char *hostname, const char *pluginname, const char *filename, int ds_id, const char *data);
#else
#define rrd_submit(hostname, plugin, filename, ds_id, data)
#endif
#endif /* _RRDTOOL_H_ */

15
probe.c
View File

@ -14,6 +14,7 @@
#define SUBMIT_NET_ONLY 0x01
static int submit_flags;
static const char *hostname;
int probe_init(void)
{
@ -21,20 +22,16 @@ int probe_init(void)
if (!strncmp(fwd_only, "true", 4))
submit_flags |= SUBMIT_NET_ONLY;
static char hostname_buf[32];
if (gethostname(hostname_buf, sizeof(hostname_buf)) != 0)
strcpy(hostname_buf, "localhost");
hostname = config_get_string("global", "hostname", hostname_buf);
return 0;
}
int probe_submit(struct sammler_plugin *plugin, const char *filename, int ds_id, const char *fmt, ... )
{
static const char *hostname = NULL;
if (hostname == NULL) {
static char hostname_buf[32];
if (gethostname(hostname_buf, sizeof(hostname_buf)) != 0)
strcpy(hostname_buf, "localhost");
hostname = config_get_string("global", "hostname", hostname_buf);
}
char *buffer = malloc(BUFSIZE);
if (buffer == NULL) {
log_print(LOG_ERROR, "probe_submit: out of memory");

30
rrdtool-fake.c Normal file
View File

@ -0,0 +1,30 @@
/***************************************************************************
* Copyright (C) 05/2009 by Olaf Rempel *
* razzor@kopf-tisch.de *
* *
* 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., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include <rrdtool.h>
int rrd_init(void)
{
return 0;
}
int rrd_submit(const char *hostname, const char *pluginname, const char *filename, int ds_id, const char *data)
{
return 0;
}

View File

@ -48,6 +48,14 @@ struct rra_cb_data {
int *pos;
};
static const char *rrd_dir;
int rrd_init(void)
{
rrd_dir = config_get_string("global", "rrd_dir", ".");
return 0;
}
static int append_rra_config(const char *parameter, void *privdata)
{
struct rra_cb_data *data = (struct rra_cb_data *)privdata;
@ -201,10 +209,6 @@ static int create_parent_dirs(char *filename)
int rrd_submit(const char *hostname, const char *pluginname, const char *filename, int ds_id, const char *data)
{
static const char *rrd_dir = NULL;
if (rrd_dir == NULL)
rrd_dir = config_get_string("global", "rrd_dir", ".");
char *fullfile = malloc(BUFSIZE);
if (fullfile == NULL) {
log_print(LOG_ERROR, "rrd_submit: out of memory");

View File

@ -31,6 +31,7 @@
#include "event.h"
#include "logging.h"
#include "network.h"
#include "rrdtool.h"
#include "plugins.h"
#include "probe.h"
@ -103,6 +104,9 @@ int main(int argc, char *argv[])
if (net_init())
exit(1);
if (rrd_init())
exit(1);
if (plugin_init()) {
net_close();
exit(1);