parent
f16b9a8169
commit
b71a7cfe04
@ -1,5 +1,4 @@
|
||||
*.o
|
||||
*.so
|
||||
*.d
|
||||
sammler
|
||||
sammler.log
|
||||
|
@ -0,0 +1,9 @@
|
||||
#ifndef _PROBE_H_
|
||||
#define _PROBE_H_
|
||||
|
||||
#include "plugins.h"
|
||||
|
||||
int probe_init(void);
|
||||
int probe_submit(struct sammler_plugin *plugin, const char *filename, int ds_id, const char *fmt, ... );
|
||||
|
||||
#endif /* _PROBE_H_ */
|
@ -0,0 +1,3 @@
|
||||
*.o
|
||||
*.so
|
||||
*.d
|
@ -0,0 +1,26 @@
|
||||
CFLAGS := -O2 -Wall -fno-stack-protector -I../include
|
||||
LDFLAGS := -ldl -rdynamic
|
||||
|
||||
# ############################
|
||||
|
||||
all: $(PLUGINS:%=%.so)
|
||||
|
||||
%.d: %.c
|
||||
$(CC) $(CFLAGS) -MM -c $< -o $@
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) -fPIC -o $@ -c $<
|
||||
|
||||
apache.so: apache.o
|
||||
$(LD) -shared -lcurl -o $@ $^
|
||||
|
||||
mysql.so: mysql.o mysql_helper.o
|
||||
$(LD) -shared -lmysqlclient -o $@ $^
|
||||
|
||||
%.so: %.o
|
||||
$(LD) -shared -o $@ $<
|
||||
|
||||
clean:
|
||||
rm -rf *.d *.o *.so
|
||||
|
||||
-include $(PLUGINS:%=%.d)
|
@ -0,0 +1,56 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "configfile.h"
|
||||
#include "logging.h"
|
||||
#include "network.h"
|
||||
#include "rrdtool.h"
|
||||
|
||||
#define BUFSIZE 512
|
||||
|
||||
#define SUBMIT_NET_ONLY 0x01
|
||||
|
||||
static int submit_flags;
|
||||
|
||||
int probe_init(void)
|
||||
{
|
||||
const char *fwd_only = config_get_string("global", "forward_only", "false");
|
||||
if (fwd_only == NULL || strncmp(fwd_only, "true", 4))
|
||||
submit_flags |= SUBMIT_NET_ONLY;
|
||||
|
||||
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)
|
||||
hostname = config_get_string("global", "hostname", "localhost");
|
||||
|
||||
char *buffer = malloc(BUFSIZE);
|
||||
if (buffer == NULL) {
|
||||
log_print(LOG_ERROR, "probe_submit: out of memory");
|
||||
return -1;
|
||||
}
|
||||
|
||||
va_list az;
|
||||
va_start(az, fmt);
|
||||
int len = vsnprintf(buffer, BUFSIZE, fmt, az);
|
||||
va_end(az);
|
||||
|
||||
if (len < 0 || len >= BUFSIZE) {
|
||||
log_print(LOG_ERROR, "probe_submit: %s arguments too long", plugin->name);
|
||||
free(buffer);
|
||||
return -1;
|
||||
}
|
||||
|
||||
net_submit(hostname, plugin->name, filename, ds_id, buffer);
|
||||
|
||||
if (!(submit_flags & SUBMIT_NET_ONLY))
|
||||
rrd_submit(hostname, plugin->name, filename, ds_id, buffer);
|
||||
|
||||
free(buffer);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in new issue