可以修复单页或者全部服务日志

This commit is contained in:
GoEdgeLab
2022-03-23 17:31:53 +08:00
parent 3d45db8f3e
commit ee24baf7d6
11 changed files with 144 additions and 138 deletions

View File

@@ -0,0 +1,33 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package logs
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/types"
"strings"
)
type FixAction struct {
actionutils.ParentAction
}
func (this *FixAction) RunPost(params struct {
LogIds []int64
}) {
var logIdStrings = []string{}
for _, logId := range params.LogIds {
logIdStrings = append(logIdStrings, types.String(logId))
}
defer this.CreateLogInfo("设置日志 %s 为已修复", strings.Join(logIdStrings, ", "))
_, err := this.RPC().NodeLogRPC().FixNodeLogs(this.AdminContext(), &pb.FixNodeLogsRequest{NodeLogIds: params.LogIds})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,25 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package logs
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
)
type FixAllAction struct {
actionutils.ParentAction
}
func (this *FixAllAction) RunPost(params struct {
}) {
defer this.CreateLogInfo("设置所有日志为已修复")
_, err := this.RPC().NodeLogRPC().FixAllNodeLogs(this.AdminContext(), &pb.FixAllNodeLogsRequest{})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -3,8 +3,10 @@ package logs
import (
"github.com/TeaOSLab/EdgeAdmin/internal/utils/nodelogutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/configutils"
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/lists"
"github.com/iwind/TeaGo/maps"
timeutil "github.com/iwind/TeaGo/utils/time"
)
@@ -14,8 +16,11 @@ type IndexAction struct {
}
func (this *IndexAction) Init() {
if this.ParamString("type") == "unread" {
var paramType = this.ParamString("type")
if paramType == "unread" {
this.FirstMenu("unread")
} else if paramType == "needFix" {
this.FirstMenu("needFix")
} else {
this.FirstMenu("index")
}
@@ -26,7 +31,7 @@ func (this *IndexAction) RunGet(params struct {
DayTo string
Keyword string
Level string
Type string
Type string // unread, needFix
Tag string
ClusterId int64
NodeId int64
@@ -40,6 +45,13 @@ func (this *IndexAction) RunGet(params struct {
this.Data["clusterId"] = params.ClusterId
this.Data["nodeId"] = params.NodeId
var fixedState configutils.BoolState = 0
var allServers = false
if params.Type == "needFix" {
fixedState = configutils.BoolStateNo
allServers = true
}
// 常见标签
this.Data["tags"] = nodelogutils.FindNodeCommonTags()
@@ -54,6 +66,18 @@ func (this *IndexAction) RunGet(params struct {
}
this.Data["countUnreadLogs"] = countUnreadResp.Count
// 需要修复数量
countNeedFixResp, err := this.RPC().NodeLogRPC().CountNodeLogs(this.AdminContext(), &pb.CountNodeLogsRequest{
Role: nodeconfigs.NodeRoleNode,
AllServers: true,
FixedState: int32(configutils.BoolStateNo),
})
if err != nil {
this.ErrorPage(err)
return
}
this.Data["countNeedFixLogs"] = countNeedFixResp.Count
// 日志数量
countResp, err := this.RPC().NodeLogRPC().CountNodeLogs(this.AdminContext(), &pb.CountNodeLogsRequest{
NodeClusterId: params.ClusterId,
@@ -65,13 +89,15 @@ func (this *IndexAction) RunGet(params struct {
Level: params.Level,
IsUnread: params.Type == "unread",
Tag: params.Tag,
FixedState: int32(fixedState),
AllServers: allServers,
})
if err != nil {
this.ErrorPage(err)
return
}
count := countResp.Count
page := this.NewPage(count)
var count = countResp.Count
var page = this.NewPage(count)
this.Data["page"] = page.AsHTML()
logsResp, err := this.RPC().NodeLogRPC().ListNodeLogs(this.AdminContext(), &pb.ListNodeLogsRequest{
@@ -84,6 +110,8 @@ func (this *IndexAction) RunGet(params struct {
Level: params.Level,
IsUnread: params.Type == "unread",
Tag: params.Tag,
FixedState: int32(fixedState),
AllServers: allServers,
Offset: page.Offset,
Size: page.Size,
})
@@ -92,14 +120,14 @@ func (this *IndexAction) RunGet(params struct {
return
}
logs := []maps.Map{}
var logs = []maps.Map{}
for _, log := range logsResp.NodeLogs {
// 节点信息
nodeResp, err := this.RPC().NodeRPC().FindEnabledNode(this.AdminContext(), &pb.FindEnabledNodeRequest{NodeId: log.NodeId})
if err != nil {
continue
}
node := nodeResp.Node
var node = nodeResp.Node
if node == nil || node.NodeCluster == nil {
continue
}
@@ -118,6 +146,11 @@ func (this *IndexAction) RunGet(params struct {
}
}
var isFixed = true
if !log.IsFixed && log.ServerId > 0 && lists.ContainsString([]string{"success", "warning", "error"}, log.Level) {
isFixed = false
}
logs = append(logs, maps.Map{
"id": log.Id,
"tag": log.Tag,
@@ -127,6 +160,7 @@ func (this *IndexAction) RunGet(params struct {
"isToday": timeutil.FormatTime("Y-m-d", log.CreatedAt) == timeutil.Format("Y-m-d"),
"count": log.Count,
"isRead": log.IsRead,
"isFixed": isFixed,
"node": maps.Map{
"id": node.Id,
"cluster": maps.Map{

View File

@@ -16,6 +16,8 @@ func init() {
Get("", new(IndexAction)).
Post("/readLogs", new(ReadLogsAction)).
Post("/readAllLogs", new(ReadAllLogsAction)).
Post("/fix", new(FixAction)).
Post("/fixAll", new(FixAllAction)).
EndAll()
})
}