Skip to content

Commit 8976ad5

Browse files
committed
fix: improve log handling in GPT request and ensure last log entry is used
1 parent da77066 commit 8976ad5

2 files changed

Lines changed: 18 additions & 9 deletions

File tree

soc-ai/elastic/alerts.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -234,19 +234,20 @@ func BuildCorrelationContext(corr *AlertCorrelation) string {
234234
return sb.String()
235235
}
236236

237-
var matchTypeNames = map[string]string{
238-
"SourceIP": "Source IP",
239-
"DestinationIP": "Destination IP",
240-
"SourceUser": "Source User",
241-
"DestinationUser": "Destination User",
242-
}
243-
244237
func translateMatchTypes(types []string) string {
245238
sort.Strings(types)
246239
var out []string
240+
247241
for _, t := range types {
248-
if name, ok := matchTypeNames[t]; ok {
249-
out = append(out, name)
242+
switch t {
243+
case "SourceIP":
244+
out = append(out, "Source IP")
245+
case "DestinationIP":
246+
out = append(out, "Destination IP")
247+
case "SourceUser":
248+
out = append(out, "Source User")
249+
case "DestinationUser":
250+
out = append(out, "Destination User")
250251
}
251252
}
252253
return strings.Join(out, " and ")

soc-ai/gpt/client.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ func (c *GPTClient) Request(alert schema.AlertGPTDetails) (string, error) {
3939
if alert.Logs == "" || alert.Logs == " " {
4040
content += content + ". " + configurations.GPT_FALSE_POSITIVE
4141
}
42+
43+
if alert.Logs != "" && alert.Logs != " " {
44+
logs := strings.Split(alert.Logs, configurations.LOGS_SEPARATOR)
45+
if len(logs) > 0 {
46+
alert.Logs = logs[len(logs)-1]
47+
}
48+
}
49+
4250
jsonContent, err := json.Marshal(alert)
4351
if err != nil {
4452
return "", fmt.Errorf("error marshalling alert: %v", err)

0 commit comments

Comments
 (0)