This commit is contained in:
unknown
2026-02-04 20:27:13 +08:00
commit 3b042d1dad
9410 changed files with 1488147 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
//go:build plus
package groups
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
)
type CreatePopupAction struct {
actionutils.ParentAction
}
func (this *CreatePopupAction) Init() {
this.Nav("", "", "")
}
func (this *CreatePopupAction) RunGet(params struct{}) {
this.Show()
}
func (this *CreatePopupAction) RunPost(params struct {
Name string
Must *actions.Must
CSRF *actionutils.CSRF
}) {
var groupId int64 = 0
defer func() {
this.CreateLogInfo(codes.ReportNodeGroup_LogCreateReportNodeGroup, groupId)
}()
params.Must.
Field("name", params.Name).
Require("请输入分组名称")
createResp, err := this.RPC().ReportNodeGroupRPC().CreateReportNodeGroup(this.AdminContext(), &pb.CreateReportNodeGroupRequest{Name: params.Name})
if err != nil {
this.ErrorPage(err)
return
}
groupId = createResp.ReportNodeGroupId
this.Success()
}

View File

@@ -0,0 +1,28 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
//go:build plus
package group
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
)
type DeleteAction struct {
actionutils.ParentAction
}
func (this *DeleteAction) RunPost(params struct {
GroupId int64
}) {
defer this.CreateLogInfo(codes.ReportNodeGroup_LogDeleteReportNodeGroup, params.GroupId)
_, err := this.RPC().ReportNodeGroupRPC().DeleteReportNodeGroup(this.AdminContext(), &pb.DeleteReportNodeGroupRequest{ReportNodeGroupId: params.GroupId})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,67 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
//go:build plus
package group
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
)
type UpdatePopupAction struct {
actionutils.ParentAction
}
func (this *UpdatePopupAction) Init() {
this.Nav("", "", "")
}
func (this *UpdatePopupAction) RunGet(params struct {
GroupId int64
}) {
groupResp, err := this.RPC().ReportNodeGroupRPC().FindEnabledReportNodeGroup(this.AdminContext(), &pb.FindEnabledReportNodeGroupRequest{ReportNodeGroupId: params.GroupId})
if err != nil {
this.ErrorPage(err)
return
}
var group = groupResp.ReportNodeGroup
if group == nil {
this.NotFound("reportNodeGroup", params.GroupId)
return
}
this.Data["group"] = maps.Map{
"id": group.Id,
"name": group.Name,
}
this.Show()
}
func (this *UpdatePopupAction) RunPost(params struct {
GroupId int64
Name string
Must *actions.Must
CSRF *actionutils.CSRF
}) {
defer this.CreateLogInfo(codes.ReportNodeGroup_LogUpdateReportNodeGroup, params.GroupId)
params.Must.
Field("name", params.Name).
Require("请输入分组名称")
_, err := this.RPC().ReportNodeGroupRPC().UpdateReportNodeGroup(this.AdminContext(), &pb.UpdateReportNodeGroupRequest{
ReportNodeGroupId: params.GroupId,
Name: params.Name,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,36 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
//go:build plus
package groups
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
)
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("", "", "group")
}
func (this *IndexAction) RunGet(params struct{}) {
groupsResp, err := this.RPC().ReportNodeGroupRPC().FindAllEnabledReportNodeGroups(this.AdminContext(), &pb.FindAllEnabledReportNodeGroupsRequest{})
if err != nil {
this.ErrorPage(err)
return
}
var groupMaps = []maps.Map{}
for _, group := range groupsResp.ReportNodeGroups {
groupMaps = append(groupMaps, maps.Map{
"id": group.Id,
"name": group.Name,
})
}
this.Data["groups"] = groupMaps
this.Show()
}

View File

@@ -0,0 +1,33 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
//go:build plus
package groups
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
)
type OptionsAction struct {
actionutils.ParentAction
}
func (this *OptionsAction) RunPost(params struct{}) {
resp, err := this.RPC().ReportNodeGroupRPC().FindAllEnabledReportNodeGroups(this.AdminContext(), &pb.FindAllEnabledReportNodeGroupsRequest{})
if err != nil {
this.ErrorPage(err)
return
}
var groupMaps = []maps.Map{}
for _, group := range resp.ReportNodeGroups {
groupMaps = append(groupMaps, maps.Map{
"id": group.Id,
"name": group.Name,
})
}
this.Data["groups"] = groupMaps
this.Success()
}

View File

@@ -0,0 +1,130 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
//go:build plus
package monitors
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/reporterconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
"math"
)
var indexLastClusterId int64 = 0
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("", "", "index")
}
func (this *IndexAction) RunGet(params struct {
ClusterId int64
}) {
// TODO
// 先跳转到终端,以后再实现任务
this.RedirectURL("/clusters/monitors/reporters")
return
//所有集群
clustersResp, err := this.RPC().NodeClusterRPC().FindAllEnabledNodeClusters(this.AdminContext(), &pb.FindAllEnabledNodeClustersRequest{})
if err != nil {
this.ErrorPage(err)
return
}
var clusters = clustersResp.NodeClusters
var clusterMaps = []maps.Map{}
for _, cluster := range clusters {
clusterMaps = append(clusterMaps, maps.Map{
"id": cluster.Id,
"name": cluster.Name,
})
}
this.Data["clusters"] = clusterMaps
if params.ClusterId <= 0 && len(clusters) > 0 {
var found = false
if indexLastClusterId > 0 {
for _, c := range clusters {
if indexLastClusterId == c.Id {
found = true
params.ClusterId = indexLastClusterId
break
}
}
}
if !found {
params.ClusterId = clusters[0].Id
}
}
this.Data["clusterId"] = params.ClusterId
indexLastClusterId = params.ClusterId
if params.ClusterId > 0 {
// 数量
countResp, err := this.RPC().ReportNodeRPC().CountAllReportNodeTasks(this.AdminContext(), &pb.CountAllReportNodeTasksRequest{
Role: nodeconfigs.NodeRoleNode,
Type: reporterconfigs.TaskTypeIPAddr,
NodeClusterId: params.ClusterId,
})
if err != nil {
this.ErrorPage(err)
return
}
var page = this.NewPage(countResp.Count)
this.Data["page"] = page.AsHTML()
// 列表
listResp, err := this.RPC().ReportNodeRPC().ListReportNodeTasks(this.AdminContext(), &pb.ListReportNodeTasksRequest{
Role: nodeconfigs.NodeRoleNode,
Type: reporterconfigs.TaskTypeIPAddr,
NodeClusterId: params.ClusterId,
Offset: page.Offset,
Size: page.Size,
})
if err != nil {
this.ErrorPage(err)
return
}
var taskMaps = []maps.Map{}
for _, task := range listResp.IpAddrReportTasks {
nodeResp, err := this.RPC().NodeRPC().FindEnabledBasicNode(this.AdminContext(), &pb.FindEnabledBasicNodeRequest{NodeId: task.NodeIPAddress.NodeId})
if err != nil {
this.ErrorPage(err)
return
}
var node = nodeResp.Node
var nodeMap = maps.Map{"id": 0, "name": ""}
if node != nil {
nodeMap = maps.Map{
"id": node.Id,
"name": node.Name,
}
}
taskMaps = append(taskMaps, maps.Map{
"addr": maps.Map{
"id": task.NodeIPAddress.Id,
},
"port": task.Port,
"ip": task.Ip,
"costMs": task.CostMs,
"level": task.Level,
"levelName": reporterconfigs.FindReportLevelName(task.Level),
"connectivity": math.Ceil(float64(task.Connectivity*100)) / 100,
"node": nodeMap,
})
}
this.Data["tasks"] = taskMaps
} else {
this.Data["page"] = ""
this.Data["tasks"] = []maps.Map{}
}
this.Show()
}

View File

