diff options
Diffstat (limited to 'output')
-rw-r--r-- | output/Makefile.am | 4 | ||||
-rw-r--r-- | output/ulogd_output_LOGEMU.c | 58 | ||||
-rw-r--r-- | output/ulogd_output_SYSLOG.c | 19 |
3 files changed, 62 insertions, 19 deletions
diff --git a/output/Makefile.am b/output/Makefile.am index 88e353e..9a966d2 100644 --- a/output/Makefile.am +++ b/output/Makefile.am @@ -6,10 +6,10 @@ SUBDIRS= pcap mysql pgsql sqlite3 pkglib_LTLIBRARIES = ulogd_output_LOGEMU.la ulogd_output_SYSLOG.la \ ulogd_output_OPRINT.la ulogd_output_IPFIX.la -ulogd_output_LOGEMU_la_SOURCES = ulogd_output_LOGEMU.c ../util/printpkt.c +ulogd_output_LOGEMU_la_SOURCES = ulogd_output_LOGEMU.c ulogd_output_LOGEMU_la_LDFLAGS = -module -ulogd_output_SYSLOG_la_SOURCES = ulogd_output_SYSLOG.c ../util/printpkt.c +ulogd_output_SYSLOG_la_SOURCES = ulogd_output_SYSLOG.c ulogd_output_SYSLOG_la_LDFLAGS = -module ulogd_output_OPRINT_la_SOURCES = ulogd_output_OPRINT.c diff --git a/output/ulogd_output_LOGEMU.c b/output/ulogd_output_LOGEMU.c index f18da61..a224d7b 100644 --- a/output/ulogd_output_LOGEMU.c +++ b/output/ulogd_output_LOGEMU.c @@ -29,9 +29,14 @@ #include <unistd.h> #include <string.h> #include <errno.h> +#include <time.h> #include <ulogd/ulogd.h> #include <ulogd/conffile.h> -#include <ulogd/printpkt.h> + +#ifndef HOST_NAME_MAX +#warning this libc does not define HOST_NAME_MAX +#define HOST_NAME_MAX (255+1) +#endif #ifndef ULOGD_LOGEMU_DEFAULT #define ULOGD_LOGEMU_DEFAULT "/var/log/ulogd.syslogemu" @@ -41,6 +46,19 @@ #define ULOGD_LOGEMU_SYNC_DEFAULT 0 #endif +static char hostname[HOST_NAME_MAX+1]; + +static struct ulogd_key logemu_inp[] = { + { + .type = ULOGD_RET_STRING, + .name = "print", + }, + { + .type = ULOGD_RET_UINT32, + .name = "oob.time.sec", + }, +}; + static struct config_keyset logemu_kset = { .num_ces = 2, .ces = { @@ -67,14 +85,27 @@ static int _output_logemu(struct ulogd_pluginstance *upi) { struct logemu_instance *li = (struct logemu_instance *) &upi->private; struct ulogd_key *res = upi->input.keys; - static char buf[4096]; - printpkt_print(res, buf, 1); + if (res[0].u.source->flags & ULOGD_RETF_VALID) { + char *timestr; + char *tmp; + time_t now; - fprintf(li->of, "%s", buf); + if (res[1].u.source->flags & ULOGD_RETF_VALID) + now = (time_t) res[1].u.source->u.value.ui32; + else + now = time(NULL); - if (upi->config_kset->ces[1].u.value) - fflush(li->of); + timestr = ctime(&now) + 4; + if ((tmp = strchr(timestr, '\n'))) + *tmp = '\0'; + + fprintf(li->of, "%.15s %s %s", timestr, hostname, + res[0].u.source->u.value.ptr); + + if (upi->config_kset->ces[1].u.value) + fflush(li->of); + } return 0; } @@ -102,6 +133,7 @@ static void signal_handler_logemu(struct ulogd_pluginstance *pi, int signal) static int start_logemu(struct ulogd_pluginstance *pi) { struct logemu_instance *li = (struct logemu_instance *) &pi->private; + char *tmp; ulogd_log(ULOGD_DEBUG, "starting logemu\n"); @@ -117,11 +149,17 @@ static int start_logemu(struct ulogd_pluginstance *pi) return errno; } #endif - if (printpkt_init()) { - ulogd_log(ULOGD_ERROR, "can't resolve all keyhash id's\n"); + + if (gethostname(hostname, sizeof(hostname)) < 0) { + ulogd_log(ULOGD_FATAL, "can't gethostname(): %s\n", + strerror(errno)); return -EINVAL; } + /* truncate hostname */ + if ((tmp = strchr(hostname, '.'))) + *tmp = '\0'; + return 0; } @@ -147,8 +185,8 @@ static int configure_logemu(struct ulogd_pluginstance *pi, static struct ulogd_plugin logemu_plugin = { .name = "LOGEMU", .input = { - .keys = printpkt_keys, - .num_keys = ARRAY_SIZE(printpkt_keys), + .keys = logemu_inp, + .num_keys = ARRAY_SIZE(logemu_inp), .type = ULOGD_DTYPE_PACKET, }, .output = { diff --git a/output/ulogd_output_SYSLOG.c b/output/ulogd_output_SYSLOG.c index 3d08f74..8b89295 100644 --- a/output/ulogd_output_SYSLOG.c +++ b/output/ulogd_output_SYSLOG.c @@ -31,7 +31,6 @@ #include <errno.h> #include <ulogd/ulogd.h> #include <ulogd/conffile.h> -#include <ulogd/printpkt.h> #ifndef SYSLOG_FACILITY_DEFAULT #define SYSLOG_FACILITY_DEFAULT "LOG_KERN" @@ -41,6 +40,13 @@ #define SYSLOG_LEVEL_DEFAULT "LOG_NOTICE" #endif +static struct ulogd_key syslog_inp[] = { + { + .type = ULOGD_RET_STRING, + .name = "print", + }, +}; + static struct config_keyset syslog_kset = { .num_ces = 2, .ces = { @@ -68,11 +74,10 @@ static int _output_syslog(struct ulogd_pluginstance *upi) { struct syslog_instance *li = (struct syslog_instance *) &upi->private; struct ulogd_key *res = upi->input.keys; - static char buf[4096]; - - printpkt_print(res, buf, 0); - syslog(li->syslog_level | li->syslog_facility, buf); + if (res[0].u.source->flags & ULOGD_RETF_VALID) + syslog(li->syslog_level | li->syslog_facility, "%s", + res[0].u.source->u.value.ptr); return 0; } @@ -156,8 +161,8 @@ static int syslog_start(struct ulogd_pluginstance *pi) static struct ulogd_plugin syslog_plugin = { .name = "SYSLOG", .input = { - .keys = printpkt_keys, - .num_keys = ARRAY_SIZE(printpkt_keys), + .keys = syslog_inp, + .num_keys = ARRAY_SIZE(syslog_inp), .type = ULOGD_DTYPE_PACKET, }, .output = { |