49 lines
1.2 KiB
Go
Raw Permalink Normal View History

2024-05-27 15:10:26 +02:00
package services
import (
"bufio"
"encoding/json"
"os"
"slices"
"strings"
2024-05-27 15:13:11 +02:00
"wazuh-notify/services/log"
2024-05-27 15:10:26 +02:00
"wazuh-notify/types"
)
func ParseWazuhInput(params types.Params) types.Params {
var wazuhData types.WazuhMessage
2024-05-27 15:49:04 +02:00
//Read stdin
2024-05-27 15:10:26 +02:00
reader := bufio.NewReader(os.Stdin)
2024-05-27 15:49:04 +02:00
//Decode stdin to wazuhData
2024-05-27 15:10:26 +02:00
json.NewDecoder(reader).Decode(&wazuhData)
2024-05-27 15:49:04 +02:00
//Parse tags
2024-05-27 15:10:26 +02:00
params.Tags += strings.Join(wazuhData.Parameters.Alert.Rule.Groups, ",")
params.WazuhMessage = wazuhData
2024-05-27 15:49:04 +02:00
//Map priority and color based on config
2024-05-27 15:10:26 +02:00
for i := range params.PriorityMap {
if slices.Contains(params.PriorityMap[i].ThreatMap, wazuhData.Parameters.Alert.Rule.Level) {
2024-05-27 15:49:04 +02:00
//Check notify threshold
2024-05-27 15:10:26 +02:00
if params.WazuhMessage.Parameters.Alert.Rule.Firedtimes%params.PriorityMap[i].NotifyThreshold != 0 {
log.Log("threshold not met")
log.CloseLogFile()
os.Exit(0)
}
2024-05-27 15:49:04 +02:00
//Set color based on config map
2024-05-27 15:10:26 +02:00
params.Color = params.PriorityMap[i].Color
2024-05-27 15:49:04 +02:00
//Check mention threshold
2024-05-27 15:10:26 +02:00
if params.WazuhMessage.Parameters.Alert.Rule.Firedtimes >= params.PriorityMap[i].MentionThreshold {
params.Mention = "@here"
}
params.Priority = 5 - i
}
}
log.Log("Wazuh data loaded")
2024-05-27 15:49:04 +02:00
//Filter messages based on rules defined in config
2024-05-27 15:10:26 +02:00
Filter(params)
return params
}