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