ntfy enter

refactor auto
types refactor
This commit is contained in:
darius 2024-05-27 14:47:18 +02:00
parent 2bc675b150
commit ba49467acf
10 changed files with 25 additions and 27 deletions

View File

@ -29,7 +29,7 @@ func CloseLogFile() {
if err != nil { if err != nil {
panic(err) panic(err)
} }
logFile.Close() logFile.Close()
} }
func Log(message string) { func Log(message string) {

View File

@ -6,7 +6,6 @@ import (
"log" "log"
"net/http" "net/http"
"os" "os"
"strconv"
"wazuh-notify/services" "wazuh-notify/services"
"wazuh-notify/types" "wazuh-notify/types"
) )
@ -14,7 +13,6 @@ import (
func SendDiscord(params types.Params) { func SendDiscord(params types.Params) {
embedDescription := services.BuildMessage(params, "discord", params.MarkdownEmphasis.Discord) + embedDescription := services.BuildMessage(params, "discord", params.MarkdownEmphasis.Discord) +
"**Priority:** " + strconv.Itoa(params.Priority) + "\n" +
"**Tags:** " + params.Tags + "\n\n" + "**Tags:** " + params.Tags + "\n\n" +
params.General.Click params.General.Click

View File

@ -14,7 +14,7 @@ func SendNtfy(params types.Params) {
req, _ := http.NewRequest( req, _ := http.NewRequest(
"POST", "POST",
os.Getenv("NTFY_URL"), os.Getenv("NTFY_URL"),
strings.NewReader(services.BuildMessage(params, "ntfy", params.MarkdownEmphasis.Ntfy))) strings.NewReader(" "+services.BuildMessage(params, "ntfy", params.MarkdownEmphasis.Ntfy)))
req.Header.Set("Content-Type", "text/markdown") req.Header.Set("Content-Type", "text/markdown")

View File

@ -6,7 +6,6 @@ import (
"log" "log"
"net/http" "net/http"
"os" "os"
"strconv"
"wazuh-notify/services" "wazuh-notify/services"
"wazuh-notify/types" "wazuh-notify/types"
) )
@ -15,7 +14,6 @@ func SendSlack(params types.Params) {
message := types.SlackMessage{ message := types.SlackMessage{
Text: services.BuildMessage(params, "slack", params.MarkdownEmphasis.Slack) + Text: services.BuildMessage(params, "slack", params.MarkdownEmphasis.Slack) +
"*Priority:* " + strconv.Itoa(params.Priority) + "\n" +
"*Tags:* " + params.Tags + "\n\n" + "*Tags:* " + params.Tags + "\n\n" +
params.General.Click, params.General.Click,
} }

View File

@ -80,7 +80,7 @@ func wazuhInput() {
inputParams.WazuhMessage = wazuhData inputParams.WazuhMessage = wazuhData
for i, _ := range configParams.PriorityMap { for i := range configParams.PriorityMap {
if slices.Contains(configParams.PriorityMap[i].ThreatMap, wazuhData.Parameters.Alert.Rule.Level) { if slices.Contains(configParams.PriorityMap[i].ThreatMap, wazuhData.Parameters.Alert.Rule.Level) {
if inputParams.WazuhMessage.Parameters.Alert.Rule.Firedtimes%inputParams.PriorityMap[i].NotifyThreshold != 0 { if inputParams.WazuhMessage.Parameters.Alert.Rule.Firedtimes%inputParams.PriorityMap[i].NotifyThreshold != 0 {
os.Exit(0) os.Exit(0)

View File

@ -33,7 +33,8 @@ func BuildMessage(params types.Params, target string, emphasis string) string {
fmt.Sprintf("%sDescription:%s ", emphasis, emphasis) + params.WazuhMessage.Parameters.Alert.FullLog + "\n" + fmt.Sprintf("%sDescription:%s ", emphasis, emphasis) + params.WazuhMessage.Parameters.Alert.FullLog + "\n" +
fmt.Sprintf("%sThreat level:%s ", emphasis, emphasis) + strconv.Itoa(params.WazuhMessage.Parameters.Alert.Rule.Level) + "\n" + fmt.Sprintf("%sThreat level:%s ", emphasis, emphasis) + strconv.Itoa(params.WazuhMessage.Parameters.Alert.Rule.Level) + "\n" +
fmt.Sprintf("%sTimes fired:%s ", emphasis, emphasis) + strconv.Itoa(params.WazuhMessage.Parameters.Alert.Rule.Firedtimes) + fmt.Sprintf("%sTimes fired:%s ", emphasis, emphasis) + strconv.Itoa(params.WazuhMessage.Parameters.Alert.Rule.Firedtimes) +
"\n\n" "\n\n" +
fmt.Sprintf("%sPriority:%s ", emphasis, emphasis) + strconv.Itoa(params.Priority) + "\n"
} }
} }

View File

@ -0,0 +1,14 @@
package types
type DiscordMessage struct {
Username string `json:"username,omitempty"`
AvatarUrl string `json:"avatar_url,omitempty"`
Content string `json:"content,omitempty"`
Embeds []Embed `json:"embeds,omitempty"`
}
type Embed struct {
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Color int `json:"color,omitempty"`
}

View File

@ -0,0 +1 @@
package types

View File

@ -0,0 +1,5 @@
package types
type SlackMessage struct {
Text string `json:"text,omitempty"`
}

View File

@ -31,22 +31,3 @@ type MarkdownEmphasis struct {
Ntfy string `toml:"ntfy"` Ntfy string `toml:"ntfy"`
Discord string `toml:"discord"` Discord string `toml:"discord"`
} }
// Discord
type DiscordMessage struct {
Username string `json:"username,omitempty"`
AvatarUrl string `json:"avatar_url,omitempty"`
Content string `json:"content,omitempty"`
Embeds []Embed `json:"embeds,omitempty"`
}
type Embed struct {
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Color int `json:"color,omitempty"`
}
// slack
type SlackMessage struct {
Text string `json:"text,omitempty"`
}