2024-05-27 11:36:33 +02:00
|
|
|
package notification
|
2024-05-27 11:44:24 +02:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bytes"
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"log"
|
|
|
|
|
"net/http"
|
|
|
|
|
"os"
|
|
|
|
|
"strconv"
|
2024-05-27 14:16:50 +02:00
|
|
|
"wazuh-notify/services"
|
2024-05-27 11:44:24 +02:00
|
|
|
"wazuh-notify/types"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func SendSlack(params types.Params) {
|
|
|
|
|
|
2024-05-27 14:16:50 +02:00
|
|
|
message := types.SlackMessage{
|
|
|
|
|
Text: services.BuildMessage(params, "slack", params.MarkdownEmphasis.Slack) +
|
2024-05-27 13:48:08 +02:00
|
|
|
"*Priority:* " + strconv.Itoa(params.Priority) + "\n" +
|
|
|
|
|
"*Tags:* " + params.Tags + "\n\n" +
|
2024-05-27 14:16:50 +02:00
|
|
|
params.General.Click,
|
2024-05-27 13:48:08 +02:00
|
|
|
}
|
2024-05-27 11:44:24 +02:00
|
|
|
|
|
|
|
|
payload := new(bytes.Buffer)
|
|
|
|
|
|
|
|
|
|
err := json.NewEncoder(payload).Encode(message)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_, err = http.Post(os.Getenv("SLACK_URL"), "application/json", payload)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatalf("An Error Occured %v", err)
|
|
|
|
|
}
|
|
|
|
|
}
|