implementing log manager
parent
2e2cfb69a3
commit
bbea663825
1
main.go
1
main.go
|
@ -59,7 +59,6 @@ func init() {
|
|||
createGlobalRequirementsTxtIfNotExists()
|
||||
|
||||
utils.ValidatorInit()
|
||||
logger.InitLanguageLogMessages()
|
||||
grouptasks.InitLoadCategoryGroups()
|
||||
database.InitDatabase()
|
||||
systempermissions.CreateMasterRoleIfNotExist()
|
||||
|
|
|
@ -18,8 +18,6 @@ import (
|
|||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
|
||||
|
||||
type Notes struct {
|
||||
Image string
|
||||
Description string
|
||||
|
@ -107,18 +105,8 @@ func CreateEquipmentDocumentation(c *fiber.Ctx, body structs.CreateEquipmentDocu
|
|||
|
||||
database.DB.Create(&newEquipmentDocumentation)
|
||||
|
||||
logger.AddSystemLog(structs.LogMessage{
|
||||
Id: 27,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "userId", Value: userId},
|
||||
{Type: "equipmentDocumentationId", Value: newEquipmentDocumentation.Id},
|
||||
{Type: "stockItemId", Value: newEquipmentDocumentation.StockItemId},
|
||||
{Type: "type", Value: strconv.Itoa(int(body.Type))},
|
||||
{Type: "title", Value: body.Title},
|
||||
{Type: "description", Value: string(marshaledNotes)},
|
||||
},
|
||||
})
|
||||
logger.AddSystemLog("User %s has created the equipment document %s for the stock item %s with the title %s type %s description %s",
|
||||
userId, newEquipmentDocumentation.Id, newEquipmentDocumentation.StockItemId, body.Title, body.Type, string(marshaledNotes))
|
||||
|
||||
return c.JSON(fiber.Map{"message": "ok"})
|
||||
}
|
||||
|
@ -153,15 +141,8 @@ func GetEquipmentDocumentations(stockItemId string, query structs.PageQuery, c *
|
|||
stockItemId)
|
||||
}
|
||||
|
||||
logger.AddSystemLog(structs.LogMessage{
|
||||
Id: 30,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "userId", Value: c.Locals("userId").(string)},
|
||||
{Type: "stockItemId", Value: stockItemId},
|
||||
{Type: "statusCode", Value: strconv.Itoa(statusCode)},
|
||||
},
|
||||
})
|
||||
logger.AddSystemLog("User %s has viewed equipment documentation of the stock item %s. StatusCode: %s",
|
||||
c.Locals("userId").(string), stockItemId, strconv.Itoa(statusCode))
|
||||
|
||||
return c.JSON(structs.EquipmentDocumentationResponse{
|
||||
Status: statusCode,
|
||||
|
@ -264,17 +245,8 @@ func EditEquipmentDocumentation(c *fiber.Ctx, body structs.EditEquipmentDocument
|
|||
Notes: string(marshaledNotes),
|
||||
})
|
||||
|
||||
logger.AddSystemLog(structs.LogMessage{
|
||||
Id: 28,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "userId", Value: c.Locals("userId").(string)},
|
||||
{Type: "equipmentDocumentationId", Value: body.DocumentationId},
|
||||
{Type: "title", Value: body.Title},
|
||||
{Type: "type", Value: strconv.Itoa(int(body.Type))},
|
||||
{Type: "description", Value: string(marshaledNotes)},
|
||||
},
|
||||
})
|
||||
logger.AddSystemLog("User %s has updated the equipment document %s to title %s type %s and description %s",
|
||||
c.Locals("userId").(string), body.DocumentationId, body.Title, strconv.Itoa(int(body.Type)), string(marshaledNotes))
|
||||
|
||||
return c.JSON(fiber.Map{"message": "ok"})
|
||||
}
|
||||
|
|
|
@ -360,16 +360,8 @@ func HandleUserActionTaskStep(userId string, body map[string]interface{}) {
|
|||
|
||||
nextStep = step + 1
|
||||
|
||||
logger.AddGroupTasksLog(structs.LogMessage{
|
||||
Id: 8,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "userId", Value: userId},
|
||||
{Type: "action", Value: "resume"},
|
||||
{Type: "taskStepId", Value: taskStepId},
|
||||
{Type: "groupTaskId", Value: groupTaskId},
|
||||
},
|
||||
})
|
||||
logger.AddGroupTasksLog("User %s has executed action %s on step %s of groupTaskId %s",
|
||||
userId, "resume", taskStepId, groupTaskId)
|
||||
} else {
|
||||
groupTaskStep.Status = utils.GroupTasksStatusRunning
|
||||
}
|
||||
|
@ -401,30 +393,14 @@ func HandleUserActionTaskStep(userId string, body map[string]interface{}) {
|
|||
if action == UserActionTaskStepRepeat {
|
||||
runGroupTaskArgs.StartType = RunGroupTaskStartTypeTryAgain
|
||||
|
||||
logger.AddGroupTasksLog(structs.LogMessage{
|
||||
Id: 8,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "userId", Value: userId},
|
||||
{Type: "action", Value: "repeat"},
|
||||
{Type: "taskStepId", Value: taskStepId},
|
||||
{Type: "groupTaskId", Value: groupTaskId},
|
||||
},
|
||||
})
|
||||
logger.AddGroupTasksLog("User %s has executed action %s on step %s of groupTaskId %s",
|
||||
userId, "repeat", taskStepId, groupTaskId)
|
||||
} else if action == UserActionTaskStepUndo {
|
||||
runGroupTaskArgs.StartType = RunGroupTaskStartTypeUndo
|
||||
runGroupTaskArgs.TaskInputs = dbGroupTaskStep.Inputs
|
||||
|
||||
logger.AddGroupTasksLog(structs.LogMessage{
|
||||
Id: 8,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "userId", Value: userId},
|
||||
{Type: "action", Value: "undo"},
|
||||
{Type: "taskStepId", Value: taskStepId},
|
||||
{Type: "groupTaskId", Value: groupTaskId},
|
||||
},
|
||||
})
|
||||
logger.AddGroupTasksLog("User %s has executed action %s on step %s of groupTaskId %s",
|
||||
userId, "undo", taskStepId, groupTaskId)
|
||||
}
|
||||
|
||||
// run next task step
|
||||
|
@ -492,15 +468,8 @@ func RunGroupTask(args RunGroupTaskArgs) {
|
|||
|
||||
updateGroupTaskSteps(groupTaskStep, args.Category)
|
||||
|
||||
logger.AddGroupTasksLog(structs.LogMessage{
|
||||
Id: 5,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "taskStepId", Value: groupTaskStep.Id},
|
||||
{Type: "groupTaskId", Value: groupTaskStep.GroupTasksId},
|
||||
{Type: "status", Value: "input required"},
|
||||
},
|
||||
})
|
||||
logger.AddGroupTasksLog("Step %s of groupTaskId %s status set to %s",
|
||||
groupTaskStep.Id, groupTaskStep.GroupTasksId, "input required")
|
||||
return
|
||||
} else if len(args.TaskInputs) > 0 {
|
||||
commandArgs = append(commandArgs, args.TaskInputs)
|
||||
|
@ -565,27 +534,13 @@ func RunGroupTask(args RunGroupTaskArgs) {
|
|||
log.Error().Msgf("error exec command %s", err.Error())
|
||||
groupTaskStep.Status = utils.GroupTasksStatusFailed
|
||||
|
||||
logger.AddGroupTasksLog(structs.LogMessage{
|
||||
Id: 5,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "taskStepId", Value: groupTaskStep.Id},
|
||||
{Type: "groupTaskId", Value: groupTaskStep.GroupTasksId},
|
||||
{Type: "status", Value: "failed"},
|
||||
},
|
||||
})
|
||||
logger.AddGroupTasksLog("Step %s of groupTaskId %s status set to %s",
|
||||
groupTaskStep.Id, groupTaskStep.GroupTasksId, "failed")
|
||||
} else {
|
||||
groupTaskStep.Status = utils.GroupTasksStatusFinished
|
||||
|
||||
logger.AddGroupTasksLog(structs.LogMessage{
|
||||
Id: 5,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "taskStepId", Value: groupTaskStep.Id},
|
||||
{Type: "groupTaskId", Value: groupTaskStep.GroupTasksId},
|
||||
{Type: "status", Value: "finished"},
|
||||
},
|
||||
})
|
||||
logger.AddGroupTasksLog("Step %s of groupTaskId %s status set to %s",
|
||||
groupTaskStep.Id, groupTaskStep.GroupTasksId, "finished")
|
||||
}
|
||||
|
||||
fmt.Println(cmdLog)
|
||||
|
@ -681,14 +636,8 @@ func RunGroupTask(args RunGroupTaskArgs) {
|
|||
Status: utils.GroupTasksStatusFailed,
|
||||
}, args.Category)
|
||||
|
||||
logger.AddGroupTasksLog(structs.LogMessage{
|
||||
Id: 2,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "groupTaskId", Value: groupTaskStep.GroupTasksId},
|
||||
{Type: "status", Value: "failed"},
|
||||
},
|
||||
})
|
||||
logger.AddGroupTasksLog("GroupTaskId %s status set to %s",
|
||||
groupTaskStep.GroupTasksId, "failed")
|
||||
} else {
|
||||
prevStartType := args.StartType
|
||||
args.StartType = RunGroupTaskStartTypeNormal
|
||||
|
@ -701,43 +650,17 @@ func RunGroupTask(args RunGroupTaskArgs) {
|
|||
groupTaskStep.Inputs = " "
|
||||
groupTaskStep.Files = " "
|
||||
|
||||
logger.AddGroupTasksLog(structs.LogMessage{
|
||||
Id: 2,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "groupTaskId", Value: groupTaskStep.GroupTasksId},
|
||||
{Type: "status", Value: "Undo ended"},
|
||||
},
|
||||
})
|
||||
logger.AddGroupTasksLog("GroupTaskId %s status set to %s",
|
||||
groupTaskStep.GroupTasksId, "Undo ended")
|
||||
|
||||
logger.AddGroupTasksLog(structs.LogMessage{
|
||||
Id: 5,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "taskStepId", Value: groupTaskStep.Id},
|
||||
{Type: "groupTaskId", Value: groupTaskStep.GroupTasksId},
|
||||
{Type: "status", Value: "Undo ended"},
|
||||
},
|
||||
})
|
||||
logger.AddGroupTasksLog("Step %s of groupTaskId %s status set to %s",
|
||||
groupTaskStep.Id, groupTaskStep.GroupTasksId, "Undo ended")
|
||||
} else {
|
||||
logger.AddGroupTasksLog(structs.LogMessage{
|
||||
Id: 2,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "groupTaskId", Value: groupTaskStep.GroupTasksId},
|
||||
{Type: "status", Value: "paused"},
|
||||
},
|
||||
})
|
||||
logger.AddGroupTasksLog("GroupTaskId %s status set to %s",
|
||||
groupTaskStep.GroupTasksId, "paused")
|
||||
|
||||
logger.AddGroupTasksLog(structs.LogMessage{
|
||||
Id: 5,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "taskStepId", Value: groupTaskStep.Id},
|
||||
{Type: "groupTaskId", Value: groupTaskStep.GroupTasksId},
|
||||
{Type: "status", Value: "paused"},
|
||||
},
|
||||
})
|
||||
logger.AddGroupTasksLog("Step %s of groupTaskId %s status set to %s",
|
||||
groupTaskStep.Id, groupTaskStep.GroupTasksId, "paused")
|
||||
}
|
||||
|
||||
groupTaskStep.Status = status
|
||||
|
@ -757,14 +680,8 @@ func RunGroupTask(args RunGroupTaskArgs) {
|
|||
CurrentTasksStep: args.Step,
|
||||
}, args.Category)
|
||||
|
||||
logger.AddGroupTasksLog(structs.LogMessage{
|
||||
Id: 9,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "groupTaskId", Value: groupTaskStep.GroupTasksId},
|
||||
{Type: "step", Value: utils.MarshalJson(args.Step)},
|
||||
},
|
||||
})
|
||||
logger.AddGroupTasksLog("System has started step %s of groupTaskId %s",
|
||||
utils.MarshalJson(args.Step), groupTaskStep.GroupTasksId)
|
||||
|
||||
RunGroupTask(args)
|
||||
} else {
|
||||
|
@ -785,14 +702,7 @@ func groupTaskFinished(groupTasksId string, category string) {
|
|||
log.Error().Msgf("Failed to delete running task folder %s", err.Error())
|
||||
}
|
||||
|
||||
logger.AddGroupTasksLog(structs.LogMessage{
|
||||
Id: 2,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "groupTaskId", Value: groupTasksId},
|
||||
{Type: "status", Value: "finished"},
|
||||
},
|
||||
})
|
||||
logger.AddGroupTasksLog("GroupTaskId %s status set to %s", groupTasksId, "finished")
|
||||
}
|
||||
|
||||
// Updates group task and send it to websocket users
|
||||
|
@ -968,25 +878,13 @@ func StartGroupTask(userId string, groupTask structs.GroupTasks) {
|
|||
GlobalInputs: groupTask.GlobalInputs,
|
||||
})
|
||||
|
||||
logger.AddGroupTasksLog(structs.LogMessage{
|
||||
Id: 0,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "userId", Value: userId},
|
||||
{Type: "groupTaskId", Value: groupTask.Id},
|
||||
{Type: "groupTaskName", Value: groupTask.GroupName},
|
||||
},
|
||||
})
|
||||
logger.AddGroupTasksLog("User %s has started group task groupTaskId %s groupTaskName %s",
|
||||
userId, groupTask.Id, groupTask.GroupName)
|
||||
}
|
||||
|
||||
func InstallGlobalPythonPackages(userId string) {
|
||||
logger.AddGroupTasksLog(structs.LogMessage{
|
||||
Id: 13,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "userId", Value: userId},
|
||||
},
|
||||
})
|
||||
logger.AddGroupTasksLog("User %s has requested installing the global python packages",
|
||||
userId)
|
||||
|
||||
socketclients.BroadcastMessageToUsersWithPermissionAndTopic(
|
||||
utils.PermissionGroupTasksInstallGlobalPythonPackages,
|
||||
|
@ -997,13 +895,7 @@ func InstallGlobalPythonPackages(userId string) {
|
|||
|
||||
// check if requirements.txt exists
|
||||
if _, err := os.Stat(config.Cfg.FolderPaths.GroupTasksGroups + "requirements.txt"); errors.Is(err, os.ErrNotExist) {
|
||||
logger.AddGroupTasksLog(structs.LogMessage{
|
||||
Id: 14,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "error", Value: "requirements.txt not found"},
|
||||
},
|
||||
})
|
||||
logger.AddGroupTasksLog("Installing the global python packages failed. Error %s", "requirements.txt not found")
|
||||
|
||||
socketclients.BroadcastMessageToUsersWithPermissionAndTopic(
|
||||
utils.PermissionGroupTasksInstallGlobalPythonPackages,
|
||||
|
@ -1019,13 +911,7 @@ func InstallGlobalPythonPackages(userId string) {
|
|||
out, err := cmd.CombinedOutput()
|
||||
|
||||
if err != nil {
|
||||
logger.AddGroupTasksLog(structs.LogMessage{
|
||||
Id: 14,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "error", Value: err.Error()},
|
||||
},
|
||||
})
|
||||
logger.AddGroupTasksLog("Installing the global python packages failed. Error %s", err.Error())
|
||||
|
||||
socketclients.BroadcastMessageToUsersWithPermissionAndTopic(
|
||||
utils.PermissionGroupTasksInstallGlobalPythonPackages,
|
||||
|
@ -1036,13 +922,7 @@ func InstallGlobalPythonPackages(userId string) {
|
|||
return
|
||||
}
|
||||
|
||||
logger.AddGroupTasksLog(structs.LogMessage{
|
||||
Id: 15,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "log", Value: string(out)},
|
||||
},
|
||||
})
|
||||
logger.AddGroupTasksLog("Installation of the global python packages finished. Log %s", string(out))
|
||||
|
||||
socketclients.BroadcastMessageToUsersWithPermissionAndTopic(
|
||||
utils.PermissionGroupTasksInstallGlobalPythonPackages,
|
||||
|
@ -1053,15 +933,7 @@ func InstallGlobalPythonPackages(userId string) {
|
|||
}
|
||||
|
||||
func InstallPythonPackages(userId string, category string, groupId string) {
|
||||
logger.AddGroupTasksLog(structs.LogMessage{
|
||||
Id: 10,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "userId", Value: userId},
|
||||
{Type: "category", Value: category},
|
||||
{Type: "groupId", Value: groupId},
|
||||
},
|
||||
})
|
||||
logger.AddGroupTasksLog("User %s has requested installing python packages for groupId %s of category %s", userId, groupId, category)
|
||||
|
||||
messageBody := struct {
|
||||
Category string
|
||||
|
@ -1083,15 +955,8 @@ func InstallPythonPackages(userId string, category string, groupId string) {
|
|||
|
||||
// check if requirements.txt exists
|
||||
if _, err := os.Stat(config.Cfg.FolderPaths.GroupTasksGroups + groupId + "/requirements.txt"); errors.Is(err, os.ErrNotExist) {
|
||||
logger.AddGroupTasksLog(structs.LogMessage{
|
||||
Id: 11,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "category", Value: category},
|
||||
{Type: "groupId", Value: groupId},
|
||||
{Type: "error", Value: "requirements.txt not found"},
|
||||
},
|
||||
})
|
||||
logger.AddGroupTasksLog("Installing python packages for groupId %s of category %s failed. Error: %s",
|
||||
category, groupId, "requirements.txt not found")
|
||||
|
||||
socketclients.BroadcastMessageToUsersWithPermissionAndTopic(
|
||||
convertedXYPermission,
|
||||
|
@ -1108,15 +973,8 @@ func InstallPythonPackages(userId string, category string, groupId string) {
|
|||
out, err := cmd.CombinedOutput()
|
||||
|
||||
if err != nil {
|
||||
logger.AddGroupTasksLog(structs.LogMessage{
|
||||
Id: 11,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "category", Value: category},
|
||||
{Type: "groupId", Value: groupId},
|
||||
{Type: "error", Value: err.Error()},
|
||||
},
|
||||
})
|
||||
logger.AddGroupTasksLog("Installing python packages for groupId %s of category %s failed. Error: %s",
|
||||
category, groupId, err.Error())
|
||||
|
||||
socketclients.BroadcastMessageToUsersWithPermissionAndTopic(
|
||||
convertedXYPermission,
|
||||
|
@ -1128,15 +986,8 @@ func InstallPythonPackages(userId string, category string, groupId string) {
|
|||
return
|
||||
}
|
||||
|
||||
logger.AddGroupTasksLog(structs.LogMessage{
|
||||
Id: 12,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "category", Value: category},
|
||||
{Type: "groupId", Value: groupId},
|
||||
{Type: "log", Value: string(out)},
|
||||
},
|
||||
})
|
||||
logger.AddGroupTasksLog("Installing python packages for groupId %s of category %s finished. Log: %s",
|
||||
category, groupId, string(out))
|
||||
|
||||
socketclients.BroadcastMessageToUsersWithPermissionAndTopic(
|
||||
convertedXYPermission,
|
||||
|
|
|
@ -1,25 +1,20 @@
|
|||
package logger
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"jannex/admin-dashboard-backend/modules/config"
|
||||
"jannex/admin-dashboard-backend/modules/structs"
|
||||
"jannex/admin-dashboard-backend/modules/utils"
|
||||
"os"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
var systemLanguageLogMessages []structs.LanguageLogMessages
|
||||
var grouptasksLanguageLogMessages []structs.LanguageLogMessages
|
||||
//var systemLanguageLogMessages []structs.LanguageLogMessages
|
||||
//var grouptasksLanguageLogMessages []structs.LanguageLogMessages
|
||||
|
||||
func InitLogger() {
|
||||
zerolog.TimeFieldFormat = zerolog.TimeFormatUnix
|
||||
|
@ -35,14 +30,59 @@ func InitLogger() {
|
|||
}
|
||||
}
|
||||
|
||||
func AddSystemLog(logMessage structs.LogMessage) {
|
||||
addLog(logMessage, true)
|
||||
func getTime() string {
|
||||
currentTime := time.Now().UTC()
|
||||
|
||||
millisecondsSinceEpoch := currentTime.UnixNano() / int64(time.Millisecond)
|
||||
|
||||
return strconv.FormatInt(millisecondsSinceEpoch, 10) + " "
|
||||
}
|
||||
|
||||
func AddGroupTasksLog(logMessage structs.LogMessage) {
|
||||
addLog(logMessage, false)
|
||||
func AddSystemLog(format string, v ...any) {
|
||||
go LogManagerRequestClient(fiber.MethodPost, "http://localhost:50110/v1/log", LogManagerRequestBody{
|
||||
Type: "system",
|
||||
Logs: []string{"I " + getTime() + fmt.Sprintf(format, v...)}})
|
||||
}
|
||||
|
||||
func AddGroupTasksLog(format string, v ...any) {
|
||||
go LogManagerRequestClient(fiber.MethodPost, "http://localhost:50110/v1/log", LogManagerRequestBody{
|
||||
Type: "grouptasks",
|
||||
Logs: []string{"I " + getTime() + fmt.Sprintf(format, v...)}})
|
||||
}
|
||||
|
||||
type LogManagerRequestBody struct {
|
||||
Type string
|
||||
Logs []string
|
||||
}
|
||||
|
||||
func LogManagerRequestClient(requestMethod string, url string, body interface{}) {
|
||||
a := fiber.AcquireAgent()
|
||||
|
||||
req := a.Request()
|
||||
req.Header.SetMethod(requestMethod)
|
||||
req.SetRequestURI(url)
|
||||
req.Header.SetContentType("application/json")
|
||||
|
||||
reqestBodyBytes, err := json.Marshal(body)
|
||||
|
||||
if err != nil {
|
||||
log.Error().Msgf("Failed to marshal request body, err: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
req.SetBody(reqestBodyBytes)
|
||||
|
||||
if err := a.Parse(); err != nil {
|
||||
log.Error().Msgf("Failed to parse request, err: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
code, body, _ := a.Bytes()
|
||||
|
||||
log.Info().Msgf("Log manager request, code: %d, body: %s", code, body)
|
||||
}
|
||||
|
||||
/*
|
||||
func addLog(logMessage structs.LogMessage, systemLog bool) {
|
||||
year, month, day := time.Now().Date()
|
||||
|
||||
|
@ -157,7 +197,7 @@ func GetAllLogMessagesDates(systemLogs bool) []string {
|
|||
path = config.Cfg.FolderPaths.LogsGroupTasks
|
||||
}
|
||||
|
||||
files, err := ioutil.ReadDir(path)
|
||||
files, err := os.ReadDir(path)
|
||||
|
||||
if err != nil {
|
||||
log.Error().Msgf("Failed to read log messages directory %s", err.Error())
|
||||
|
@ -236,3 +276,4 @@ func readLanguageLogMessages(systemLogs bool) {
|
|||
grouptasksLanguageLogMessages = langLogMessages
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -2,8 +2,6 @@ package requestclient
|
|||
|
||||
import (
|
||||
"jannex/admin-dashboard-backend/modules/logger"
|
||||
"jannex/admin-dashboard-backend/modules/structs"
|
||||
"jannex/admin-dashboard-backend/modules/utils"
|
||||
"strconv"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
|
@ -33,14 +31,8 @@ func InvexApiRequestClient(requestMethod string, url string) (statusCode int, bo
|
|||
if code == 401 {
|
||||
log.Error().Msgf("invex not authorized, code: %d", code)
|
||||
|
||||
logger.AddSystemLog(structs.LogMessage{
|
||||
Id: 29,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "error", Value: "invex not authorized"},
|
||||
{Type: "statusCode", Value: strconv.Itoa(code)},
|
||||
},
|
||||
})
|
||||
logger.AddSystemLog("InvexApiRequestClient err: %s statusCode: %s",
|
||||
"invex not authorized", strconv.Itoa(code))
|
||||
|
||||
return code, nil, err
|
||||
}
|
||||
|
@ -48,14 +40,9 @@ func InvexApiRequestClient(requestMethod string, url string) (statusCode int, bo
|
|||
if code == 404 {
|
||||
log.Error().Msgf("Invex stock item not found, code: %d", code)
|
||||
|
||||
logger.AddSystemLog(structs.LogMessage{
|
||||
Id: 29,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "error", Value: "invex stock item not found"},
|
||||
{Type: "statusCode", Value: strconv.Itoa(code)},
|
||||
},
|
||||
})
|
||||
logger.AddSystemLog("InvexApiRequestClient err: %s statusCode: %s",
|
||||
"invex stock item not found", strconv.Itoa(code))
|
||||
|
||||
return code, nil, err
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ const (
|
|||
MaxRoleDescription = 80
|
||||
MaxEquipmentDocumentationTitleLength = "60"
|
||||
MaxEquipmentDocumentationNoteLength = 2000
|
||||
MaxNoficationTitleLength = "255"
|
||||
|
||||
LenHeaderXAuthorization = 36
|
||||
lenHeaderXAuthorization = "36"
|
||||
|
@ -156,6 +157,11 @@ var (
|
|||
"Title": "required,max=" + MaxEquipmentDocumentationTitleLength,
|
||||
"Notes": "required",
|
||||
}
|
||||
|
||||
notificationRules = map[string]string{
|
||||
"Type": "required,number",
|
||||
"Title": "required,max=" + MaxNoficationTitleLength,
|
||||
}
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
@ -52,4 +52,7 @@ func ValidatorInit() {
|
|||
structs.GetDocumentationEquipmentRequest{},
|
||||
structs.CreateEquipmentDocumentationRequest{},
|
||||
structs.EditEquipmentDocumentationRequest{})
|
||||
|
||||
Validate.RegisterStructValidationMapRules(notificationRules,
|
||||
structs.AddNotificationRequest{})
|
||||
}
|
||||
|
|
|
@ -51,20 +51,7 @@ func AddScanner(c *fiber.Ctx) error {
|
|||
Body: scanner,
|
||||
})
|
||||
|
||||
logger.AddSystemLog(structs.LogMessage{
|
||||
Id: 14,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{
|
||||
Type: "scannerId",
|
||||
Value: scanner.Id,
|
||||
},
|
||||
{
|
||||
Type: "scannerName",
|
||||
Value: scanner.Name,
|
||||
},
|
||||
},
|
||||
})
|
||||
logger.AddSystemLog("Scanner %s %s was registered", scanner.Id, scanner.Name)
|
||||
|
||||
return c.JSON(structs.ScannerResponse{Id: id, Session: session})
|
||||
}
|
||||
|
@ -102,20 +89,7 @@ func ScanResult(c *fiber.Ctx) error {
|
|||
Body: body.ScanResult,
|
||||
})
|
||||
|
||||
logger.AddSystemLog(structs.LogMessage{
|
||||
Id: 15,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{
|
||||
Type: "scannerId",
|
||||
Value: scannerId,
|
||||
},
|
||||
{
|
||||
Type: "scanResult",
|
||||
Value: body.ScanResult,
|
||||
},
|
||||
},
|
||||
})
|
||||
logger.AddSystemLog("Scanner %s has scanned %s", scannerId, body.ScanResult)
|
||||
|
||||
return c.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
@ -138,16 +112,7 @@ func DeleteScanner(c *fiber.Ctx) error {
|
|||
},
|
||||
})
|
||||
|
||||
logger.AddSystemLog(structs.LogMessage{
|
||||
Id: 16,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{
|
||||
Type: "scannerId",
|
||||
Value: scanner.Id,
|
||||
},
|
||||
},
|
||||
})
|
||||
logger.AddSystemLog("Scanner %s was deleted", scanner.Id)
|
||||
|
||||
return c.SendStatus(fiber.StatusOK)
|
||||
}
|
||||
|
|
|
@ -1,17 +1,6 @@
|
|||
package logger
|
||||
|
||||
import (
|
||||
"jannex/admin-dashboard-backend/modules/cache"
|
||||
"jannex/admin-dashboard-backend/modules/database"
|
||||
"jannex/admin-dashboard-backend/modules/grouptasks"
|
||||
"jannex/admin-dashboard-backend/modules/logger"
|
||||
"jannex/admin-dashboard-backend/modules/structs"
|
||||
"jannex/admin-dashboard-backend/modules/utils"
|
||||
"jannex/admin-dashboard-backend/socketclients"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
/*
|
||||
func GetSystemLog(c *fiber.Ctx) error {
|
||||
t := c.Query("type")
|
||||
date := c.Query("date")
|
||||
|
@ -31,15 +20,8 @@ func GetSystemLog(c *fiber.Ctx) error {
|
|||
logType = "System"
|
||||
}
|
||||
|
||||
logger.AddSystemLog(structs.LogMessage{
|
||||
Id: 17,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "userId", Value: c.Locals("userId").(string)},
|
||||
{Type: "logType", Value: logType},
|
||||
{Type: "logDate", Value: date},
|
||||
},
|
||||
})
|
||||
logger.AddSystemLog("User %s has viewed %s logs of the date %s",
|
||||
c.Locals("userId").(string), logType, date)
|
||||
|
||||
// / TODO: remove this by rendering the log message on backend site
|
||||
|
||||
|
@ -47,6 +29,8 @@ func GetSystemLog(c *fiber.Ctx) error {
|
|||
|
||||
database.DB.Find(&groupTasks)
|
||||
|
||||
return c.JSON([]string{})
|
||||
/*
|
||||
if t == "g" {
|
||||
// grouptasks logs
|
||||
return c.JSON(structs.LogMessageResponse{
|
||||
|
@ -69,5 +53,5 @@ func GetSystemLog(c *fiber.Ctx) error {
|
|||
CategoryGroups: cache.GetCategoryGroupsSorted(),
|
||||
GroupTasks: groupTasks,
|
||||
GroupTasksSteps: grouptasks.GetAllGroupTasksSteps(),
|
||||
})
|
||||
}
|
||||
}) */ /*
|
||||
} */
|
||||
|
|
|
@ -87,16 +87,7 @@ func UserLogin(c *fiber.Ctx) error {
|
|||
UserAgent: string(c.Context().UserAgent()),
|
||||
ExpiresAt: utils.GetSessionExpiresAtTime()})
|
||||
|
||||
logger.AddSystemLog(structs.LogMessage{
|
||||
Id: 19,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{
|
||||
Type: "userId",
|
||||
Value: user.Id,
|
||||
},
|
||||
},
|
||||
})
|
||||
logger.AddSystemLog("User %s has logged in", user.Id)
|
||||
|
||||
return c.JSON(structs.UserLoginResponse{Session: session})
|
||||
}
|
||||
|
@ -125,16 +116,7 @@ func UserLogout(c *fiber.Ctx) error {
|
|||
|
||||
socketclients.CloseAllUserSessionConnections(session)
|
||||
|
||||
logger.AddSystemLog(structs.LogMessage{
|
||||
Id: 20,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{
|
||||
Type: "userId",
|
||||
Value: c.Locals("userId").(string),
|
||||
},
|
||||
},
|
||||
})
|
||||
logger.AddSystemLog("User %s has logged out", c.Locals("userId").(string))
|
||||
|
||||
return c.SendStatus(fiber.StatusCreated)
|
||||
}
|
||||
|
|
|
@ -84,13 +84,7 @@ func UpdateAvatar(c *fiber.Ctx) error {
|
|||
},
|
||||
})
|
||||
|
||||
logger.AddSystemLog(structs.LogMessage{
|
||||
Id: 21,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "userId", Value: user.Id},
|
||||
},
|
||||
})
|
||||
logger.AddSystemLog("User %s has changed his avatar", user.Id)
|
||||
|
||||
return c.SaveFile(fileHeader, fmt.Sprintf("%savatars/%s", config.Cfg.FolderPaths.PublicStatic, fileName))
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"jannex/admin-dashboard-backend/modules/database"
|
||||
"jannex/admin-dashboard-backend/modules/logger"
|
||||
"jannex/admin-dashboard-backend/modules/structs"
|
||||
"jannex/admin-dashboard-backend/modules/utils"
|
||||
"jannex/admin-dashboard-backend/socketclients"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
|
@ -54,16 +53,7 @@ func SignOutSession(c *fiber.Ctx) error {
|
|||
|
||||
socketclients.UpdateUserSessionsForUser(userSession.UserId, userSession.Id)
|
||||
|
||||
logger.AddSystemLog(structs.LogMessage{
|
||||
Id: 22,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{
|
||||
Type: "userId",
|
||||
Value: c.Locals("userId").(string),
|
||||
},
|
||||
},
|
||||
})
|
||||
logger.AddSystemLog("User %s has logged out one of his account sessions", c.Locals("userId").(string))
|
||||
}
|
||||
|
||||
return c.JSON(fiber.Map{"status": "ok"})
|
||||
|
|
|
@ -45,6 +45,6 @@ func UserInfo(c *fiber.Ctx) error {
|
|||
Permissions: socketclients.GetPermissionsByRoleId(user.RoleId),
|
||||
AvailableCategories: categories,
|
||||
Users: socketclients.GetAllUsers(),
|
||||
TotalNotifications: notification.GetTotalNotifications(user.Id),
|
||||
TotalNotifications: notification.GetTotalNotifications(userId),
|
||||
})
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
adminarea "jannex/admin-dashboard-backend/routers/router/api/v1/adminArea"
|
||||
"jannex/admin-dashboard-backend/routers/router/api/v1/equipment"
|
||||
"jannex/admin-dashboard-backend/routers/router/api/v1/grouptasks"
|
||||
log "jannex/admin-dashboard-backend/routers/router/api/v1/logger"
|
||||
"jannex/admin-dashboard-backend/routers/router/api/v1/machines"
|
||||
"jannex/admin-dashboard-backend/routers/router/api/v1/notification"
|
||||
"jannex/admin-dashboard-backend/routers/router/api/v1/user"
|
||||
|
@ -40,8 +39,8 @@ func SetupRoutes(app *fiber.App) {
|
|||
//s.Post("/scan", scannerSessionValidation, jxscanner.ScanResult)
|
||||
//s.Delete("/", scannerSessionValidation, jxscanner.DeleteScanner)
|
||||
|
||||
l := v1.Group("/log")
|
||||
l.Get("/", requestAccessValidation, log.GetSystemLog)
|
||||
//l := v1.Group("/log")
|
||||
//l.Get("/", requestAccessValidation, log.GetSystemLog)
|
||||
|
||||
gs := v1.Group("/grouptasks")
|
||||
gs.Get("/:category", requestAccessValidation, grouptasks.GetGroupTasks)
|
||||
|
@ -106,13 +105,8 @@ func userApikeyTokenValidation(c *fiber.Ctx) error {
|
|||
// delete api key from database
|
||||
database.DB.Delete(&apiKey)
|
||||
|
||||
logger.AddSystemLog(structs.LogMessage{
|
||||
Id: 26,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "userId", Value: apiKey.UserId},
|
||||
},
|
||||
})
|
||||
logger.AddSystemLog("User %s has tried to use one of its api keys, but has no longer permission to do so",
|
||||
apiKey.UserId)
|
||||
|
||||
return fiber.ErrUnauthorized
|
||||
}
|
||||
|
@ -142,13 +136,7 @@ func userApikeyTokenValidation(c *fiber.Ctx) error {
|
|||
},
|
||||
})
|
||||
|
||||
logger.AddSystemLog(structs.LogMessage{
|
||||
Id: 25,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "userId", Value: apiKey.UserId},
|
||||
},
|
||||
})
|
||||
logger.AddSystemLog("User %s has used one of its api keys", apiKey.UserId)
|
||||
|
||||
return c.Next()
|
||||
}
|
||||
|
|
|
@ -415,13 +415,7 @@ func UpdateUserProfile(conn *websocket.Conn, changes map[string]interface{}) {
|
|||
// user has changed password - logout all his sessions
|
||||
CloseAndDeleteAllUserConnections(userId)
|
||||
|
||||
logger.AddSystemLog(structs.LogMessage{
|
||||
Id: 12,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "userId", Value: userId},
|
||||
},
|
||||
})
|
||||
logger.AddSystemLog("%s has changed his password", userId)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -447,14 +441,7 @@ func UpdateUserProfile(conn *websocket.Conn, changes map[string]interface{}) {
|
|||
},
|
||||
})
|
||||
|
||||
logger.AddSystemLog(structs.LogMessage{
|
||||
Id: 13,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "userId", Value: userId},
|
||||
{Type: "changes", Value: utils.MarshalJson(updates)},
|
||||
},
|
||||
})
|
||||
logger.AddSystemLog("User %s has updated his account with the following changes: %v", userId, utils.MarshalJson(updates))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -633,15 +620,8 @@ func AdminAreaUpdateRole(conn *websocket.Conn, body map[string]interface{}) {
|
|||
},
|
||||
})
|
||||
|
||||
logger.AddSystemLog(structs.LogMessage{
|
||||
Id: 2,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "userId", Value: conn.Locals("userId").(string)},
|
||||
{Type: "roleId", Value: roleId},
|
||||
{Type: "changes", Value: utils.MarshalJson(updates)},
|
||||
},
|
||||
})
|
||||
logger.AddSystemLog("User %s has updated the role %s with the following changes: %v",
|
||||
conn.Locals("userId").(string), roleId, utils.MarshalJson(updates))
|
||||
}
|
||||
|
||||
func AdminAreaMoveRoleToSortingOrder(conn *websocket.Conn, body map[string]interface{}) {
|
||||
|
@ -699,15 +679,8 @@ func AdminAreaMoveRoleToSortingOrder(conn *websocket.Conn, body map[string]inter
|
|||
Body: body,
|
||||
})
|
||||
|
||||
logger.AddSystemLog(structs.LogMessage{
|
||||
Id: 3,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "userId", Value: conn.Locals("userId").(string)},
|
||||
{Type: "roleId", Value: role.Id},
|
||||
{Type: "sortingOrder", Value: strconv.Itoa(newSortingOrder)},
|
||||
},
|
||||
})
|
||||
logger.AddSystemLog("User %s has changed the sorting order of role %s to %s",
|
||||
conn.Locals("userId").(string), roleId, strconv.Itoa(newSortingOrder))
|
||||
}
|
||||
|
||||
func AdminAreaDeleteRole(conn *websocket.Conn, body map[string]interface{}) {
|
||||
|
@ -731,14 +704,7 @@ func AdminAreaDeleteRole(conn *websocket.Conn, body map[string]interface{}) {
|
|||
Body: body,
|
||||
})
|
||||
|
||||
logger.AddSystemLog(structs.LogMessage{
|
||||
Id: 4,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "userId", Value: conn.Locals("userId").(string)},
|
||||
{Type: "roleId", Value: role.Id},
|
||||
},
|
||||
})
|
||||
logger.AddSystemLog("User %s has deleted the role %s", conn.Locals("userId").(string), role.Id)
|
||||
}
|
||||
|
||||
func UpdateUserRole(conn *websocket.Conn, userId string, roleId string) {
|
||||
|
@ -771,15 +737,8 @@ func UpdateUserRole(conn *websocket.Conn, userId string, roleId string) {
|
|||
},
|
||||
})
|
||||
|
||||
logger.AddSystemLog(structs.LogMessage{
|
||||
Id: 5,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "userId", Value: conn.Locals("userId").(string)},
|
||||
{Type: "roleId", Value: roleId},
|
||||
{Type: "targetUserId", Value: userId},
|
||||
},
|
||||
})
|
||||
logger.AddSystemLog("User %s has assigned the role %s to %s",
|
||||
conn.Locals("userId").(string), roleId, userId)
|
||||
}
|
||||
|
||||
func HasPermission(userId string, permission string) bool {
|
||||
|
@ -916,15 +875,8 @@ func AllUsersCreateNewUser(conn *websocket.Conn, body map[string]interface{}) {
|
|||
},
|
||||
})
|
||||
|
||||
logger.AddSystemLog(structs.LogMessage{
|
||||
Id: 6,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "userId", Value: conn.Locals("userId").(string)},
|
||||
{Type: "targetUserId", Value: newUser.Id},
|
||||
{Type: "roleId", Value: roleId},
|
||||
},
|
||||
})
|
||||
logger.AddSystemLog("User %s has created the user %s with the assigned role %s",
|
||||
conn.Locals("userId").(string), newUser.Id, roleId)
|
||||
}
|
||||
|
||||
func AllUsersDeleteUser(conn *websocket.Conn, userId string) {
|
||||
|
@ -962,14 +914,8 @@ func AllUsersDeleteUser(conn *websocket.Conn, userId string) {
|
|||
},
|
||||
})
|
||||
|
||||
logger.AddSystemLog(structs.LogMessage{
|
||||
Id: 7,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "userId", Value: conn.Locals("userId").(string)},
|
||||
{Type: "targetUserId", Value: userId},
|
||||
},
|
||||
})
|
||||
logger.AddSystemLog("User %s has deleted the user %s",
|
||||
conn.Locals("userId").(string), userId)
|
||||
}
|
||||
|
||||
func AllUsersUserDeactivation(conn *websocket.Conn, userId string, deactivate bool) {
|
||||
|
@ -992,15 +938,8 @@ func AllUsersUserDeactivation(conn *websocket.Conn, userId string, deactivate bo
|
|||
},
|
||||
})
|
||||
|
||||
logger.AddSystemLog(structs.LogMessage{
|
||||
Id: 9,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "userId", Value: conn.Locals("userId").(string)},
|
||||
{Type: "targetUserId", Value: userId},
|
||||
{Type: "deactivated", Value: strconv.FormatBool(deactivate)},
|
||||
},
|
||||
})
|
||||
logger.AddSystemLog("User %s has changed the deactivation status of user %s to %v",
|
||||
conn.Locals("userId").(string), userId, strconv.FormatBool(deactivate))
|
||||
}
|
||||
|
||||
func ScannersUpdateScannerUsedByUserId(userId string, scannerId string) {
|
||||
|
@ -1018,22 +957,9 @@ func ScannersUpdateScannerUsedByUserId(userId string, scannerId string) {
|
|||
})
|
||||
|
||||
if userId != "" {
|
||||
logger.AddSystemLog(structs.LogMessage{
|
||||
Id: 10,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "scannerId", Value: scannerId},
|
||||
{Type: "userId", Value: userId},
|
||||
},
|
||||
})
|
||||
logger.AddSystemLog("Scanner %s is now used by user %s", scannerId, userId)
|
||||
} else {
|
||||
logger.AddSystemLog(structs.LogMessage{
|
||||
Id: 11,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "scannerId", Value: scannerId},
|
||||
},
|
||||
})
|
||||
logger.AddSystemLog("Scanner %s is not longer used", scannerId)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1068,13 +994,7 @@ func CreateNewUserApiKey(userId string, apiName string) {
|
|||
Body: newApiKey,
|
||||
})
|
||||
|
||||
logger.AddSystemLog(structs.LogMessage{
|
||||
Id: 23,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "userId", Value: userId},
|
||||
},
|
||||
})
|
||||
logger.AddSystemLog("User %s has created an API key", userId)
|
||||
}
|
||||
|
||||
func DeleteUserApiKey(userId string, apiKey string) {
|
||||
|
@ -1090,13 +1010,7 @@ func DeleteUserApiKey(userId string, apiKey string) {
|
|||
Body: apiKey,
|
||||
})
|
||||
|
||||
logger.AddSystemLog(structs.LogMessage{
|
||||
Id: 24,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "userId", Value: userId},
|
||||
},
|
||||
})
|
||||
logger.AddSystemLog("User %s has deleted one of its api keys", userId)
|
||||
}
|
||||
|
||||
func GetAvailableCategories(userId string) []string {
|
||||
|
|
|
@ -61,11 +61,7 @@ func RunHub() {
|
|||
socketclients.UpdateConnectedUsers(userId)
|
||||
socketclients.UpdateUserSessionsForUser(userId, sessionId)
|
||||
|
||||
logger.AddSystemLog(structs.LogMessage{
|
||||
Id: 0,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "userId", Value: userId}}})
|
||||
logger.AddSystemLog("User %v has come online", userId)
|
||||
|
||||
case data := <-broadcast:
|
||||
var receivedMessage structs.ReceivedMessage
|
||||
|
@ -116,15 +112,8 @@ func RunHub() {
|
|||
|
||||
go grouptasks.RunGroupTask(groupTaskArgs)
|
||||
|
||||
logger.AddGroupTasksLog(structs.LogMessage{
|
||||
Id: 4,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "taskStepId", Value: groupTaskArgs.TaskStepId},
|
||||
{Type: "groupTaskId", Value: groupTaskArgs.GroupTaskId},
|
||||
{Type: "userId", Value: groupTaskArgs.CreatorUserId},
|
||||
},
|
||||
})
|
||||
logger.AddGroupTasksLog("Step %s of groupTaskId %s has failed and was started by user %s to try again",
|
||||
groupTaskArgs.TaskStepId, groupTaskArgs.GroupTaskId, groupTaskArgs.CreatorUserId)
|
||||
break
|
||||
case utils.ReceivedCmdTaskContinueTaskStep:
|
||||
groupTaskArgs := grouptasks.RunGroupTaskArgs{
|
||||
|
@ -140,15 +129,8 @@ func RunHub() {
|
|||
|
||||
go grouptasks.RunGroupTask(groupTaskArgs)
|
||||
|
||||
logger.AddGroupTasksLog(structs.LogMessage{
|
||||
Id: 3,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "taskStepId", Value: groupTaskArgs.TaskStepId},
|
||||
{Type: "groupTaskId", Value: groupTaskArgs.GroupTaskId},
|
||||
{Type: "userId", Value: groupTaskArgs.CreatorUserId},
|
||||
},
|
||||
})
|
||||
logger.AddGroupTasksLog("Step %s of groupTaskId %s was continued by user %s",
|
||||
groupTaskArgs.TaskStepId, groupTaskArgs.GroupTaskId, groupTaskArgs.CreatorUserId)
|
||||
break
|
||||
case utils.ReceivedCmdReloadGroupTasks:
|
||||
category := receivedMessage.Body["category"].(string)
|
||||
|
@ -168,14 +150,8 @@ func RunHub() {
|
|||
|
||||
grouptasks.ReloadCategoryGroups(category)
|
||||
|
||||
logger.AddGroupTasksLog(structs.LogMessage{
|
||||
Id: 1,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "userId", Value: data.Conn.Locals("userId").(string)},
|
||||
{Type: "category", Value: category},
|
||||
},
|
||||
})
|
||||
logger.AddGroupTasksLog("User %s has reloaded group tasks config of category %s",
|
||||
data.Conn.Locals("userId").(string), category)
|
||||
break
|
||||
case utils.ReceivedCmdTaskLocking:
|
||||
log.Info().Msgf("body %v", receivedMessage.Body)
|
||||
|
@ -229,14 +205,9 @@ func RunHub() {
|
|||
Body: role,
|
||||
})
|
||||
|
||||
logger.AddSystemLog(structs.LogMessage{
|
||||
Id: 1,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "userId", Value: data.Conn.Locals("userId").(string)},
|
||||
{Type: "roleId", Value: role.Id},
|
||||
},
|
||||
})
|
||||
logger.AddSystemLog("User %s has created the role %s",
|
||||
data.Conn.Locals("userId").(string),
|
||||
role.Id)
|
||||
break
|
||||
case utils.ReceivedCmdAdminAreaUpdateRole:
|
||||
if !socketclients.HasPermission(data.Conn.Locals("userId").(string), utils.PermissionAdminAreaUpdateRole) {
|
||||
|
@ -382,13 +353,7 @@ func RunHub() {
|
|||
socketclients.UpdateUserSessionsForUser(userId, sessionId)
|
||||
socketclients.UpdateConnectedUsers(userId)
|
||||
|
||||
logger.AddSystemLog(structs.LogMessage{
|
||||
Id: 18,
|
||||
Type: utils.LogTypeInfo,
|
||||
Messages: []structs.LogData{
|
||||
{Type: "userId", Value: userId},
|
||||
},
|
||||
})
|
||||
logger.AddSystemLog("User %s has gone offline", userId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue