Initial commit (code only without large binaries)
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package addr
|
||||
|
||||
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 {
|
||||
AddrId int64
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.NodeIPAddress_LogDeleteNodeIPAddress, params.AddrId)
|
||||
|
||||
_, err := this.RPC().NodeIPAddressRPC().DisableNodeIPAddress(this.AdminContext(), &pb.DisableNodeIPAddressRequest{NodeIPAddressId: params.AddrId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
//go:build plus
|
||||
|
||||
package addr
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/ip-addrs/ipaddrutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes/ipAddresses/ipaddressutils"
|
||||
"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 IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.Nav("", "", "addr")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct {
|
||||
AddrId int64
|
||||
}) {
|
||||
addr, err := ipaddrutils.InitIPAddr(this.Parent(), params.AddrId)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
nodeResp, err := this.RPC().NodeRPC().FindEnabledNode(this.AdminContext(), &pb.FindEnabledNodeRequest{NodeId: addr.NodeId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var node = nodeResp.Node
|
||||
if node == nil || node.NodeCluster == nil {
|
||||
this.ErrorPage(errors.New("node or cluster is not available"))
|
||||
return
|
||||
}
|
||||
|
||||
// 集群
|
||||
var nodeClusters = []*pb.NodeCluster{}
|
||||
if node.NodeCluster != nil {
|
||||
nodeClusters = append(nodeClusters, node.NodeCluster)
|
||||
}
|
||||
if node.SecondaryNodeClusters != nil {
|
||||
nodeClusters = append(nodeClusters, node.SecondaryNodeClusters...)
|
||||
}
|
||||
var clusterIdMap = map[int64]bool{}
|
||||
for _, cluster := range nodeClusters {
|
||||
clusterIdMap[cluster.Id] = true
|
||||
}
|
||||
|
||||
var addrClusterMaps = []maps.Map{}
|
||||
if len(addr.NodeClusters) > 0 {
|
||||
for _, cluster := range addr.NodeClusters {
|
||||
// 检查IP地址设置的集群是否仍然有效
|
||||
_, ok := clusterIdMap[cluster.Id]
|
||||
if ok {
|
||||
addrClusterMaps = append(addrClusterMaps, maps.Map{
|
||||
"id": cluster.Id,
|
||||
"name": cluster.Name,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 阈值
|
||||
thresholds, err := ipaddressutils.InitNodeIPAddressThresholds(this.Parent(), params.AddrId)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["addr"] = maps.Map{
|
||||
"id": addr.Id,
|
||||
"name": addr.Name,
|
||||
"description": addr.Description,
|
||||
"ip": addr.Ip,
|
||||
"canAccess": addr.CanAccess,
|
||||
"isOn": addr.IsOn,
|
||||
"isUp": addr.IsUp,
|
||||
"node": maps.Map{"id": node.Id, "name": node.Name},
|
||||
"cluster": maps.Map{"id": node.NodeCluster.Id, "name": node.NodeCluster.Name},
|
||||
"thresholds": thresholds,
|
||||
"backupIP": addr.BackupIP,
|
||||
"clusters": addrClusterMaps,
|
||||
}
|
||||
|
||||
// 监控
|
||||
resultsResp, err := this.RPC().ReportResultRPC().FindAllReportResults(this.AdminContext(), &pb.FindAllReportResultsRequest{
|
||||
Type: reporterconfigs.TaskTypeIPAddr,
|
||||
TargetId: params.AddrId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var resultMaps = []maps.Map{}
|
||||
for _, result := range resultsResp.ReportResults {
|
||||
reportNodeResp, err := this.RPC().ReportNodeRPC().FindEnabledReportNode(this.AdminContext(), &pb.FindEnabledReportNodeRequest{ReportNodeId: result.ReportNodeId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var reportNode = reportNodeResp.ReportNode
|
||||
if reportNode == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
resultMaps = append(resultMaps, maps.Map{
|
||||
"id": result.Id,
|
||||
"type": result.Type,
|
||||
"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),
|
||||
"node": maps.Map{
|
||||
"id": reportNode.Id,
|
||||
"name": reportNode.Name,
|
||||
"location": reportNode.Location,
|
||||
"isp": reportNode.Isp,
|
||||
},
|
||||
})
|
||||
}
|
||||
this.Data["results"] = resultMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package addr
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/ip-addrs/ipaddrutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"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 {
|
||||
AddrId int64
|
||||
}) {
|
||||
_, err := ipaddrutils.InitIPAddr(this.Parent(), params.AddrId)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
countResp, err := this.RPC().NodeIPAddressLogRPC().CountAllNodeIPAddressLogs(this.AdminContext(), &pb.CountAllNodeIPAddressLogsRequest{NodeIPAddressId: params.AddrId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var page = this.NewPage(countResp.Count)
|
||||
this.Data["page"] = page.AsHTML()
|
||||
|
||||
logsResp, err := this.RPC().NodeIPAddressLogRPC().ListNodeIPAddressLogs(this.AdminContext(), &pb.ListNodeIPAddressLogsRequest{
|
||||
NodeIPAddressId: params.AddrId,
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var logMaps = []maps.Map{}
|
||||
for _, log := range logsResp.NodeIPAddressLogs {
|
||||
var adminMap maps.Map
|
||||
if log.Admin != nil {
|
||||
adminMap = maps.Map{
|
||||
"id": log.Admin.Id,
|
||||
"name": log.Admin.Fullname,
|
||||
}
|
||||
} else {
|
||||
adminMap = maps.Map{
|
||||
"id": 0,
|
||||
"name": "[" + this.Lang(codes.AdminCommon_System) + "]",
|
||||
}
|
||||
}
|
||||
|
||||
logMaps = append(logMaps, maps.Map{
|
||||
"id": log.Id,
|
||||
"description": log.Description,
|
||||
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", log.CreatedAt),
|
||||
"isUp": log.IsUp,
|
||||
"isOn": log.IsOn,
|
||||
"canAccess": log.CanAccess,
|
||||
"backupIP": log.BackupIP,
|
||||
"admin": adminMap,
|
||||
})
|
||||
}
|
||||
this.Data["logs"] = logMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
//go:build plus
|
||||
|
||||
package addr
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/ip-addrs/ipaddrutils"
|
||||
"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 ReportsAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *ReportsAction) Init() {
|
||||
this.Nav("", "", "report")
|
||||
}
|
||||
|
||||
func (this *ReportsAction) RunGet(params struct {
|
||||
AddrId int64
|
||||
}) {
|
||||
_, err := ipaddrutils.InitIPAddr(this.Parent(), params.AddrId)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
resultsResp, err := this.RPC().ReportResultRPC().FindAllReportResults(this.AdminContext(), &pb.FindAllReportResultsRequest{
|
||||
Type: reporterconfigs.TaskTypeIPAddr,
|
||||
TargetId: params.AddrId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var resultMaps = []maps.Map{}
|
||||
for _, result := range resultsResp.ReportResults {
|
||||
reportNodeResp, err := this.RPC().ReportNodeRPC().FindEnabledReportNode(this.AdminContext(), &pb.FindEnabledReportNodeRequest{ReportNodeId: result.ReportNodeId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var reportNode = reportNodeResp.ReportNode
|
||||
if reportNode == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
resultMaps = append(resultMaps, maps.Map{
|
||||
"id": result.Id,
|
||||
"type": result.Type,
|
||||
"typeName": reporterconfigs.FindTaskTypeName(result.Type),
|
||||
"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),
|
||||
"node": maps.Map{
|
||||
"id": reportNode.Id,
|
||||
"name": reportNode.Name,
|
||||
"location": reportNode.Location,
|
||||
"isp": reportNode.Isp,
|
||||
},
|
||||
})
|
||||
}
|
||||
this.Data["results"] = resultMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package addr
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
type RestoreBackupAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *RestoreBackupAction) RunPost(params struct {
|
||||
AddrId int64
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.NodeIPAddress_LogRestoreNodeIPAddress, params.AddrId)
|
||||
|
||||
_, err := this.RPC().NodeIPAddressRPC().RestoreNodeIPAddressBackupIP(this.AdminContext(), &pb.RestoreNodeIPAddressBackupIPRequest{
|
||||
NodeIPAddressId: params.AddrId,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package addr
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
)
|
||||
|
||||
type UpAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *UpAction) RunPost(params struct {
|
||||
AddrId int64
|
||||
IsUp bool
|
||||
}) {
|
||||
if params.IsUp {
|
||||
defer this.CreateLogInfo(codes.NodeIPAddress_LogUpNodeIPAddress, params.AddrId)
|
||||
} else {
|
||||
defer this.CreateLogInfo(codes.NodeIPAddress_LogDownNodeIPAddress, params.AddrId)
|
||||
}
|
||||
|
||||
_, err := this.RPC().NodeIPAddressRPC().UpdateNodeIPAddressIsUp(this.AdminContext(), &pb.UpdateNodeIPAddressIsUpRequest{
|
||||
NodeIPAddressId: params.AddrId,
|
||||
IsUp: params.IsUp,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package addr
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/ip-addrs/ipaddrutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/nodes/ipAddresses/ipaddressutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/lists"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"net"
|
||||
)
|
||||
|
||||
type UpdateAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *UpdateAction) Init() {
|
||||
this.Nav("", "", "update")
|
||||
}
|
||||
|
||||
func (this *UpdateAction) RunGet(params struct {
|
||||
AddrId int64
|
||||
}) {
|
||||
addr, err := ipaddrutils.InitIPAddr(this.Parent(), params.AddrId)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["supportThresholds"] = true
|
||||
|
||||
thresholds, err := ipaddressutils.InitNodeIPAddressThresholds(this.Parent(), addr.Id)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
// 默认集群
|
||||
nodeResp, err := this.RPC().NodeRPC().FindEnabledNode(this.AdminContext(), &pb.FindEnabledNodeRequest{NodeId: addr.NodeId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var node = nodeResp.Node
|
||||
if node == nil {
|
||||
this.NotFound("node", addr.NodeId)
|
||||
return
|
||||
}
|
||||
|
||||
var clusters = []*pb.NodeCluster{}
|
||||
if node.NodeCluster != nil {
|
||||
clusters = append(clusters, node.NodeCluster)
|
||||
}
|
||||
if node.SecondaryNodeClusters != nil {
|
||||
clusters = append(clusters, node.SecondaryNodeClusters...)
|
||||
}
|
||||
|
||||
var allClusterIdMap = map[int64]bool{}
|
||||
for _, cluster := range clusters {
|
||||
allClusterIdMap[cluster.Id] = true
|
||||
}
|
||||
|
||||
// 当前地址专属集群
|
||||
var selectedClusterIds = []int64{}
|
||||
if addr.NodeClusters != nil {
|
||||
for _, cluster := range addr.NodeClusters {
|
||||
_, ok := allClusterIdMap[cluster.Id]
|
||||
if ok {
|
||||
selectedClusterIds = append(selectedClusterIds, cluster.Id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var allClusterMaps = []maps.Map{}
|
||||
for _, cluster := range clusters {
|
||||
allClusterMaps = append(allClusterMaps, maps.Map{
|
||||
"id": cluster.Id,
|
||||
"name": cluster.Name,
|
||||
"isChecked": lists.ContainsInt64(selectedClusterIds, cluster.Id),
|
||||
})
|
||||
}
|
||||
this.Data["clusters"] = allClusterMaps
|
||||
|
||||
this.Data["addr"] = maps.Map{
|
||||
"id": addr.Id,
|
||||
"name": addr.Name,
|
||||
"description": addr.Description,
|
||||
"ip": addr.Ip,
|
||||
"canAccess": addr.CanAccess,
|
||||
"isOn": addr.IsOn,
|
||||
"isUp": addr.IsUp,
|
||||
"thresholds": thresholds,
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *UpdateAction) RunPost(params struct {
|
||||
AddrId int64
|
||||
IP string `alias:"ip"`
|
||||
Name string
|
||||
CanAccess bool
|
||||
IsOn bool
|
||||
ThresholdsJSON []byte
|
||||
IsUp bool
|
||||
ClusterIds []int64
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
params.Must.
|
||||
Field("ip", params.IP).
|
||||
Require("请输入IP地址")
|
||||
|
||||
var ip = net.ParseIP(params.IP)
|
||||
if len(ip) == 0 {
|
||||
this.Fail("请输入正确的IP")
|
||||
}
|
||||
|
||||
_, err := this.RPC().NodeIPAddressRPC().UpdateNodeIPAddress(this.AdminContext(), &pb.UpdateNodeIPAddressRequest{
|
||||
NodeIPAddressId: params.AddrId,
|
||||
Name: params.Name,
|
||||
Ip: params.IP,
|
||||
CanAccess: params.CanAccess,
|
||||
IsOn: params.IsOn,
|
||||
IsUp: params.IsUp,
|
||||
ClusterIds: params.ClusterIds,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
// 保存阈值
|
||||
if len(params.ThresholdsJSON) > 0 {
|
||||
_, err = this.RPC().NodeIPAddressThresholdRPC().UpdateAllNodeIPAddressThresholds(this.AdminContext(), &pb.UpdateAllNodeIPAddressThresholdsRequest{
|
||||
NodeIPAddressId: params.AddrId,
|
||||
NodeIPAddressThresholdsJSON: params.ThresholdsJSON,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
_, err = this.RPC().NodeIPAddressThresholdRPC().UpdateAllNodeIPAddressThresholds(this.AdminContext(), &pb.UpdateAllNodeIPAddressThresholdsRequest{
|
||||
NodeIPAddressId: params.AddrId,
|
||||
NodeIPAddressThresholdsJSON: []byte("[]"),
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
Reference in New Issue
Block a user