健康检查设置域名时检查域名是否存在

This commit is contained in:
刘祥超
2022-09-17 11:38:04 +08:00
parent b0b82b29c1
commit 13f00104dd
4 changed files with 79 additions and 5 deletions

View File

@@ -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()
}

View File

@@ -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)).

View File

@@ -1,5 +1,5 @@
Vue.component("health-check-config-box", {
props: ["v-health-check-config"],
props: ["v-health-check-config", "v-check-domain-url"],
data: function () {
let healthCheckConfig = this.vHealthCheckConfig
let urlProtocol = "http"
@@ -76,7 +76,9 @@ Vue.component("health-check-config-box", {
urlHost: urlHost,
urlPort: urlPort,
urlRequestURI: urlRequestURI,
urlIsEditing: healthCheckConfig.url.length == 0
urlIsEditing: healthCheckConfig.url.length == 0,
hostErr: ""
}
},
watch: {
@@ -100,6 +102,7 @@ Vue.component("health-check-config-box", {
},
urlHost: function () {
this.changeURL()
this.hostErr = ""
},
"healthCheck.countTries": function (v) {
let count = parseInt(v)
@@ -147,6 +150,24 @@ Vue.component("health-check-config-box", {
}
})
},
onChangeURLHost: function () {
let checkDomainURL = this.vCheckDomainUrl
if (checkDomainURL == null || checkDomainURL.length == 0) {
return
}
let that = this
Tea.action(checkDomainURL)
.params({host: this.urlHost})
.success(function (resp) {
if (!resp.data.isOk) {
that.hostErr = "在当前集群中找不到此域名,可能会影响健康检查结果。"
} else {
that.hostErr = ""
}
})
.post()
},
editURL: function () {
this.urlIsEditing = !this.urlIsEditing
}
@@ -185,8 +206,8 @@ Vue.component("health-check-config-box", {
<tr>
<td>域名</td>
<td>
<input type="text" v-model="urlHost"/>
<p class="comment">已经部署到当前集群的一个域名如果为空则使用节点IP作为域名。<span class="red" v-if="urlProtocol == 'https' && urlHost.length == 0">如果协议是https这里必须填写一个已经设置了SSL证书的域名。</span></p>
<input type="text" v-model="urlHost" @change="onChangeURLHost"/>
<p class="comment"><span v-if="hostErr.length > 0" class="red">{{hostErr}}</span>已经部署到当前集群的一个域名如果为空则使用节点IP作为域名。<span class="red" v-if="urlProtocol == 'https' && urlHost.length == 0">如果协议是https这里必须填写一个已经设置了SSL证书的域名。</span></p>
</td>
</tr>
<tr>

View File

@@ -5,7 +5,7 @@
<div class="right-box with-menu">
<form method="post" class="ui form" data-tea-action="$" data-tea-success="success">
<input type="hidden" name="clusterId" :value="clusterId"/>
<health-check-config-box :v-health-check-config="healthCheckConfig"></health-check-config-box>
<health-check-config-box :v-health-check-config="healthCheckConfig" :v-check-domain-url="'/clusters/cluster/settings/health/checkDomain?clusterId=' + clusterId"></health-check-config-box>
<submit-btn></submit-btn> &nbsp; <a href="" @click.prevent="run()" v-if="healthCheckConfig != null && healthCheckConfig.isOn">立即检查</a>
</form>
</div>