Merge remote-tracking branch 'origin/master'
# Conflicts: # wazuh-notify-go/wazuh-notify-config.yaml
This commit is contained in:
commit
bff328cfcd
@ -20,6 +20,18 @@ func OpenLogFile(BasePath string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CloseLogFile() {
|
||||||
|
_, err := logFile.WriteString(
|
||||||
|
"\n\n#######################################\n## CLOSE ##" +
|
||||||
|
"\n" + time.Now().String() +
|
||||||
|
"\n#######################################\n",
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
logFile.Close()
|
||||||
|
}
|
||||||
|
|
||||||
func Log(message string) {
|
func Log(message string) {
|
||||||
if _, err := logFile.WriteString("\n" + message + ": " + time.Now().String()); err != nil {
|
if _, err := logFile.WriteString("\n" + message + ": " + time.Now().String()); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|||||||
@ -20,4 +20,5 @@ func main() {
|
|||||||
notification.SendNtfy(inputParams)
|
notification.SendNtfy(inputParams)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
log.CloseLogFile()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import (
|
|||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"runtime"
|
"strings"
|
||||||
"wazuh-notify/log"
|
"wazuh-notify/log"
|
||||||
"wazuh-notify/types"
|
"wazuh-notify/types"
|
||||||
)
|
)
|
||||||
@ -16,33 +16,31 @@ import (
|
|||||||
var inputParams types.Params
|
var inputParams types.Params
|
||||||
var configParams types.Params
|
var configParams types.Params
|
||||||
var wazuhData types.WazuhMessage
|
var wazuhData types.WazuhMessage
|
||||||
var BasePath string
|
|
||||||
|
|
||||||
func InitNotify() types.Params {
|
func InitNotify() types.Params {
|
||||||
_, currentFile, _, _ := runtime.Caller(1)
|
BaseFilePath, _ := os.Executable()
|
||||||
|
BaseDirPath := path.Dir(BaseFilePath)
|
||||||
|
|
||||||
BasePath = path.Dir(currentFile)
|
log.OpenLogFile(BaseDirPath)
|
||||||
|
|
||||||
log.OpenLogFile(BasePath)
|
err := godotenv.Load(path.Join(BaseDirPath, "../../etc/.env"))
|
||||||
|
|
||||||
err := godotenv.Load(path.Join(BasePath, "../../etc/.env"))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Log("env failed to load")
|
log.Log("env failed to load")
|
||||||
godotenv.Load(path.Join(BasePath, ".env"))
|
godotenv.Load(path.Join(BaseDirPath, ".env"))
|
||||||
} else {
|
} else {
|
||||||
log.Log("env loaded")
|
log.Log("env loaded")
|
||||||
}
|
}
|
||||||
|
|
||||||
wazuhInput()
|
yamlFile, err := os.ReadFile(path.Join(BaseDirPath, "../../etc/wazuh-notify-config.yaml"))
|
||||||
|
|
||||||
yamlFile, err := os.ReadFile(path.Join(BasePath, "../../etc/wazuh-notify-config.yaml"))
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Log("yaml failed to load")
|
log.Log("yaml failed to load")
|
||||||
yamlFile, err = os.ReadFile(path.Join(BasePath, "wazuh-notify-config.yaml"))
|
yamlFile, err = os.ReadFile(path.Join(BaseDirPath, "wazuh-notify-config.yaml"))
|
||||||
}
|
}
|
||||||
yaml.Unmarshal(yamlFile, &configParams)
|
yaml.Unmarshal(yamlFile, &configParams)
|
||||||
|
|
||||||
log.Log("yaml loaded")
|
log.Log("yaml loaded")
|
||||||
|
configParamString, _ := json.Marshal(configParams)
|
||||||
|
log.Log(string(configParamString))
|
||||||
|
|
||||||
flag.StringVar(&inputParams.Url, "url", "", "is the webhook URL of the Discord server. It is stored in .env.")
|
flag.StringVar(&inputParams.Url, "url", "", "is the webhook URL of the Discord server. It is stored in .env.")
|
||||||
flag.StringVar(&inputParams.Click, "click", configParams.Click, "is a link (URL) that can be followed by tapping/clicking inside the message. Default is https://google.com.")
|
flag.StringVar(&inputParams.Click, "click", configParams.Click, "is a link (URL) that can be followed by tapping/clicking inside the message. Default is https://google.com.")
|
||||||
@ -54,8 +52,13 @@ func InitNotify() types.Params {
|
|||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
log.Log("params loaded")
|
log.Log("params loaded")
|
||||||
|
inputParamString, _ := json.Marshal(inputParams)
|
||||||
|
log.Log(string(inputParamString))
|
||||||
|
|
||||||
inputParams.Targets = configParams.Targets
|
inputParams.Targets = configParams.Targets
|
||||||
|
|
||||||
|
wazuhInput()
|
||||||
|
|
||||||
return inputParams
|
return inputParams
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +67,13 @@ func wazuhInput() {
|
|||||||
|
|
||||||
json.NewDecoder(reader).Decode(&wazuhData)
|
json.NewDecoder(reader).Decode(&wazuhData)
|
||||||
|
|
||||||
mapPriority()
|
inputParams.Priority = mapPriority()
|
||||||
|
|
||||||
|
inputParams.Tags += strings.Join(wazuhData.Parameters.Alert.Rule.Groups, ",")
|
||||||
|
|
||||||
inputParams.WazuhMessage = wazuhData
|
inputParams.WazuhMessage = wazuhData
|
||||||
|
|
||||||
|
log.Log("Wazuh data loaded")
|
||||||
|
inputParamString, _ := json.Marshal(inputParams)
|
||||||
|
log.Log(string(inputParamString))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,20 +2,21 @@ package services
|
|||||||
|
|
||||||
import "slices"
|
import "slices"
|
||||||
|
|
||||||
func mapPriority() {
|
func mapPriority() int {
|
||||||
if slices.Contains(configParams.Priority1, wazuhData.Parameters.Alert.Rule.Level) {
|
if slices.Contains(configParams.Priority1, wazuhData.Parameters.Alert.Rule.Level) {
|
||||||
inputParams.Priority = wazuhData.Parameters.Alert.Rule.Level
|
return 1
|
||||||
}
|
}
|
||||||
if slices.Contains(configParams.Priority2, wazuhData.Parameters.Alert.Rule.Level) {
|
if slices.Contains(configParams.Priority2, wazuhData.Parameters.Alert.Rule.Level) {
|
||||||
inputParams.Priority = wazuhData.Parameters.Alert.Rule.Level
|
return 2
|
||||||
}
|
}
|
||||||
if slices.Contains(configParams.Priority3, wazuhData.Parameters.Alert.Rule.Level) {
|
if slices.Contains(configParams.Priority3, wazuhData.Parameters.Alert.Rule.Level) {
|
||||||
inputParams.Priority = wazuhData.Parameters.Alert.Rule.Level
|
return 3
|
||||||
}
|
}
|
||||||
if slices.Contains(configParams.Priority4, wazuhData.Parameters.Alert.Rule.Level) {
|
if slices.Contains(configParams.Priority4, wazuhData.Parameters.Alert.Rule.Level) {
|
||||||
inputParams.Priority = wazuhData.Parameters.Alert.Rule.Level
|
return 4
|
||||||
}
|
}
|
||||||
if slices.Contains(configParams.Priority5, wazuhData.Parameters.Alert.Rule.Level) {
|
if slices.Contains(configParams.Priority5, wazuhData.Parameters.Alert.Rule.Level) {
|
||||||
inputParams.Priority = wazuhData.Parameters.Alert.Rule.Level
|
return 5
|
||||||
}
|
}
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user