diff options
author | Christian Hesse <mail@eworm.de> | 2019-09-04 11:45:01 +0200 |
---|---|---|
committer | Christian Hesse <mail@eworm.de> | 2019-09-04 11:45:01 +0200 |
commit | aedd6f6551da38c90135c9b607143909981bf4b7 (patch) | |
tree | 16b5adfd7f5d48dd885f59d7313db3b3d9575d56 | |
parent | ad9bd94d84d32d0a4d0a5f4448d1b54fb81a6fa6 (diff) | |
download | udp514-journal-aedd6f6551da38c90135c9b607143909981bf4b7.tar.gz udp514-journal-aedd6f6551da38c90135c9b607143909981bf4b7.tar.zst |
parse and send priority
-rw-r--r-- | udp514-journal.c | 15 | ||||
-rw-r--r-- | udp514-journal.h | 4 |
2 files changed, 18 insertions, 1 deletions
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 <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> |