mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-12-30 14:56:34 +08:00
实现健康检查配置、立即执行健康检查
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
package ipAddresses
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"net"
|
||||
)
|
||||
|
||||
type CreatePopupAction struct {
|
||||
@@ -20,31 +20,28 @@ func (this *CreatePopupAction) RunGet(params struct{}) {
|
||||
}
|
||||
|
||||
func (this *CreatePopupAction) RunPost(params struct {
|
||||
IP string `alias:"ip"`
|
||||
Name string
|
||||
IP string `alias:"ip"`
|
||||
CanAccess bool
|
||||
Name string
|
||||
|
||||
Must *actions.Must
|
||||
}) {
|
||||
// TODO 严格校验IP地址
|
||||
|
||||
ip := net.ParseIP(params.IP)
|
||||
if len(ip) == 0 {
|
||||
this.Fail("请输入正确的IP")
|
||||
}
|
||||
|
||||
params.Must.
|
||||
Field("ip", params.IP).
|
||||
Require("请输入IP地址")
|
||||
|
||||
resp, err := this.RPC().NodeIPAddressRPC().CreateNodeIPAddress(this.AdminContext(), &pb.CreateNodeIPAddressRequest{
|
||||
NodeId: 0,
|
||||
Name: params.Name,
|
||||
Ip: params.IP,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["ipAddress"] = maps.Map{
|
||||
"name": params.Name,
|
||||
"ip": params.IP,
|
||||
"id": resp.AddressId,
|
||||
"name": params.Name,
|
||||
"canAccess": params.CanAccess,
|
||||
"ip": params.IP,
|
||||
"id": 0,
|
||||
}
|
||||
this.Success()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package ipaddressutils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
// 保存一组IP地址
|
||||
func UpdateNodeIPAddresses(parentAction *actionutils.ParentAction, nodeId int64, ipAddressesJSON []byte) error {
|
||||
addresses := []maps.Map{}
|
||||
err := json.Unmarshal(ipAddressesJSON, &addresses)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, addr := range addresses {
|
||||
addrId := addr.GetInt64("id")
|
||||
if addrId > 0 {
|
||||
_, err = parentAction.RPC().NodeIPAddressRPC().UpdateNodeIPAddress(parentAction.AdminContext(), &pb.UpdateNodeIPAddressRequest{
|
||||
AddressId: addrId,
|
||||
Ip: addr.GetString("ip"),
|
||||
Name: addr.GetString("name"),
|
||||
CanAccess: addr.GetBool("canAccess"),
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
_, err = parentAction.RPC().NodeIPAddressRPC().CreateNodeIPAddress(parentAction.AdminContext(), &pb.CreateNodeIPAddressRequest{
|
||||
NodeId: nodeId,
|
||||
Name: addr.GetString("name"),
|
||||
Ip: addr.GetString("ip"),
|
||||
CanAccess: addr.GetBool("canAccess"),
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package ipAddresses
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"net"
|
||||
)
|
||||
|
||||
type UpdatePopupAction struct {
|
||||
@@ -18,23 +18,6 @@ func (this *UpdatePopupAction) Init() {
|
||||
func (this *UpdatePopupAction) RunGet(params struct {
|
||||
AddressId int64
|
||||
}) {
|
||||
addressResp, err := this.RPC().NodeIPAddressRPC().FindEnabledNodeIPAddress(this.AdminContext(), &pb.FindEnabledNodeIPAddressRequest{AddressId: params.AddressId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
address := addressResp.IpAddress
|
||||
if address == nil {
|
||||
this.WriteString("找不到要修改的IP地址")
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["address"] = maps.Map{
|
||||
"id": address.Id,
|
||||
"name": address.Name,
|
||||
"ip": address.Ip,
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
@@ -42,6 +25,7 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
||||
AddressId int64
|
||||
IP string `alias:"ip"`
|
||||
Name string
|
||||
CanAccess bool
|
||||
|
||||
Must *actions.Must
|
||||
}) {
|
||||
@@ -51,20 +35,16 @@ func (this *UpdatePopupAction) RunPost(params struct {
|
||||
Field("ip", params.IP).
|
||||
Require("请输入IP地址")
|
||||
|
||||
_, err := this.RPC().NodeIPAddressRPC().UpdateNodeIPAddress(this.AdminContext(), &pb.UpdateNodeIPAddressRequest{
|
||||
AddressId: params.AddressId,
|
||||
Name: params.Name,
|
||||
Ip: params.IP,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
ip := net.ParseIP(params.IP)
|
||||
if len(ip) == 0 {
|
||||
this.Fail("请输入正确的IP")
|
||||
}
|
||||
|
||||
this.Data["ipAddress"] = maps.Map{
|
||||
"name": params.Name,
|
||||
"ip": params.IP,
|
||||
"id": params.AddressId,
|
||||
"name": params.Name,
|
||||
"ip": params.IP,
|
||||
"id": params.AddressId,
|
||||
"canAccess": params.CanAccess,
|
||||
}
|
||||
|
||||
this.Success()
|
||||
|
||||
Reference in New Issue
Block a user