|
|
|
@ -22,27 +22,17 @@
|
|
|
|
|
#include <dlfcn.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
#include <limits.h>
|
|
|
|
|
|
|
|
|
|
#include "list.h"
|
|
|
|
|
|
|
|
|
|
#include "plugins.h"
|
|
|
|
|
#include "configfile.h"
|
|
|
|
|
#include "event.h"
|
|
|
|
|
#include "logging.h"
|
|
|
|
|
#include "network.h"
|
|
|
|
|
#include "rrdtool.h"
|
|
|
|
|
|
|
|
|
|
#define BUFSIZE 512
|
|
|
|
|
|
|
|
|
|
#define SUBMIT_NET_ONLY 0x01
|
|
|
|
|
#include "plugins.h"
|
|
|
|
|
|
|
|
|
|
static LIST_HEAD(plugin_list);
|
|
|
|
|
|
|
|
|
|
static int submit_flags;
|
|
|
|
|
|
|
|
|
|
static char *scratchpad;
|
|
|
|
|
|
|
|
|
|
static int plugin_init_cb(const char *filename, void *privdata)
|
|
|
|
@ -118,11 +108,15 @@ static int plugins_probe(void *privdata)
|
|
|
|
|
int plugin_init(void)
|
|
|
|
|
{
|
|
|
|
|
int bufsize = 0;
|
|
|
|
|
config_get_strings("global", "plugin", plugin_init_cb, &bufsize);
|
|
|
|
|
int cnt = config_get_strings("global", "plugin", plugin_init_cb, &bufsize);
|
|
|
|
|
if (cnt == 0) {
|
|
|
|
|
log_print(LOG_ERROR, "plugin_init(): no working plugins");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
scratchpad = malloc(bufsize);
|
|
|
|
|
if (scratchpad == NULL) {
|
|
|
|
|
log_print(LOG_ERROR, "plugin_init: out of memory");
|
|
|
|
|
log_print(LOG_ERROR, "plugin_init(): out of memory");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -130,10 +124,6 @@ int plugin_init(void)
|
|
|
|
|
list_for_each_entry(plugin, &plugin_list, list)
|
|
|
|
|
plugin->buffer = scratchpad;
|
|
|
|
|
|
|
|
|
|
const char *fwd_only = config_get_string("global", "forward_only", NULL);
|
|
|
|
|
if (fwd_only == NULL || strncmp(fwd_only, "true", 4))
|
|
|
|
|
submit_flags |= SUBMIT_NET_ONLY;
|
|
|
|
|
|
|
|
|
|
struct timeval tv;
|
|
|
|
|
tv.tv_sec = 1;
|
|
|
|
|
tv.tv_usec = 0;
|
|
|
|
@ -151,35 +141,3 @@ struct sammler_plugin * plugin_lookup(const char *name)
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|