mirror of
https://dev.iopsys.eu/feed/iopsys.git
synced 2025-12-10 07:44:50 +01:00
fluent-bit: fix kmsg plugin and add syslog timestamp to kmsg logs
This commit is contained in:
parent
bc041faf04
commit
5b865c9dbc
1 changed files with 58 additions and 0 deletions
58
fluent-bit/patches/0005-kmsg_log.patch
Normal file
58
fluent-bit/patches/0005-kmsg_log.patch
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
diff --git a/plugins/in_kmsg/in_kmsg.c b/plugins/in_kmsg/in_kmsg.c
|
||||
index 9bafd1b60..9524cf194 100644
|
||||
--- a/plugins/in_kmsg/in_kmsg.c
|
||||
+++ b/plugins/in_kmsg/in_kmsg.c
|
||||
@@ -36,6 +36,7 @@
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <inttypes.h>
|
||||
+#include <time.h>
|
||||
|
||||
#include "in_kmsg.h"
|
||||
|
||||
@@ -143,7 +144,7 @@ static inline int process_line(const char *line,
|
||||
}
|
||||
p++;
|
||||
|
||||
- val = strtol(p, &end, 10);
|
||||
+ val = strtoul(p, &end, 10);
|
||||
if ((errno == ERANGE && (val == INT_MAX || val == INT_MIN))
|
||||
|| (errno != 0 && val == 0)) {
|
||||
goto fail;
|
||||
@@ -153,7 +154,7 @@ static inline int process_line(const char *line,
|
||||
p = ++end;
|
||||
|
||||
/* Timestamp */
|
||||
- val = strtol(p, &end, 10);
|
||||
+ val = strtoul(p, &end, 10);
|
||||
if ((errno == ERANGE && (val == INT_MAX || val == INT_MIN))
|
||||
|| (errno != 0 && val == 0)) {
|
||||
goto fail;
|
||||
@@ -164,6 +165,15 @@ static inline int process_line(const char *line,
|
||||
|
||||
flb_time_set(&ts, ctx->boot_time.tv_sec + tv.tv_sec, tv.tv_usec * 1000);
|
||||
|
||||
+ /* Format syslog timestamp: "Jul 03 10:31:53" */
|
||||
+ time_t real_time = ctx->boot_time.tv_sec + tv.tv_sec;
|
||||
+ struct tm tm_info;
|
||||
+ char syslog_ts[32];
|
||||
+
|
||||
+ localtime_r(&real_time, &tm_info);
|
||||
+ strftime(syslog_ts, sizeof(syslog_ts), "%b %d %H:%M:%S", &tm_info);
|
||||
+ int syslog_ts_len = strlen(syslog_ts);
|
||||
+
|
||||
/* Now process the human readable message */
|
||||
p = strchr(p, ';');
|
||||
if (!p) {
|
||||
@@ -197,7 +207,10 @@ static inline int process_line(const char *line,
|
||||
FLB_LOG_EVENT_UINT64_VALUE(tv.tv_usec),
|
||||
|
||||
FLB_LOG_EVENT_CSTRING_VALUE("msg"),
|
||||
- FLB_LOG_EVENT_STRING_VALUE((char *) p, line_len - 1));
|
||||
+ FLB_LOG_EVENT_STRING_VALUE((char *) p, line_len - 1),
|
||||
+
|
||||
+ FLB_LOG_EVENT_CSTRING_VALUE("syslog_ts"),
|
||||
+ FLB_LOG_EVENT_STRING_VALUE(syslog_ts, syslog_ts_len));
|
||||
}
|
||||
|
||||
if (ret == FLB_EVENT_ENCODER_SUCCESS) {
|
||||
Loading…
Add table
Reference in a new issue