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 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'udp514-journal.c') 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 */ -- cgit v1.2.3-54-g00ecf