Skip to content

Commit

Permalink
#859 monitor接入标准日志规范
Browse files Browse the repository at this point in the history
  • Loading branch information
tangjiawei committed Dec 18, 2024
1 parent 025aea4 commit 62417d7
Show file tree
Hide file tree
Showing 31 changed files with 977 additions and 660 deletions.
537 changes: 264 additions & 273 deletions monitor-server/api/api.go

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions monitor-server/api/v1/agent/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func ExportPanelAdd(c *gin.Context) {
var result resultObj
if err := c.ShouldBindJSON(&param); err == nil {
if len(param.Inputs) == 0 {
result = resultObj{ResultCode: "0", ResultMessage: fmt.Sprintf(mid.GetMessageMap(c).ParamEmptyError, "inputs")}
result = resultObj{ResultCode: "0", ResultMessage: fmt.Sprintf(m.GetMessageMap(c).ParamEmptyError.Error(), "inputs")}
log.Logger.Warn(result.ResultMessage)
c.JSON(http.StatusOK, result)
return
Expand All @@ -59,7 +59,7 @@ func ExportPanelAdd(c *gin.Context) {
tmpMessage = checkRoleErr.Error()
}
if v.Guid == "" {
tmpMessage = fmt.Sprintf(mid.GetMessageMap(c).ParamEmptyError, "guid")
tmpMessage = fmt.Sprintf(m.GetMessageMap(c).ParamEmptyError.Error(), "guid")
}
if tmpMessage != "" {
errorMessage = tmpMessage
Expand All @@ -82,15 +82,15 @@ func ExportPanelAdd(c *gin.Context) {
if len(tmpList) == 2 {
tmpAddress = fmt.Sprintf("%s:%s", tmpList[0], tmpList[1])
} else {
tmpMessage += fmt.Sprintf(mid.GetMessageMap(c).ParamTypeError, "endpoint", "[guid] or [ip:port]")
tmpMessage += fmt.Sprintf(m.GetMessageMap(c).ParamTypeError.Error(), "endpoint", "[guid] or [ip:port]")
continue
}
endpointObj = m.EndpointTable{Address: tmpAddress}
db.GetEndpoint(&endpointObj)
if endpointObj.Id > 0 {
endpointStringList = append(endpointStringList, endpointObj.Guid)
} else {
tmpMessage += fmt.Sprintf(mid.GetMessageMap(c).FetchTableDataError, "endpoint", "address", tmpAddress)
tmpMessage += fmt.Sprintf(m.GetMessageMap(c).FetchTableDataError.Error(), "endpoint", "address", tmpAddress)
}
}
}
Expand All @@ -102,7 +102,7 @@ func ExportPanelAdd(c *gin.Context) {
}
err := db.UpdateRecursivePanel(m.PanelRecursiveTable{Guid: v.Guid, DisplayName: v.DisplayName, Parent: strings.Join(tmpParent, "^"), Endpoint: strings.Join(endpointStringList, "^"), Email: v.Email, Phone: v.Phone, Role: strings.Join(inputRoleList, ","), FiringCallbackKey: v.FiringCallback, RecoverCallbackKey: v.RecoverCallback, ObjType: v.Type}, mid.GetOperateUser(c))
if err != nil {
tmpMessage = fmt.Sprintf(mid.GetMessageMap(c).UpdateTableError, "recursive_panel")
tmpMessage = fmt.Sprintf(m.GetMessageMap(c).UpdateTableError.Error(), "recursive_panel")
errorMessage = tmpMessage
tmpResult = append(tmpResult, resultOutputObj{Guid: v.Guid, CallbackParameter: v.CallbackParameter, ErrorCode: "1", ErrorMessage: tmpMessage, ErrorDetail: err.Error(), MonitorKey: v.Guid})
successFlag = "1"
Expand All @@ -114,7 +114,7 @@ func ExportPanelAdd(c *gin.Context) {
log.Logger.Info("Plugin result", log.JsonObj("result", result))
mid.ReturnData(c, result)
} else {
result = resultObj{ResultCode: "1", ResultMessage: fmt.Sprintf(mid.GetMessageMap(c).ParamValidateError, err.Error())}
result = resultObj{ResultCode: "1", ResultMessage: fmt.Sprintf(m.GetMessageMap(c).ParamValidateError.Error(), err.Error())}
log.Logger.Warn(result.ResultMessage)
c.JSON(http.StatusBadRequest, result)
}
Expand Down Expand Up @@ -179,7 +179,7 @@ func ExportPanelDelete(c *gin.Context) {
continue
}
if v.Guid == "" {
tmpMessage = fmt.Sprintf(mid.GetMessageMap(c).ParamEmptyError, "guid")
tmpMessage = fmt.Sprintf(m.GetMessageMap(c).ParamEmptyError.Error(), "guid")
}
if tmpMessage != "" {
errorMessage = tmpMessage
Expand Down Expand Up @@ -207,15 +207,15 @@ func ExportPanelDelete(c *gin.Context) {
if len(tmpList) == 2 {
tmpAddress = fmt.Sprintf("%s:%s", tmpList[0], tmpList[1])
} else {
tmpMessage += fmt.Sprintf(mid.GetMessageMap(c).ParamTypeError, "endpoint", "[guid] or [ip:port]")
tmpMessage += fmt.Sprintf(m.GetMessageMap(c).ParamTypeError.Error(), "endpoint", "[guid] or [ip:port]")
continue
}
endpointObj = m.EndpointTable{Address: tmpAddress}
db.GetEndpoint(&endpointObj)
if endpointObj.Id > 0 {
endpointStringList = append(endpointStringList, endpointObj.Guid)
} else {
tmpMessage += fmt.Sprintf(mid.GetMessageMap(c).FetchTableDataError, "endpoint", "address", tmpAddress)
tmpMessage += fmt.Sprintf(m.GetMessageMap(c).FetchTableDataError.Error(), "endpoint", "address", tmpAddress)
}
}
}
Expand All @@ -230,7 +230,7 @@ func ExportPanelDelete(c *gin.Context) {
}
}
if cErr != nil {
tmpMessage = fmt.Sprintf(mid.GetMessageMap(c).UpdateTableError, "recursive_panel")
tmpMessage = fmt.Sprintf(m.GetMessageMap(c).UpdateTableError.Error(), "recursive_panel")
errorMessage = tmpMessage
tmpResult = append(tmpResult, resultOutputObj{Guid: v.Guid, CallbackParameter: v.CallbackParameter, ErrorCode: "1", ErrorMessage: tmpMessage, ErrorDetail: cErr.Error()})
successFlag = "1"
Expand All @@ -242,7 +242,7 @@ func ExportPanelDelete(c *gin.Context) {
log.Logger.Info("Plugin result", log.JsonObj("result", result))
mid.ReturnData(c, result)
} else {
result = resultObj{ResultCode: "1", ResultMessage: fmt.Sprintf(mid.GetMessageMap(c).ParamValidateError, err.Error())}
result = resultObj{ResultCode: "1", ResultMessage: fmt.Sprintf(m.GetMessageMap(c).ParamValidateError.Error(), err.Error())}
log.Logger.Warn(result.ResultMessage)
c.JSON(http.StatusBadRequest, result)
}
Expand Down
4 changes: 2 additions & 2 deletions monitor-server/api/v1/agent/deregister.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func DeregisterAgent(c *gin.Context) {
return
}
if len(processList) > 0 {
mid.ReturnServerHandleError(c, fmt.Errorf(mid.GetMessageMap(c).EndpointHostDeleteError))
mid.ReturnServerHandleError(c, m.GetMessageMap(c).EndpointHostDeleteError)
return
}
}
Expand Down Expand Up @@ -146,7 +146,7 @@ func CustomRegister(c *gin.Context) {
mid.ReturnSuccess(c)
}
} else {
mid.ReturnValidateError(c, fmt.Sprintf(mid.GetMessageMap(c).ParamValidateError, err.Error()))
mid.ReturnValidateError(c, err.Error())
}
}

Expand Down
20 changes: 8 additions & 12 deletions monitor-server/api/v1/agent/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ func ExportAgentNew(c *gin.Context) {
err := json.Unmarshal(data, &param)
if err != nil {
resultCode = "1"
resultMessage = mid.GetMessageMap(c).RequestJsonUnmarshalError
resultMessage = m.GetMessageMap(c).RequestJsonUnmarshalError.Error()
return
}
if len(param.Inputs) == 0 {
resultCode = "0"
resultMessage = fmt.Sprintf(mid.GetMessageMap(c).ParamEmptyError, "inputs")
resultMessage = fmt.Sprintf(m.GetMessageMap(c).ParamEmptyError.Error(), "inputs")
return
}
for _, v := range param.Inputs {
Expand Down Expand Up @@ -125,7 +125,7 @@ func ExportAgentNew(c *gin.Context) {
registerParam.Tags = v.Tags
validateMessage, endpointGuid, inputErr = AgentRegister(registerParam, mid.GetOperateUser(c))
if validateMessage != "" {
validateMessage = fmt.Sprintf(mid.GetMessageMap(c).ParamValidateError, validateMessage)
validateMessage = fmt.Sprintf(m.GetMessageMap(c).ParamValidateError.Error(), validateMessage)
}
if validateMessage == "" && inputErr == nil && v.AppLogPaths != "" {
inputErr = autoAddAppPathConfig(registerParam, v.AppLogPaths)
Expand All @@ -149,7 +149,7 @@ func ExportAgentNew(c *gin.Context) {
if validateMessage != "" || inputErr != nil {
errorMessage := validateMessage
if errorMessage == "" {
errorMessage = fmt.Sprintf(mid.GetMessageMap(c).HandleError, inputErr.Error())
errorMessage = fmt.Sprintf(m.GetMessageMap(c).HandleError.Error(), inputErr.Error())
}
resultData.Outputs = append(resultData.Outputs, resultOutputObj{CallbackParameter: v.CallbackParameter, ErrorCode: "1", ErrorMessage: errorMessage, Guid: v.Guid, MonitorKey: endpointGuid})
resultCode = "1"
Expand Down Expand Up @@ -185,7 +185,7 @@ func AlarmControl(c *gin.Context) {
err := json.Unmarshal(data, &param)
if err == nil {
if len(param.Inputs) == 0 {
result = resultObj{ResultCode: "0", ResultMessage: fmt.Sprintf(mid.GetMessageMap(c).ParamEmptyError, "inputs")}
result = resultObj{ResultCode: "0", ResultMessage: fmt.Sprintf(m.GetMessageMap(c).ParamEmptyError.Error(), "inputs")}
log.Logger.Warn(result.ResultMessage)
c.JSON(http.StatusOK, result)
return
Expand All @@ -210,8 +210,8 @@ func AlarmControl(c *gin.Context) {
var msg string
if err != nil {
msg = fmt.Sprintf("%s %s:%s %s fail,error %v", action, agentType, v.HostIp, instanceName, err)
resultMessage = fmt.Sprintf(mid.GetMessageMap(c).HandleError, msg)
tmpResult = append(tmpResult, resultOutputObj{CallbackParameter: v.CallbackParameter, ErrorCode: "1", Guid: v.Guid, ErrorMessage: fmt.Sprintf(mid.GetMessageMap(c).HandleError, msg)})
resultMessage = fmt.Sprintf(m.GetMessageMap(c).HandleError.Error(), msg)
tmpResult = append(tmpResult, resultOutputObj{CallbackParameter: v.CallbackParameter, ErrorCode: "1", Guid: v.Guid, ErrorMessage: fmt.Sprintf(m.GetMessageMap(c).HandleError.Error(), msg)})
successFlag = "1"
} else {
msg = fmt.Sprintf("%s %s:%s %s succeed", action, agentType, v.HostIp, instanceName)
Expand All @@ -223,7 +223,7 @@ func AlarmControl(c *gin.Context) {
log.Logger.Info("result", log.JsonObj("result", result))
mid.ReturnData(c, result)
} else {
result = resultObj{ResultCode: "1", ResultMessage: fmt.Sprintf(mid.GetMessageMap(c).ParamValidateError, err.Error())}
result = resultObj{ResultCode: "1", ResultMessage: fmt.Sprintf(m.GetMessageMap(c).ParamValidateError.Error(), err.Error())}
log.Logger.Error("Param validate fail", log.Error(err))
c.JSON(http.StatusBadRequest, result)
}
Expand Down Expand Up @@ -281,10 +281,6 @@ func autoAddAppPathConfig(param m.RegisterParamNew, paths string) error {
log.Logger.Error("Update endpoint business table error", log.Error(err))
return err
}
//err = alarm.UpdateNodeExporterBusinessConfig(hostEndpoint.Id)
//if err != nil {
// log.Logger.Error("Update business config error", log.Error(err))
//}
return err
}

Expand Down
Loading

0 comments on commit 62417d7

Please sign in to comment.