file location fix
This commit is contained in:
parent
f4a66df0f6
commit
e1b005ce19
@ -2,13 +2,18 @@ package log
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"time"
|
"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) {
|
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)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,12 +22,28 @@ func SendDiscord(params types.Params) {
|
|||||||
"Tags: " + params.Tags + "\n\n" +
|
"Tags: " + params.Tags + "\n\n" +
|
||||||
params.Click
|
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{
|
message := types.Message{
|
||||||
Username: params.Sender,
|
Username: params.Sender,
|
||||||
Embeds: []types.Embed{
|
Embeds: []types.Embed{
|
||||||
{
|
{
|
||||||
Title: params.Sender,
|
Title: params.Sender,
|
||||||
Description: embedDescription,
|
Description: embedDescription,
|
||||||
|
Color: color,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,6 +7,8 @@ import (
|
|||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
|
"runtime"
|
||||||
"wazuh-notify/log"
|
"wazuh-notify/log"
|
||||||
"wazuh-notify/types"
|
"wazuh-notify/types"
|
||||||
)
|
)
|
||||||
@ -14,18 +16,30 @@ 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 {
|
||||||
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 {
|
if err != nil {
|
||||||
log.Log("env failed to load")
|
log.Log("env failed to load")
|
||||||
|
godotenv.Load(path.Join(BasePath, "/.env"))
|
||||||
} else {
|
} else {
|
||||||
log.Log("env loaded")
|
log.Log("env loaded")
|
||||||
}
|
}
|
||||||
|
|
||||||
wazuhInput()
|
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)
|
yaml.Unmarshal(yamlFile, &configParams)
|
||||||
|
|
||||||
log.Log("yaml loaded")
|
log.Log("yaml loaded")
|
||||||
@ -39,7 +53,7 @@ func InitNotify() types.Params {
|
|||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
log.Log("yaml loaded")
|
log.Log("params loaded")
|
||||||
inputParams.Targets = configParams.Targets
|
inputParams.Targets = configParams.Targets
|
||||||
|
|
||||||
return inputParams
|
return inputParams
|
||||||
|
|||||||
@ -25,5 +25,5 @@ type Message struct {
|
|||||||
type Embed struct {
|
type Embed struct {
|
||||||
Title string `json:"title,omitempty"`
|
Title string `json:"title,omitempty"`
|
||||||
Description string `json:"description,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