mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-03 20:40:26 +08:00
健康检查设置域名时检查域名是否存在
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
|
||||
package health
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"net"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type CheckDomainAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *CheckDomainAction) RunPost(params struct {
|
||||
Host string
|
||||
ClusterId int64
|
||||
}) {
|
||||
this.Data["isOk"] = true // 默认为TRUE
|
||||
|
||||
var host = params.Host
|
||||
if len(host) > 0 &&
|
||||
!strings.Contains(host, "{") /** 包含变量 **/ {
|
||||
h, _, err := net.SplitHostPort(host)
|
||||
if err == nil && len(h) > 0 {
|
||||
host = h
|
||||
}
|
||||
|
||||
// 是否为IP
|
||||
if net.ParseIP(host) != nil {
|
||||
this.Success()
|
||||
return
|
||||
}
|
||||
|
||||
host = strings.ToLower(host)
|
||||
resp, err := this.RPC().ServerRPC().CheckServerNameDuplicationInNodeCluster(this.AdminContext(), &pb.CheckServerNameDuplicationInNodeClusterRequest{
|
||||
NodeClusterId: params.ClusterId,
|
||||
ServerNames: []string{host},
|
||||
SupportWildcard: true,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if len(resp.DuplicatedServerNames) == 0 {
|
||||
this.Data["isOk"] = false
|
||||
}
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -29,6 +29,7 @@ func init() {
|
||||
// 健康检查
|
||||
GetPost("/health", new(health.IndexAction)).
|
||||
GetPost("/health/runPopup", new(health.RunPopupAction)).
|
||||
Post("/health/checkDomain", new(health.CheckDomainAction)).
|
||||
|
||||
// 缓存
|
||||
GetPost("/cache", new(cache.IndexAction)).
|
||||
|
||||
Reference in New Issue
Block a user