diff --git a/internal/rpc/rpc_client.go b/internal/rpc/rpc_client.go index 9a83b34d..b47c7067 100644 --- a/internal/rpc/rpc_client.go +++ b/internal/rpc/rpc_client.go @@ -22,7 +22,7 @@ import ( "time" ) -// RPC客户端 +// RPCClient RPC客户端 type RPCClient struct { apiConfig *configs.APIConfig conns []*grpc.ClientConn @@ -30,7 +30,7 @@ type RPCClient struct { locker sync.Mutex } -// 构造新的RPC客户端 +// NewRPCClient 构造新的RPC客户端 func NewRPCClient(apiConfig *configs.APIConfig) (*RPCClient, error) { if apiConfig == nil { return nil, errors.New("api config should not be nil") diff --git a/internal/rpc/rpc_client_test.go b/internal/rpc/rpc_client_test.go index 8769f966..1fa59d64 100644 --- a/internal/rpc/rpc_client_test.go +++ b/internal/rpc/rpc_client_test.go @@ -37,7 +37,7 @@ func TestRPC_Dial_HTTP(t *testing.T) { RPC: struct { Endpoints []string `yaml:"endpoints"` }{ - Endpoints: []string{"127.0.0.1:8003"}, + Endpoints: []string{"http://127.0.0.1:8004"}, }, NodeId: "a7e55782dab39bce0901058a1e14a0e6", Secret: "lvyPobI3BszkJopz5nPTocOs0OLkEJ7y", @@ -58,7 +58,7 @@ func TestRPC_Dial_HTTP_2(t *testing.T) { RPC: struct { Endpoints []string `yaml:"endpoints"` }{ - Endpoints: []string{"http://127.0.0.1:8003"}, + Endpoints: []string{"https://127.0.0.1:8003"}, }, NodeId: "a7e55782dab39bce0901058a1e14a0e6", Secret: "lvyPobI3BszkJopz5nPTocOs0OLkEJ7y", diff --git a/internal/web/actions/default/clusters/logs/index.go b/internal/web/actions/default/clusters/logs/index.go new file mode 100644 index 00000000..64b0424e --- /dev/null +++ b/internal/web/actions/default/clusters/logs/index.go @@ -0,0 +1,86 @@ +package logs + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/iwind/TeaGo/maps" + timeutil "github.com/iwind/TeaGo/utils/time" +) + +type IndexAction struct { + actionutils.ParentAction +} + +func (this *IndexAction) Init() { +} + +func (this *IndexAction) RunGet(params struct { + DayFrom string + DayTo string + Keyword string + Level string +}) { + this.Data["dayFrom"] = params.DayFrom + this.Data["dayTo"] = params.DayTo + this.Data["keyword"] = params.Keyword + this.Data["level"] = params.Level + + countResp, err := this.RPC().NodeLogRPC().CountNodeLogs(this.AdminContext(), &pb.CountNodeLogsRequest{ + NodeId: 0, + Role: "node", + DayFrom: params.DayFrom, + DayTo: params.DayTo, + Keyword: params.Keyword, + Level: params.Level, + }) + if err != nil { + this.ErrorPage(err) + return + } + count := countResp.Count + page := this.NewPage(count) + this.Data["page"] = page.AsHTML() + + logsResp, err := this.RPC().NodeLogRPC().ListNodeLogs(this.AdminContext(), &pb.ListNodeLogsRequest{ + NodeId: 0, + Role: "node", + DayFrom: params.DayFrom, + DayTo: params.DayTo, + Keyword: params.Keyword, + Level: params.Level, + Offset: page.Offset, + Size: page.Size, + }) + + 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 + if node == nil || node.NodeCluster == nil { + continue + } + + logs = append(logs, maps.Map{ + "tag": log.Tag, + "description": log.Description, + "createdTime": timeutil.FormatTime("Y-m-d H:i:s", log.CreatedAt), + "level": log.Level, + "isToday": timeutil.FormatTime("Y-m-d", log.CreatedAt) == timeutil.Format("Y-m-d"), + "node": maps.Map{ + "id": node.Id, + "cluster": maps.Map{ + "id": node.NodeCluster.Id, + "name": node.NodeCluster.Name, + }, + "name": node.Name, + }, + }) + } + this.Data["logs"] = logs + + this.Show() +} diff --git a/internal/web/actions/default/clusters/logs/init.go b/internal/web/actions/default/clusters/logs/init.go new file mode 100644 index 00000000..53bd6673 --- /dev/null +++ b/internal/web/actions/default/clusters/logs/init.go @@ -0,0 +1,19 @@ +package logs + +import ( + "github.com/TeaOSLab/EdgeAdmin/internal/configloaders" + "github.com/TeaOSLab/EdgeAdmin/internal/web/helpers" + "github.com/iwind/TeaGo" +) + +func init() { + TeaGo.BeforeStart(func(server *TeaGo.Server) { + server. + Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeNode)). + Data("teaMenu", "clusters"). + Data("teaSubMenu", "log"). + Prefix("/clusters/logs"). + Get("", new(IndexAction)). + EndAll() + }) +} diff --git a/internal/web/helpers/user_must_auth.go b/internal/web/helpers/user_must_auth.go index 71031de4..20d84568 100644 --- a/internal/web/helpers/user_must_auth.go +++ b/internal/web/helpers/user_must_auth.go @@ -181,6 +181,11 @@ func (this *userMustAuth) modules(adminId int64) []maps.Map { "subtitle": "集群列表", "icon": "cloud", "subItems": []maps.Map{ + { + "name": "节点日志", + "url": "/clusters/logs", + "code": "log", + }, { "name": "SSH认证", "url": "/clusters/grants", diff --git a/internal/web/import.go b/internal/web/import.go index a47ff5b4..1d8b9c52 100644 --- a/internal/web/import.go +++ b/internal/web/import.go @@ -15,6 +15,7 @@ import ( _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster" _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/settings" _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/grants" + _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/logs" _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/regions" _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/regions/items" _ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/tasks" diff --git a/web/public/js/components/server/origin-list-box.js b/web/public/js/components/server/origin-list-box.js index 6dbcc9ed..d71f6d9e 100644 --- a/web/public/js/components/server/origin-list-box.js +++ b/web/public/js/components/server/origin-list-box.js @@ -11,7 +11,9 @@ Vue.component("origin-list-box", { teaweb.popup("/servers/server/settings/origins/addPopup?originType=primary&" + this.vParams, { height: "24em", callback: function (resp) { - window.location.reload() + teaweb.success("保存成功", function () { + window.location.reload() + }) } }) }, @@ -19,7 +21,9 @@ Vue.component("origin-list-box", { teaweb.popup("/servers/server/settings/origins/addPopup?originType=backup&" + this.vParams, { height: "24em", callback: function (resp) { - window.location.reload() + teaweb.success("保存成功", function () { + window.location.reload() + }) } }) }, @@ -27,7 +31,9 @@ Vue.component("origin-list-box", { teaweb.popup("/servers/server/settings/origins/updatePopup?originType=" + originType + "&" + this.vParams + "&originId=" + originId, { height: "24em", callback: function (resp) { - window.location.reload() + teaweb.success("保存成功", function () { + window.location.reload() + }) } }) }, @@ -37,7 +43,9 @@ Vue.component("origin-list-box", { Tea.action("/servers/server/settings/origins/delete?" + that.vParams + "&originId=" + originId + "&originType=" + originType) .post() .success(function () { - window.location.reload() + teaweb.success("保存成功", function () { + window.location.reload() + }) }) }) } diff --git a/web/views/@default/clusters/cluster/node/logs.html b/web/views/@default/clusters/cluster/node/logs.html index c938db9a..15f05a88 100644 --- a/web/views/@default/clusters/cluster/node/logs.html +++ b/web/views/@default/clusters/cluster/node/logs.html @@ -1,20 +1,19 @@ {$layout} +{$template "node_menu"} - {$template "node_menu"} +
暂时还没有日志。
-暂时还没有日志。
+
+ [{{log.createdTime}}][{{log.createdTime}}][{{log.tag}}]{{log.description}}
+ |
+
[{{log.createdTime}}][{{log.createdTime}}][{{log.tag}}]{{log.description}}
- 暂时还没有日志。
+ +| 集群 | +节点 | +信息 | +
|---|---|---|
+ [{{log.createdTime}}][{{log.createdTime}}][{{log.tag}}]{{log.description}}
+ |
+