Skip to content

Commit 42b581d

Browse files
nokute78edsiper
authored andcommitted
in_kmsg: support prio_level property.
It is for filtering using a priority (kernel log level). If user sets prio_level=4, the logs that priority is greater than 4 are ignored. Default value is 8. It means all logs are saved. Signed-off-by: Takahiro Yamashita <[email protected]>
1 parent 0a75413 commit 42b581d

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

plugins/in_kmsg/in_kmsg.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ static inline int process_line(const char *line,
132132
/* Priority */
133133
priority = FLB_KLOG_PRI(val);
134134

135+
if (priority > ctx->prio_level) {
136+
/* Drop line */
137+
return 0;
138+
}
139+
135140
/* Sequence */
136141
p = strchr(p, ',');
137142
if (!p) {
@@ -308,6 +313,7 @@ static int in_kmsg_init(struct flb_input_instance *ins,
308313
flb_free(ctx);
309314
return -1;
310315
}
316+
flb_plg_debug(ctx->ins, "prio_level is %d", ctx->prio_level);
311317

312318
/* Set our collector based on a file descriptor event */
313319
ret = flb_input_set_collector_event(ins,
@@ -339,6 +345,12 @@ static int in_kmsg_exit(void *data, struct flb_config *config)
339345
}
340346

341347
static struct flb_config_map config_map[] = {
348+
{
349+
FLB_CONFIG_MAP_INT, "prio_level", "8",
350+
0, FLB_TRUE, offsetof(struct flb_in_kmsg_config, prio_level),
351+
"The log level to filter. The kernel log is dropped if its priority is more than prio_level. "
352+
"Allowed values are 0-8. Default is 8."
353+
},
342354
/* EOF */
343355
{0}
344356
};

plugins/in_kmsg/in_kmsg.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ struct flb_in_kmsg_config {
4848
int fd; /* descriptor -> FLB_KMSG_DEV */
4949
struct timeval boot_time; /* System boot time */
5050

51+
int prio_level;
52+
5153
/* Line processing */
5254
int buffer_id;
5355

0 commit comments

Comments
 (0)