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()
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package ipaddrs
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||
"github.com/tealeg/xlsx/v3"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type ExportExcelAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *ExportExcelAction) Init() {
|
||||
this.Nav("", "", "index")
|
||||
}
|
||||
|
||||
func (this *ExportExcelAction) RunGet(params struct {
|
||||
ClusterId int64
|
||||
UpState int8
|
||||
Keyword string
|
||||
}) {
|
||||
addrsResp, err := this.RPC().NodeIPAddressRPC().ListEnabledNodeIPAddresses(this.AdminContext(), &pb.ListEnabledNodeIPAddressesRequest{
|
||||
NodeClusterId: params.ClusterId,
|
||||
Role: nodeconfigs.NodeRoleNode,
|
||||
UpState: int32(params.UpState),
|
||||
Keyword: params.Keyword,
|
||||
Offset: 0,
|
||||
Size: 100000,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var wb = xlsx.NewFile()
|
||||
sheet, err := wb.AddSheet("default")
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
// 头部
|
||||
{
|
||||
var row = sheet.AddRow()
|
||||
row.SetHeight(25)
|
||||
row.AddCell().SetString("IP")
|
||||
row.AddCell().SetString("所属集群")
|
||||
row.AddCell().SetString("所属节点")
|
||||
row.AddCell().SetString("名称")
|
||||
row.AddCell().SetString("状态")
|
||||
}
|
||||
|
||||
var nodeCacheMap = map[int64]*pb.FindEnabledBasicNodeResponse{} // node id => Response
|
||||
|
||||
for _, addr := range addrsResp.NodeIPAddresses {
|
||||
nodeResp, ok := nodeCacheMap[addr.NodeId]
|
||||
if !ok {
|
||||
nodeResp, err = this.RPC().NodeRPC().FindEnabledBasicNode(this.AdminContext(), &pb.FindEnabledBasicNodeRequest{NodeId: addr.NodeId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
nodeCacheMap[addr.NodeId] = nodeResp
|
||||
}
|
||||
var node = nodeResp.Node
|
||||
if node == nil || node.NodeCluster == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
var row = sheet.AddRow()
|
||||
row.SetHeight(25)
|
||||
row.AddCell().SetString(addr.Ip)
|
||||
row.AddCell().SetString(node.NodeCluster.Name)
|
||||
row.AddCell().SetString(node.Name)
|
||||
row.AddCell().SetString(node.Name)
|
||||
|
||||
var statusName string
|
||||
var statusIsOk = false
|
||||
if !addr.IsOn {
|
||||
statusName = "禁用"
|
||||
} else if !addr.CanAccess {
|
||||
statusName = "不公开访问"
|
||||
} else if addr.IsUp && len(addr.BackupIP) > 0 {
|
||||
statusName = "切换到备用"
|
||||
} else if addr.IsUp {
|
||||
statusName = "在线"
|
||||
statusIsOk = true
|
||||
} else {
|
||||
statusName = "离线"
|
||||
}
|
||||
var statusCell = row.AddCell()
|
||||
statusCell.SetString(statusName)
|
||||
var statusStyle = statusCell.GetStyle()
|
||||
if statusIsOk {
|
||||
statusStyle.Font.Color = xlsx.RGB_Dark_Green
|
||||
} else {
|
||||
statusStyle.Font.Color = xlsx.RGB_Dark_Red
|
||||
}
|
||||
statusCell.SetStyle(statusStyle)
|
||||
|
||||
}
|
||||
|
||||
this.AddHeader("Content-Type", "application/vnd.ms-excel")
|
||||
this.AddHeader("Content-Disposition", "attachment; filename=\"Node-IP-"+timeutil.Format("YmdHis")+".xlsx\"")
|
||||
this.AddHeader("Cache-Control", "max-age=0")
|
||||
|
||||
var buf = bytes.NewBuffer([]byte{})
|
||||
err = wb.Write(buf)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.AddHeader("Content-Length", strconv.Itoa(buf.Len()))
|
||||
_, _ = this.Write(buf.Bytes())
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package ipaddrs
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.Nav("", "", "index")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct {
|
||||
ClusterId int64
|
||||
UpState int8
|
||||
Keyword string
|
||||
}) {
|
||||
this.Data["clusterId"] = params.ClusterId
|
||||
this.Data["upState"] = params.UpState
|
||||
this.Data["keyword"] = params.Keyword
|
||||
|
||||
countResp, err := this.RPC().NodeIPAddressRPC().CountAllEnabledNodeIPAddresses(this.AdminContext(), &pb.CountAllEnabledNodeIPAddressesRequest{
|
||||
NodeClusterId: params.ClusterId,
|
||||
Role: nodeconfigs.NodeRoleNode,
|
||||
UpState: int32(params.UpState),
|
||||
Keyword: params.Keyword,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var count = countResp.Count
|
||||
var page = this.NewPage(count)
|
||||
this.Data["page"] = page.AsHTML()
|
||||
|
||||
addrsResp, err := this.RPC().NodeIPAddressRPC().ListEnabledNodeIPAddresses(this.AdminContext(), &pb.ListEnabledNodeIPAddressesRequest{
|
||||
NodeClusterId: params.ClusterId,
|
||||
Role: nodeconfigs.NodeRoleNode,
|
||||
UpState: int32(params.UpState),
|
||||
Keyword: params.Keyword,
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var addrMaps = []maps.Map{}
|
||||
for _, addr := range addrsResp.NodeIPAddresses {
|
||||
nodeResp, err := this.RPC().NodeRPC().FindEnabledBasicNode(this.AdminContext(), &pb.FindEnabledBasicNodeRequest{NodeId: addr.NodeId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var node = nodeResp.Node
|
||||
if node == nil || node.NodeCluster == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
// 阈值数量
|
||||
countThresholdsResp, err := this.RPC().NodeIPAddressThresholdRPC().CountAllEnabledNodeIPAddressThresholds(this.AdminContext(), &pb.CountAllEnabledNodeIPAddressThresholdsRequest{NodeIPAddressId: addr.Id})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var countThresholds = countThresholdsResp.Count
|
||||
|
||||
// 专属集群
|
||||
var clusterMaps = []maps.Map{}
|
||||
for _, cluster := range addr.NodeClusters {
|
||||
clusterMaps = append(clusterMaps, maps.Map{
|
||||
"id": cluster.Id,
|
||||
"name": cluster.Name,
|
||||
})
|
||||
}
|
||||
|
||||
addrMaps = append(addrMaps, maps.Map{
|
||||
"id": addr.Id,
|
||||
"name": addr.Name,
|
||||
"description": addr.Description,
|
||||
"ip": addr.Ip,
|
||||
"canAccess": addr.CanAccess,
|
||||
"isOn": addr.IsOn,
|
||||
"isUp": addr.IsUp,
|
||||
"isHealthy": addr.IsHealthy,
|
||||
"hasThresholds": countThresholds > 0,
|
||||
"node": maps.Map{"id": node.Id, "name": node.Name},
|
||||
"cluster": maps.Map{"id": node.NodeCluster.Id, "name": node.NodeCluster.Name},
|
||||
"backupIP": addr.BackupIP,
|
||||
"clusters": clusterMaps,
|
||||
})
|
||||
}
|
||||
this.Data["addrs"] = addrMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
//go:build plus
|
||||
|
||||
package ipaddrs
|
||||
|
||||
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/ip-addrs/addr"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
||||
"github.com/iwind/TeaGo"
|
||||
)
|
||||
|
||||
func init() {
|
||||
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
||||
server.
|
||||
Helper(plus.NewHelper(plus.ComponentCodeScheduling)).
|
||||
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeNode)).
|
||||
Helper(clusterutils.NewClustersHelper()).
|
||||
Data("teaMenu", "clusters").
|
||||
Data("teaSubMenu", "ipAddr").
|
||||
Prefix("/clusters/ip-addrs").
|
||||
Get("", new(IndexAction)).
|
||||
Get("/logs", new(LogsAction)).
|
||||
Get("/exportExcel", new(ExportExcelAction)).
|
||||
|
||||
// 单个地址操作
|
||||
Post("/addr/delete", new(addr.DeleteAction)).
|
||||
Get("/addr", new(addr.IndexAction)).
|
||||
GetPost("/addr/update", new(addr.UpdateAction)).
|
||||
Get("/addr/logs", new(addr.LogsAction)).
|
||||
Post("/addr/up", new(addr.UpAction)).
|
||||
Post("/addr/restoreBackup", new(addr.RestoreBackupAction)).
|
||||
Get("/addr/reports", new(addr.ReportsAction)).
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package ipaddrutils
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"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 InitIPAddr(parent *actionutils.ParentAction, addrId int64) (*pb.NodeIPAddress, error) {
|
||||
addrResp, err := parent.RPC().NodeIPAddressRPC().FindEnabledNodeIPAddress(parent.AdminContext(), &pb.FindEnabledNodeIPAddressRequest{NodeIPAddressId: addrId})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var addr = addrResp.NodeIPAddress
|
||||
if addr == nil {
|
||||
return nil, errors.New("nodeIPAddress with id '" + types.String(addrId) + "' not found")
|
||||
}
|
||||
|
||||
parent.Data["addr"] = maps.Map{
|
||||
"id": addr.Id,
|
||||
"name": addr.Name,
|
||||
"ip": addr.Ip,
|
||||
}
|
||||
|
||||
return addr, nil
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package ipaddrs
|
||||
|
||||
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/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 {
|
||||
}) {
|
||||
countResp, err := this.RPC().NodeIPAddressLogRPC().CountAllNodeIPAddressLogs(this.AdminContext(), &pb.CountAllNodeIPAddressLogsRequest{})
|
||||
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{
|
||||
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) + "]",
|
||||
}
|
||||
}
|
||||
|
||||
var addrMap maps.Map
|
||||
if log.NodeIPAddress != nil {
|
||||
var addr = log.NodeIPAddress
|
||||
if addr != nil {
|
||||
addrMap = maps.Map{
|
||||
"id": addr.Id,
|
||||
"ip": addr.Ip,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
"addr": addrMap,
|
||||
})
|
||||
}
|
||||
this.Data["logs"] = logMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
Reference in New Issue
Block a user