@@ -0,0 +1,60 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
//go:build plus
package monitors
import (
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
"github.com/TeaOSLab/EdgeAdmin/internal/plus"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/clusterutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/monitors/groups"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/monitors/groups/group"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/monitors/reporters"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/monitors/reporters/reporter"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/monitors/settings"
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/iwind/TeaGo"
)
func init() {
TeaGo.BeforeStart(func(server *TeaGo.Server) {
server.
Helper(plus.NewHelper(plus.ComponentCodeReporter)).
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeNode)).
Helper(clusterutils.NewClustersHelper()).
Data("teaMenu", "clusters").
Data("teaSubMenu", "monitor").
Prefix("/clusters/monitors").
Get("", new(IndexAction)).
Get("/logs", new(LogsAction)).
// 终端列表
Prefix("/clusters/monitors/reporters").
Get("", new(reporters.IndexAction)).
GetPost("/createPopup", new(reporters.CreatePopupAction)).
// 终端
Prefix("/clusters/monitors/reporters/reporter").
Get("", new(reporter.IndexAction)).
GetPost("/update", new(reporter.UpdateAction)).
Post("/delete", new(reporter.DeleteAction)).
Get("/logs", new(reporter.LogsAction)).
Get("/results", new(reporter.ResultsAction)).
// 分组列表
Prefix("/clusters/monitors/groups").
Get("", new(groups.IndexAction)).
GetPost("/createPopup", new(groups.CreatePopupAction)).
Post("/options", new(groups.OptionsAction)).
// 分组
Prefix("/clusters/monitors/groups/group").
GetPost("/updatePopup", new(group.UpdatePopupAction)).
Post("/delete", new(group.DeleteAction)).
// 设置
Prefix("/clusters/monitors/settings").
GetPost("", new(settings.IndexAction)).
EndAll()
})
}

View File

@@ -0,0 +1,18 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
//go:build plus
package monitors
import "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
type LogsAction struct {
actionutils.ParentAction
}
func (this *LogsAction) Init() {
this.Nav("", "", "log")
}
func (this *LogsAction) RunGet(params struct{}) {
this.Show()
}

View File

@@ -0,0 +1,77 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
//go:build plus
package reporters
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
"github.com/iwind/TeaGo/actions"
)
type CreatePopupAction struct {
actionutils.ParentAction
}
func (this *CreatePopupAction) Init() {
this.Nav("", "", "")
}
func (this *CreatePopupAction) RunGet(params struct{}) {
this.Show()
}
func (this *CreatePopupAction) RunPost(params struct {
Name string
ReportNodeGroupIdsJSON []byte
Location string
Isp string
AllowIPs []string
Must *actions.Must
CSRF *actionutils.CSRF
}) {
var reporterId int64 = 0
defer func() {
this.CreateLogInfo(codes.ReportNode_LogCreateReportNode, reporterId)
}()
params.Must.
Field("name", params.Name).
Require("请输入终端名称")
for _, allowIP := range params.AllowIPs {
_, err := shared.ParseIPRange(allowIP)
if err != nil {
this.Fail("'" + allowIP + "'不是正确的IP或者IP范围格式")
}
}
var groupIds = []int64{}
if len(params.ReportNodeGroupIdsJSON) > 0 {
err := json.Unmarshal(params.ReportNodeGroupIdsJSON, &groupIds)
if err != nil {
this.ErrorPage(err)
return
}
}
createResp, err := this.RPC().ReportNodeRPC().CreateReportNode(this.AdminContext(), &pb.CreateReportNodeRequest{
Name: params.Name,
Location: params.Location,
Isp: params.Isp,
AllowIPs: params.AllowIPs,
ReportNodeGroupIds: groupIds,
})
if err != nil {
this.ErrorPage(err)
return
}
reporterId = createResp.ReportNodeId
this.Success()
}

View File

@@ -0,0 +1,119 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
//go:build plus
package reporters
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/reporterconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
stringutil "github.com/iwind/TeaGo/utils/string"
"time"
)
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("", "", "reporter")
}
func (this *IndexAction) RunGet(params struct {
GroupId int64
Keyword string
}) {
this.Data["groupId"] = params.GroupId
this.Data["keyword"] = params.Keyword
// 所有分组
groupsResp, err := this.RPC().ReportNodeGroupRPC().FindAllEnabledReportNodeGroups(this.AdminContext(), &pb.FindAllEnabledReportNodeGroupsRequest{})
if err != nil {
this.ErrorPage(err)
return
}
var groupMaps = []maps.Map{}
for _, group := range groupsResp.ReportNodeGroups {
groupMaps = append(groupMaps, maps.Map{
"id": group.Id,
"name": group.Name,
})
}
this.Data["groups"] = groupMaps
countResp, err := this.RPC().ReportNodeRPC().CountAllEnabledReportNodes(this.AdminContext(), &pb.CountAllEnabledReportNodesRequest{
ReportNodeGroupId: params.GroupId,
Keyword: params.Keyword,
})
if err != nil {
this.ErrorPage(err)
return
}
var count = countResp.Count
var page = this.NewPage(count)
this.Data["page"] = page.AsHTML()
versionResp, err := this.RPC().ReportNodeRPC().FindLatestReportNodeVersion(this.AdminContext(), &pb.FindLatestReportNodeVersionRequest{})
if err != nil {
this.ErrorPage(err)
return
}
var latestVersion = versionResp.Version
reportersResp, err := this.RPC().ReportNodeRPC().ListEnabledReportNodes(this.AdminContext(), &pb.ListEnabledReportNodesRequest{
ReportNodeGroupId: params.GroupId,
Keyword: params.Keyword,
Offset: page.Offset,
Size: page.Size,
})
if err != nil {
this.ErrorPage(err)
return
}
var reporterMaps = []maps.Map{}
for _, reporter := range reportersResp.ReportNodes {
// 状态
var status = &reporterconfigs.Status{}
if len(reporter.StatusJSON) > 0 {
err = json.Unmarshal(reporter.StatusJSON, status)
if err != nil {
this.ErrorPage(err)
return
}
}
// 版本
var shouldUpgrade = false
if len(status.BuildVersion) > 0 && stringutil.VersionCompare(latestVersion, status.BuildVersion) > 0 {
shouldUpgrade = true
}
// 分组
var groupMaps = []maps.Map{}
for _, group := range reporter.ReportNodeGroups {
groupMaps = append(groupMaps, maps.Map{
"id": group.Id,
"name": group.Name,
})
}
reporterMaps = append(reporterMaps, maps.Map{
"id": reporter.Id,
"name": reporter.Name,
"location": reporter.Location,
"isp": reporter.Isp,
"isOn": reporter.IsOn,
"isActive": reporter.IsActive && time.Now().Unix()-status.UpdatedAt < 60,
"status": status,
"shouldUpgrade": shouldUpgrade,
"newVersion": latestVersion,
"groups": groupMaps,
})
}
this.Data["reporters"] = reporterMaps
this.Show()
}

View File

@@ -0,0 +1,28 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
//go:build plus
package reporter
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
)
type DeleteAction struct {
actionutils.ParentAction
}
func (this *DeleteAction) RunPost(params struct {
ReporterId int64
}) {
defer this.CreateLogInfo(codes.ReportNode_LogDeleteReportNode, params.ReporterId)
_, err := this.RPC().ReportNodeRPC().DeleteReportNode(this.AdminContext(), &pb.DeleteReportNodeRequest{ReportNodeId: params.ReporterId})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,84 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
//go:build plus
package reporter
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/monitors/reporters/reporter/reporterutils"
"github.com/TeaOSLab/EdgeCommon/pkg/reporterconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
"strings"
"time"
)
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("", "", "reporter")
}
func (this *IndexAction) RunGet(params struct {
ReporterId int64
}) {
reporter, err := reporterutils.InitReporter(this.Parent(), params.ReporterId)
if err != nil {
this.ErrorPage(err)
return
}
// 状态
var status = &reporterconfigs.Status{}
if len(reporter.StatusJSON) > 0 {
err = json.Unmarshal(reporter.StatusJSON, status)
if err != nil {
this.ErrorPage(err)
return
}
}
// 分组
var groupMaps = []maps.Map{}
for _, group := range reporter.ReportNodeGroups {
groupMaps = append(groupMaps, maps.Map{
"id": group.Id,
"name": group.Name,
})
}
this.Data["reporter"] = maps.Map{
"id": reporter.Id,
"isOn": reporter.IsOn,
"name": reporter.Name,
"location": reporter.Location,
"isp": reporter.Isp,
"allowIPs": reporter.AllowIPs,
"isActive": reporter.IsActive && time.Now().Unix()-status.UpdatedAt < 60,
"status": status,
"uniqueId": reporter.UniqueId,
"secret": reporter.Secret,
"groups": groupMaps,
}
// API节点列表
apiNodesResp, err := this.RPC().APINodeRPC().FindAllEnabledAPINodes(this.AdminContext(), &pb.FindAllEnabledAPINodesRequest{})
if err != nil {
this.ErrorPage(err)
return
}
apiNodes := apiNodesResp.ApiNodes
apiEndpoints := []string{}
for _, apiNode := range apiNodes {
if !apiNode.IsOn {
continue
}
apiEndpoints = append(apiEndpoints, apiNode.AccessAddrs...)
}
this.Data["apiEndpoints"] = "\"" + strings.Join(apiEndpoints, "\", \"") + "\""
this.Show()
}

