From aedd6f6551da38c90135c9b607143909981bf4b7 Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Wed, 4 Sep 2019 11:45:01 +0200 Subject: parse and send priority --- udp514-journal.c | 15 ++++++++++++++- udp514-journal.h | 4 ++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/udp514-journal.c b/udp514-journal.c index cef688f..5784491 100644 --- a/udp514-journal.c +++ b/udp514-journal.c @@ -36,6 +36,10 @@ int main(int argc, char **argv) { /* server loop */ while (1) { + char * match; + CODE * pri; + uint8_t priority = LOG_INFO; + memset(buffer, 0, BUFFER_SIZE); len = sizeof(cliAddr); n = recvfrom(s, buffer, BUFFER_SIZE, 0, @@ -44,10 +48,19 @@ int main(int argc, char **argv) { perror("could not receive data"); continue; } - + + /* parse priority */ + if ((match = strndup(buffer, BUFFER_SIZE)) != NULL) { + *strchr(match, ' ') = 0; + for (pri = prioritynames; pri->c_name && strstr(match, pri->c_name) == NULL; pri++); + free(match); + priority = pri->c_val; + } + /* send to systemd-journald */ sd_journal_send("MESSAGE=%s", buffer, "SYSLOG_IDENTIFIER=%s", inet_ntoa(cliAddr.sin_addr), + "PRIORITY=%i", priority, NULL); /* count and update status */ diff --git a/udp514-journal.h b/udp514-journal.h index d36fecf..e9b5469 100644 --- a/udp514-journal.h +++ b/udp514-journal.h @@ -8,6 +8,10 @@ #ifndef _UDP514_JOURNAL_H #define _UDP514_JOURNAL_H +#define _POSIX_C_SOURCE 200809L + +#define SYSLOG_NAMES + #include #include #include -- cgit v1.2.3-54-g00ecf