file location fix
This commit is contained in:
parent
f4a66df0f6
commit
e1b005ce19
@ -2,13 +2,18 @@ package log
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path"
|
||||
"time"
|
||||
)
|
||||
|
||||
var f, _ = os.OpenFile("active-responses.log", os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
|
||||
var logFile *os.File
|
||||
|
||||
func OpenLogFile(BasePath string) {
|
||||
logFile, _ = os.OpenFile(path.Join(BasePath, "../../log/active-responses.log"), os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
|
||||
}
|
||||
|
||||
func Log(message string) {
|
||||
if _, err := f.WriteString("\n" + time.Now().Format(time.DateTime) + message); err != nil {
|
||||
if _, err := logFile.WriteString("\n" + message + ": " + time.Now().String()); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,12 +22,28 @@ func SendDiscord(params types.Params) {
|
||||
"Tags: " + params.Tags + "\n\n" +
|
||||
params.Click
|
||||
|
||||
var color int
|
||||
|
||||
switch params.Priority {
|
||||
case 1:
|
||||
color = 0x339900
|
||||
case 2:
|
||||
color = 0x99cc33
|
||||
case 3:
|
||||
color = 0xffcc00
|
||||
case 4:
|
||||
color = 0xff9966
|
||||
case 5:
|
||||
color = 0xcc3300
|
||||
}
|
||||
|
||||
message := types.Message{
|
||||
Username: params.Sender,
|
||||
Embeds: []types.Embed{
|
||||
{
|
||||
Title: params.Sender,
|
||||
Description: embedDescription,
|
||||
Color: color,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@ -7,6 +7,8 @@ import (
|
||||
"github.com/joho/godotenv"
|
||||
"gopkg.in/yaml.v2"
|
||||
"os"
|
||||
"path"
|
||||
"runtime"
|
||||
"wazuh-notify/log"
|
||||
"wazuh-notify/types"
|
||||
)
|
||||
@ -14,18 +16,30 @@ import (
|
||||
var inputParams types.Params
|
||||
var configParams types.Params
|
||||
var wazuhData types.WazuhMessage
|
||||
var BasePath string
|
||||
|
||||
func InitNotify() types.Params {
|
||||
err := godotenv.Load()
|
||||
_, currentFile, _, _ := runtime.Caller(1)
|
||||
|
||||
BasePath = path.Dir(currentFile)
|
||||
|
||||
log.OpenLogFile(BasePath)
|
||||
|
||||
err := godotenv.Load(path.Join(BasePath, "../../etc/.env"))
|
||||
if err != nil {
|
||||
log.Log("env failed to load")
|
||||
godotenv.Load(path.Join(BasePath, "/.env"))
|
||||
} else {
|
||||
log.Log("env loaded")
|
||||
}
|
||||
|
||||
wazuhInput()
|
||||
|
||||
yamlFile, err := os.ReadFile("./config.yaml")
|
||||
yamlFile, err := os.ReadFile(path.Join(BasePath, "../../etc/config.yaml"))
|
||||
if err != nil {
|
||||
log.Log("yaml failed to load")
|
||||
yamlFile, err = os.ReadFile(path.Join(BasePath, "config.yaml"))
|
||||
}
|
||||
yaml.Unmarshal(yamlFile, &configParams)
|
||||
|
||||
log.Log("yaml loaded")
|
||||
@ -39,7 +53,7 @@ func InitNotify() types.Params {
|
||||
|
||||
flag.Parse()
|
||||
|
||||
log.Log("yaml loaded")
|
||||
log.Log("params loaded")
|
||||
inputParams.Targets = configParams.Targets
|
||||
|
||||
return inputParams
|
||||
|
||||
@ -25,5 +25,5 @@ type Message struct {
|
||||
type Embed struct {
|
||||
Title string `json:"title,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Color string `json:"color,omitempty"`
|
||||
Color int `json:"color,omitempty"`
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user