#include #include #include #include #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; }