slack added
This commit is contained in:
parent
1544ac351e
commit
69b0c95193
@ -18,7 +18,10 @@ func main() {
|
|||||||
case "ntfy":
|
case "ntfy":
|
||||||
log.Log(target)
|
log.Log(target)
|
||||||
notification.SendNtfy(inputParams)
|
notification.SendNtfy(inputParams)
|
||||||
|
case "slack":
|
||||||
|
log.Log(target)
|
||||||
|
notification.SendSlack(inputParams)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.CloseLogFile()
|
log.CloseLogFile()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1 +1,73 @@
|
|||||||
package notification
|
package notification
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"slices"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
"wazuh-notify/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func SendSlack(params types.Params) {
|
||||||
|
|
||||||
|
var embedDescription string
|
||||||
|
|
||||||
|
if slices.Contains(strings.Split(params.FullAlert, ","), "slack") {
|
||||||
|
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, " ,", "")
|
||||||
|
|
||||||
|
embedDescription = "\n\n ```" +
|
||||||
|
fullAlertString +
|
||||||
|
"```\n\n" +
|
||||||
|
"Priority: " + strconv.Itoa(params.Priority) + "\n" +
|
||||||
|
"Tags: " + params.Tags + "\n\n" +
|
||||||
|
params.Click
|
||||||
|
} else {
|
||||||
|
embedDescription = "\n\n" +
|
||||||
|
"**Timestamp: **" + time.Now().Format(time.DateTime) + "\n" +
|
||||||
|
"**Agent:** " + params.WazuhMessage.Parameters.Alert.Agent.Name + "\n" +
|
||||||
|
"**Event id:** " + params.WazuhMessage.Parameters.Alert.Rule.ID + "\n" +
|
||||||
|
"**Rule:** " + params.WazuhMessage.Parameters.Alert.Rule.Description + "\n" +
|
||||||
|
"**Description: **" + params.WazuhMessage.Parameters.Alert.FullLog + "\n" +
|
||||||
|
"**Threat level:** " + strconv.Itoa(params.WazuhMessage.Parameters.Alert.Rule.Level) + "\n" +
|
||||||
|
"**Times fired:** " + strconv.Itoa(params.WazuhMessage.Parameters.Alert.Rule.Firedtimes) +
|
||||||
|
"\n\n" +
|
||||||
|
"Priority: " + strconv.Itoa(params.Priority) + "\n" +
|
||||||
|
"Tags: " + params.Tags + "\n\n" +
|
||||||
|
params.Click
|
||||||
|
}
|
||||||
|
|
||||||
|
message := types.Message{
|
||||||
|
Username: params.Sender,
|
||||||
|
Content: params.Mention,
|
||||||
|
Embeds: []types.Embed{
|
||||||
|
{
|
||||||
|
Title: params.Sender,
|
||||||
|
Description: embedDescription,
|
||||||
|
Color: params.Color,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user