Skip to content

Commit ac450eb

Browse files
authored
in_winevtlog: adds ability to ignore channels missing in Windows Event Log (#6176)
* Additions to in_winevtlog plugin to allow scenarios where one or more channels are missing on Windows Event Log, e.g: PowerShellCore/Operational needs the proper software installed to appear under Application and Services Log Signed-off-by: Meissner Morales <[email protected]>
1 parent dbcafcf commit ac450eb

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

plugins/in_winevtlog/in_winevtlog.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static int in_winevtlog_init(struct flb_input_instance *in,
6868
tmp = "Application";
6969
}
7070

71-
ctx->active_channel = winevtlog_open_all(tmp, ctx->read_existing_events);
71+
ctx->active_channel = winevtlog_open_all(tmp, ctx->read_existing_events, ctx->ignore_missing_channels);
7272
if (!ctx->active_channel) {
7373
flb_plg_error(ctx->ins, "failed to open channels");
7474
flb_free(ctx);
@@ -238,6 +238,11 @@ static struct flb_config_map config_map[] = {
238238
0, FLB_TRUE, offsetof(struct winevtlog_config, use_ansi),
239239
"Use ANSI encoding on eventlog messages"
240240
},
241+
{
242+
FLB_CONFIG_MAP_BOOL, "ignore_missing_channels", "false",
243+
0, FLB_TRUE, offsetof(struct winevtlog_config, ignore_missing_channels),
244+
"Whether to ignore channels missing in eventlog"
245+
},
241246

242247
/* EOF */
243248
{0}

plugins/in_winevtlog/winevtlog.c

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ int winevtlog_read(struct winevtlog_channel *ch, msgpack_packer *mp_pck, struct
587587
*
588588
* "channels" are comma-separated names like "Setup,Security".
589589
*/
590-
struct mk_list *winevtlog_open_all(const char *channels, int read_existing_events)
590+
struct mk_list *winevtlog_open_all(const char *channels, int read_existing_events, int ignore_missing_channels)
591591
{
592592
char *tmp;
593593
char *channel;
@@ -612,14 +612,30 @@ struct mk_list *winevtlog_open_all(const char *channels, int read_existing_event
612612
channel = strtok_s(tmp , ",", &state);
613613
while (channel) {
614614
ch = winevtlog_subscribe(channel, read_existing_events, NULL);
615-
if (!ch) {
616-
flb_free(tmp);
617-
winevtlog_close_all(list);
618-
return NULL;
615+
if (ignore_missing_channels) {
616+
if (ch) {
617+
mk_list_add(&ch->_head, list);
618+
}
619+
else {
620+
flb_debug("[in_winevtlog] channel '%s' does not exist", channel);
621+
}
622+
}
623+
else {
624+
if (!ch) {
625+
flb_free(tmp);
626+
winevtlog_close_all(list);
627+
return NULL;
628+
}
619629
}
620-
mk_list_add(&ch->_head, list);
621630
channel = strtok_s(NULL, ",", &state);
622631
}
632+
633+
if (mk_list_size(list) == 0) {
634+
flb_free(tmp);
635+
winevtlog_close_all(list);
636+
return NULL;
637+
}
638+
623639
flb_free(tmp);
624640
return list;
625641
}

plugins/in_winevtlog/winevtlog.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ struct winevtlog_config {
3131
int read_existing_events;
3232
int render_event_as_xml;
3333
int use_ansi;
34+
int ignore_missing_channels;
3435

3536
struct mk_list *active_channel;
3637
struct flb_sqldb *db;
@@ -80,7 +81,7 @@ int winevtlog_read(struct winevtlog_channel *ch, msgpack_packer *mp_pck,
8081
*
8182
* "channels" are comma-separated names like "Setup,Security".
8283
*/
83-
struct mk_list *winevtlog_open_all(const char *channels, int read_exising_events);
84+
struct mk_list *winevtlog_open_all(const char *channels, int read_exising_events, int ignore_missing_channels);
8485
void winevtlog_close_all(struct mk_list *list);
8586

8687
void winevtlog_pack_xml_event(msgpack_packer *mp_pck, WCHAR *system_xml, WCHAR *message,

0 commit comments

Comments
 (0)