sammler/network.c
2006-08-26 14:01:10 +02:00

49 lines
764 B
C

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "configfile.h"
#include "logging.h"
#define MAX_SIZE 8192
static char *pktbuf = NULL;
static int pos = 0;
void net_submit(char *hostname, char *plugin, char *filename, int ds_id, char *data)
{
int len = 0;
if (pktbuf == NULL) {
pktbuf = malloc(MAX_SIZE);
pos = 0;
}
if (pos == 0) {
len = snprintf(pktbuf, MAX_SIZE - pos, "%s\n", hostname);
if (len < 0 || len >= MAX_SIZE - pos)
return;
pos += len;
}
len = snprintf(pktbuf + pos, MAX_SIZE - pos, "%s:%s:%d %s\n",
plugin, filename, ds_id, data);
if (len < 0 || len >= MAX_SIZE - pos)
return;
pos += len;
return;
}
void net_commit()
{
if (pos == 0)
return;
log_print(LOG_ERROR, "%s", pktbuf);
pos = 0;
}