2024-05-08 01:56:48 +02:00
|
|
|
package notification
|
|
|
|
|
|
|
|
|
|
import (
|
2024-05-27 11:36:33 +02:00
|
|
|
"encoding/json"
|
2024-05-08 01:56:48 +02:00
|
|
|
"net/http"
|
|
|
|
|
"os"
|
2024-05-27 11:36:33 +02:00
|
|
|
"slices"
|
2024-05-08 01:56:48 +02:00
|
|
|
"strconv"
|
|
|
|
|
"strings"
|
|
|
|
|
"time"
|
|
|
|
|
"wazuh-notify/types"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func SendNtfy(params types.Params) {
|
|
|
|
|
|
2024-05-27 11:36:33 +02:00
|
|
|
var payload string
|
|
|
|
|
|
|
|
|
|
if slices.Contains(strings.Split(params.FullAlert, ","), "discord") {
|
|
|
|
|
fullAlert, _ := json.MarshalIndent(params.WazuhMessage, "", " ")
|
|
|
|
|
fullAlertString := strings.ReplaceAll(string(fullAlert), `"`, "")
|
|
|
|
|
fullAlertString = strings.ReplaceAll(fullAlertString, "{", "")
|
|
|
|
|
fullAlertString = strings.ReplaceAll(fullAlertString, "}", "")
|
|
|
|
|
fullAlertString = strings.ReplaceAll(fullAlertString, "[", "")
|
|
|
|
|
fullAlertString = strings.ReplaceAll(fullAlertString, "]", "")
|
|
|
|
|
fullAlertString = strings.ReplaceAll(fullAlertString, " ,", "")
|
|
|
|
|
|
|
|
|
|
payload = "\n\n ```" +
|
|
|
|
|
fullAlertString +
|
|
|
|
|
"```"
|
|
|
|
|
} else {
|
|
|
|
|
payload = time.Now().Format(time.RFC3339) + "\n\n" +
|
|
|
|
|
"Agent: " + params.WazuhMessage.Parameters.Alert.Agent.Name + "\n" +
|
|
|
|
|
"Event id: " + params.WazuhMessage.Parameters.Alert.Rule.ID + "\n" +
|
|
|
|
|
"Description: " + params.WazuhMessage.Parameters.Alert.Rule.Description + "\n" +
|
|
|
|
|
"Threat level: " + strconv.Itoa(params.WazuhMessage.Parameters.Alert.Rule.Level) + "\n" +
|
|
|
|
|
"Times fired: " + strconv.Itoa(params.WazuhMessage.Parameters.Alert.Rule.Firedtimes) + "\n"
|
|
|
|
|
}
|
2024-05-08 01:56:48 +02:00
|
|
|
|
|
|
|
|
req, _ := http.NewRequest("POST", os.Getenv("NTFY_URL"), strings.NewReader(payload))
|
|
|
|
|
req.Header.Set("Content-Type", "text/plain")
|
|
|
|
|
|
|
|
|
|
if params.Sender != "" {
|
|
|
|
|
req.Header.Add("Title", params.Sender)
|
|
|
|
|
}
|
|
|
|
|
if params.Tags != "" {
|
|
|
|
|
req.Header.Add("Tags", params.Tags)
|
|
|
|
|
}
|
|
|
|
|
if params.Click != "" {
|
|
|
|
|
req.Header.Add("Click", params.Click)
|
|
|
|
|
}
|
|
|
|
|
if params.Priority != 0 {
|
|
|
|
|
req.Header.Add("Priority", strconv.Itoa(params.Priority))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
http.DefaultClient.Do(req)
|
|
|
|
|
}
|