View File

@@ -0,0 +1,87 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
//go:build plus
package reporter
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/monitors/reporters/reporter/reporterutils"
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
timeutil "github.com/iwind/TeaGo/utils/time"
)
type LogsAction struct {
actionutils.ParentAction
}
func (this *LogsAction) Init() {
this.Nav("", "", "log")
}
func (this *LogsAction) RunGet(params struct {
ReporterId int64
DayFrom string
DayTo string
Keyword string
Level string
}) {
_, err := reporterutils.InitReporter(this.Parent(), params.ReporterId)
if err != nil {
this.ErrorPage(err)
return
}
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{
Role: nodeconfigs.NodeRoleReport,
NodeId: params.ReporterId,
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, 20)
logsResp, err := this.RPC().NodeLogRPC().ListNodeLogs(this.AdminContext(), &pb.ListNodeLogsRequest{
NodeId: params.ReporterId,
Role: nodeconfigs.NodeRoleReport,
DayFrom: params.DayFrom,
DayTo: params.DayTo,
Keyword: params.Keyword,
Level: params.Level,
Offset: page.Offset,
Size: page.Size,
})
if err != nil {
this.ErrorPage(err)
return
}
logs := []maps.Map{}
for _, log := range logsResp.NodeLogs {
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"),
"count": log.Count,
})
}
this.Data["logs"] = logs
this.Data["page"] = page.AsHTML()
this.Show()
}

View File

@@ -0,0 +1,35 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
//go:build plus
package reporterutils
import (
"errors"
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
"github.com/iwind/TeaGo/types"
)
func InitReporter(parent *actionutils.ParentAction, reporterId int64) (*pb.ReportNode, error) {
rpcClient, err := rpc.SharedRPC()
if err != nil {
return nil, err
}
reporterResp, err := rpcClient.ReportNodeRPC().FindEnabledReportNode(parent.AdminContext(), &pb.FindEnabledReportNodeRequest{ReportNodeId: reporterId})
if err != nil {
return nil, err
}
var reporter = reporterResp.ReportNode
if reporter == nil {
return nil, errors.New("reporter with id '" + types.String(reporterId) + "' not found")
}
parent.Data["reporter"] = maps.Map{
"id": reporter.Id,
"name": reporter.Name,
}
return reporter, nil
}

View File

@@ -0,0 +1,79 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
//go:build plus
package reporter
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/monitors/reporters/reporter/reporterutils"
"github.com/TeaOSLab/EdgeCommon/pkg/reporterconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
timeutil "github.com/iwind/TeaGo/utils/time"
)
type ResultsAction struct {
actionutils.ParentAction
}
func (this *ResultsAction) Init() {
this.Nav("", "", "result")
}
func (this *ResultsAction) RunGet(params struct {
ReporterId int64
Level string
}) {
this.Data["level"] = params.Level
this.Data["levels"] = reporterconfigs.FindAllReportLevels()
_, err := reporterutils.InitReporter(this.Parent(), params.ReporterId)
if err != nil {
this.ErrorPage(err)
return
}
countResp, err := this.RPC().ReportResultRPC().CountAllReportResults(this.AdminContext(), &pb.CountAllReportResultsRequest{
ReportNodeId: params.ReporterId,
Level: params.Level,
})
if err != nil {
this.ErrorPage(err)
return
}
var count = countResp.Count
page := this.NewPage(count)
this.Data["page"] = page.AsHTML()
resultsResp, err := this.RPC().ReportResultRPC().ListReportResults(this.AdminContext(), &pb.ListReportResultsRequest{
ReportNodeId: params.ReporterId,
Level: params.Level,
Offset: page.Offset,
Size: page.Size,
})
if err != nil {
this.ErrorPage(err)
return
}
var resultMaps = []maps.Map{}
for _, result := range resultsResp.ReportResults {
resultMaps = append(resultMaps, maps.Map{
"id": result.Id,
"type": result.Type,
"typeName": reporterconfigs.FindTaskTypeName(result.Type),
"targetId": result.TargetId,
"targetDesc": result.TargetDesc,
"isOk": result.IsOk,
"error": result.Error,
"costMs": result.CostMs,
"updatedTime": timeutil.FormatTime("H:i:s", result.UpdatedAt),
"level": result.Level,
"levelName": reporterconfigs.FindReportLevelName(result.Level),
"updateTime": timeutil.FormatTime("H:i:s", result.UpdatedAt),
})
}
this.Data["results"] = resultMaps
this.Show()
}

