ntfy enter
refactor auto types refactor
This commit is contained in:
parent
2bc675b150
commit
ba49467acf
@ -29,7 +29,7 @@ func CloseLogFile() {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
logFile.Close()
|
||||
logFile.Close()
|
||||
}
|
||||
|
||||
func Log(message string) {
|
||||
|
||||
@ -6,7 +6,6 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"wazuh-notify/services"
|
||||
"wazuh-notify/types"
|
||||
)
|
||||
@ -14,7 +13,6 @@ import (
|
||||
func SendDiscord(params types.Params) {
|
||||
|
||||
embedDescription := services.BuildMessage(params, "discord", params.MarkdownEmphasis.Discord) +
|
||||
"**Priority:** " + strconv.Itoa(params.Priority) + "\n" +
|
||||
"**Tags:** " + params.Tags + "\n\n" +
|
||||
params.General.Click
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@ func SendNtfy(params types.Params) {
|
||||
req, _ := http.NewRequest(
|
||||
"POST",
|
||||
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")
|
||||
|
||||
|
||||
@ -6,7 +6,6 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
"wazuh-notify/services"
|
||||
"wazuh-notify/types"
|
||||
)
|
||||
@ -15,7 +14,6 @@ func SendSlack(params types.Params) {
|
||||
|
||||
message := types.SlackMessage{
|
||||
Text: services.BuildMessage(params, "slack", params.MarkdownEmphasis.Slack) +
|
||||
"*Priority:* " + strconv.Itoa(params.Priority) + "\n" +
|
||||
"*Tags:* " + params.Tags + "\n\n" +
|
||||
params.General.Click,
|
||||
}
|
||||
|
||||
@ -80,7 +80,7 @@ func wazuhInput() {
|
||||
|
||||
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 inputParams.WazuhMessage.Parameters.Alert.Rule.Firedtimes%inputParams.PriorityMap[i].NotifyThreshold != 0 {
|
||||
os.Exit(0)
|
||||
|
||||
@ -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("%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) +
|
||||
"\n\n"
|
||||
"\n\n" +
|
||||
fmt.Sprintf("%sPriority:%s ", emphasis, emphasis) + strconv.Itoa(params.Priority) + "\n"
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
14
wazuh-notify-go/types/discord.go
Normal file
14
wazuh-notify-go/types/discord.go
Normal 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"`
|
||||
}
|
||||
1
wazuh-notify-go/types/ntfy.go
Normal file
1
wazuh-notify-go/types/ntfy.go
Normal file
@ -0,0 +1 @@
|
||||
package types
|
||||
5
wazuh-notify-go/types/slack.go
Normal file
5
wazuh-notify-go/types/slack.go
Normal file
@ -0,0 +1,5 @@
|
||||
package types
|
||||
|
||||
type SlackMessage struct {
|
||||
Text string `json:"text,omitempty"`
|
||||
}
|
||||
@ -31,22 +31,3 @@ type MarkdownEmphasis struct {
|
||||
Ntfy string `toml:"ntfy"`
|
||||
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"`
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user