@@ -74,6 +74,9 @@ type AlertCorrelation struct {
7474}
7575
7676func GetRelatedAlerts () ([]schema.GPTAlertResponse , error ) {
77+ // Debug log
78+ utils .Logger .Info ("Getting historical alerts from Elasticsearch" )
79+
7780 result , err := ElasticSearch (configurations .ALERT_INDEX_PATTERN , "*" , "*" )
7881 if err != nil {
7982 return nil , fmt .Errorf ("error getting historical alerts: %v" , err )
@@ -89,6 +92,9 @@ func GetRelatedAlerts() ([]schema.GPTAlertResponse, error) {
8992}
9093
9194func FindRelatedAlerts (currentAlert schema.Alert ) (* AlertCorrelation , error ) {
95+ // Debug log
96+ utils .Logger .Info ("Finding related alerts for alert %s" , currentAlert .ID )
97+
9298 correlation := & AlertCorrelation {
9399 CurrentAlert : currentAlert ,
94100 RelatedAlerts : []schema.Alert {},
@@ -100,6 +106,8 @@ func FindRelatedAlerts(currentAlert schema.Alert) (*AlertCorrelation, error) {
100106 return nil , err
101107 }
102108
109+ utils .Logger .Info ("Found %d historical alerts to analyze" , len (historicalResponses ))
110+
103111 var alertIDs []string
104112 for _ , resp := range historicalResponses {
105113 alertIDs = append (alertIDs , resp .ActivityID )
@@ -123,36 +131,50 @@ func FindRelatedAlerts(currentAlert schema.Alert) (*AlertCorrelation, error) {
123131 }
124132 }
125133
134+ utils .Logger .Info ("Completed related alerts search. Found %d related alerts for ID: %s" ,
135+ len (correlation .RelatedAlerts ), currentAlert .ID )
136+
126137 return correlation , nil
127138}
128139
129140func isAlertRelated (current , historical schema.Alert ) bool {
141+ utils .Logger .Info ("Checking relation between alerts - Current: %s, Historical: %s" , current .ID , historical .ID )
142+
130143 if current .Destination .IP != "" && current .Destination .IP == historical .Destination .IP {
144+ utils .Logger .Info ("Match found: Destination IP %s" , current .Destination .IP )
131145 return true
132146 }
133147 if current .Destination .Port != 0 && current .Destination .Port == historical .Destination .Port {
148+ utils .Logger .Info ("Match found: Destination Port %d" , current .Destination .Port )
134149 return true
135150 }
136151 if current .Destination .Host != "" && current .Destination .Host == historical .Destination .Host {
152+ utils .Logger .Info ("Match found: Destination Host %s" , current .Destination .Host )
137153 return true
138154 }
139155 if current .Destination .User != "" && current .Destination .User == historical .Destination .User {
156+ utils .Logger .Info ("Match found: Destination User %s" , current .Destination .User )
140157 return true
141158 }
142159
143160 if current .Source .IP != "" && current .Source .IP == historical .Source .IP {
161+ utils .Logger .Info ("Match found: Source IP %s" , current .Source .IP )
144162 return true
145163 }
146164 if current .Source .Port != 0 && current .Source .Port == historical .Source .Port {
165+ utils .Logger .Info ("Match found: Source Port %d" , current .Source .Port )
147166 return true
148167 }
149168 if current .Source .Host != "" && current .Source .Host == historical .Source .Host {
169+ utils .Logger .Info ("Match found: Source Host %s" , current .Source .Host )
150170 return true
151171 }
152172 if current .Source .User != "" && current .Source .User == historical .Source .User {
173+ utils .Logger .Info ("Match found: Source User %s" , current .Source .User )
153174 return true
154175 }
155176
177+ utils .Logger .Info ("No match found between alerts %s and %s" , current .ID , historical .ID )
156178 return false
157179}
158180
@@ -194,12 +216,6 @@ func BuildCorrelationContext(correlation *AlertCorrelation) string {
194216 if alert .Destination .Port != 0 {
195217 context .WriteString (fmt .Sprintf ("- Destination Port: %d\n " , alert .Destination .Port ))
196218 }
197- if alert .Protocol != "" {
198- context .WriteString (fmt .Sprintf ("- Protocol: %s\n " , alert .Protocol ))
199- }
200- if alert .Severity != 0 {
201- context .WriteString (fmt .Sprintf ("- Severity: %d\n " , alert .Severity ))
202- }
203219 }
204220
205221 return context .String ()
0 commit comments