View File

@@ -0,0 +1,101 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
//go:build plus
package reporter
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/monitors/reporters/reporter/reporterutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
)
type UpdateAction struct {
actionutils.ParentAction
}
func (this *UpdateAction) Init() {
this.Nav("", "", "update")
}
func (this *UpdateAction) RunGet(params struct {
ReporterId int64
}) {
reporter, err := reporterutils.InitReporter(this.Parent(), params.ReporterId)
if err != nil {
this.ErrorPage(err)
return
}
var groupIds = []int64{}
for _, group := range reporter.ReportNodeGroups {
groupIds = append(groupIds, group.Id)
}
this.Data["reporter"] = maps.Map{
"id": reporter.Id,
"name": reporter.Name,
"location": reporter.Location,
"isp": reporter.Isp,
"isOn": reporter.IsOn,
"allowIPs": reporter.AllowIPs,
"groupIds": groupIds,
}
this.Show()
}
func (this *UpdateAction) RunPost(params struct {
ReporterId int64
Name string
ReportNodeGroupIdsJSON []byte
Location string
Isp string
AllowIPs []string
IsOn bool
Must *actions.Must
CSRF *actionutils.CSRF
}) {
defer this.CreateLogInfo(codes.ReportNode_LogUpdateReportNode, params.ReporterId)
params.Must.
Field("name", params.Name).
Require("请输入终端名称")
for _, allowIP := range params.AllowIPs {
_, err := shared.ParseIPRange(allowIP)
if err != nil {
this.Fail("'" + allowIP + "'不是正确的IP或者IP范围格式")
}
}
var groupIds = []int64{}
if len(params.ReportNodeGroupIdsJSON) > 0 {
err := json.Unmarshal(params.ReportNodeGroupIdsJSON, &groupIds)
if err != nil {
this.ErrorPage(err)
return
}
}
_, err := this.RPC().ReportNodeRPC().UpdateReportNode(this.AdminContext(), &pb.UpdateReportNodeRequest{
ReportNodeId: params.ReporterId,
Name: params.Name,
Location: params.Location,
Isp: params.Isp,
AllowIPs: params.AllowIPs,
IsOn: params.IsOn,
ReportNodeGroupIds: groupIds,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,74 @@
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
//go:build plus
package settings
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/reporterconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
"regexp"
)
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("", "", "setting")
}
func (this *IndexAction) RunGet(params struct{}) {
settingResp, err := this.RPC().ReportNodeRPC().ReadReportNodeGlobalSetting(this.AdminContext(), &pb.ReadReportNodeGlobalSettingRequest{})
if err != nil {
this.ErrorPage(err)
return
}
var setting = reporterconfigs.DefaultGlobalSetting()
err = json.Unmarshal(settingResp.SettingJSON, setting)
if err != nil {
this.ErrorPage(err)
return
}
this.Data["setting"] = setting
this.Show()
}
func (this *IndexAction) RunPost(params struct {
MinNotifyConnectivity float64
NotifyWebHookURL string
Must *actions.Must
CSRF *actionutils.CSRF
}) {
params.Must.
Field("minNotifyConnectivity", params.MinNotifyConnectivity).
Gte(0, "提醒连通性阈值取值在0到100之间").
Lte(100, "提醒连通性阈值取值在0到100之间")
if len(params.NotifyWebHookURL) > 0 && !regexp.MustCompile(`(?i)^(http|https)://`).MatchString(params.NotifyWebHookURL) {
this.FailField("notifyWebHookURL", "通知URL请以http://或者https://开头")
}
var setting = reporterconfigs.DefaultGlobalSetting()
setting.MinNotifyConnectivity = params.MinNotifyConnectivity
setting.NotifyWebHookURL = params.NotifyWebHookURL
settingJSON, err := json.Marshal(setting)
if err != nil {
this.ErrorPage(err)
return
}
_, err = this.RPC().ReportNodeRPC().UpdateReportNodeGlobalSetting(this.AdminContext(), &pb.UpdateReportNodeGlobalSetting{SettingJSON: settingJSON})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}