@@ -5,9 +5,12 @@ package events
55
66import (
77 "fmt"
8+ "regexp"
89 "strconv"
10+ "strings"
911
1012 "github.com/aws/amazon-cloudwatch-agent/tool/data"
13+ "github.com/aws/amazon-cloudwatch-agent/tool/data/config/logs"
1114 "github.com/aws/amazon-cloudwatch-agent/tool/processors"
1215 "github.com/aws/amazon-cloudwatch-agent/tool/processors/tracesconfig"
1316 "github.com/aws/amazon-cloudwatch-agent/tool/runtime"
@@ -29,6 +32,9 @@ const (
2932
3033 EventFormatXML = "xml"
3134 EventFormatPlainText = "text"
35+
36+ FilterTypeInclude = "include"
37+ FilterTypeExclude = "exclude"
3238)
3339
3440var Processor processors.Processor = & processor {}
@@ -67,6 +73,49 @@ func monitorEvents(ctx *runtime.Context, config *data.Config) {
6773 }
6874 }
6975
76+ var eventIDs []int
77+ if util .Yes ("Do you want to filter by specific Event IDs?" ) {
78+ eventIDsInput := util .Ask ("Enter Event IDs (comma-separated, e.g., 1001,1002,1003):" )
79+ if eventIDsInput != "" {
80+ eventIDStrings := strings .Split (eventIDsInput , "," )
81+ for _ , idStr := range eventIDStrings {
82+ idStr = strings .TrimSpace (idStr )
83+ if id , err := strconv .Atoi (idStr ); err == nil && id >= 0 && id <= 65535 {
84+ eventIDs = append (eventIDs , id )
85+ } else {
86+ fmt .Printf ("Warning: Invalid Event ID '%s' ignored\n " , idStr )
87+ }
88+ }
89+ }
90+ }
91+ var filters []* logs.EventFilter
92+ if util .Yes ("Do you want to add regex filters to include/exclude specific events?" ) {
93+ for {
94+ filterType := util .Choice ("Filter type:" , 1 , []string {"Include (events matching regex)" , "Exclude (events matching regex)" })
95+ var filterTypeStr string
96+ if filterType == "Include (events matching regex)" {
97+ filterTypeStr = FilterTypeInclude
98+ } else {
99+ filterTypeStr = FilterTypeExclude
100+ }
101+ regexPattern := util .Ask ("Enter regex pattern:" )
102+ if regexPattern != "" {
103+ if _ , err := regexp .Compile (regexPattern ); err != nil {
104+ fmt .Printf ("Error: Invalid regex pattern '%s': %v\n " , regexPattern , err )
105+ continue
106+ }
107+ filter := & logs.EventFilter {
108+ Type : filterTypeStr ,
109+ Expression : regexPattern ,
110+ }
111+ filters = append (filters , filter )
112+ }
113+ if ! util .Yes ("Do you want to add another regex filter?" ) {
114+ break
115+ }
116+ }
117+ }
118+
70119 logGroupName := util .AskWithDefault ("Log group name:" , eventName )
71120
72121 logStreamNameHint := "{instance_id}"
@@ -102,7 +151,7 @@ func monitorEvents(ctx *runtime.Context, config *data.Config) {
102151 if err == nil {
103152 retention = i
104153 }
105- logsConf .AddWindowsEvent (eventName , logGroupName , logStreamName , eventFormat , eventLevels , retention , logGroupClass )
154+ logsConf .AddWindowsEvent (eventName , logGroupName , logStreamName , eventFormat , eventLevels , eventIDs , filters , retention , logGroupClass )
106155
107156 yes = util .Yes (fmt .Sprintf ("Do you want to specify any additional %s to monitor?" , WindowsEventLog ))
108157 if ! yes {
0 commit comments