mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-10 01:10:29 +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", new(health.IndexAction)).
|
||||||
GetPost("/health/runPopup", new(health.RunPopupAction)).
|
GetPost("/health/runPopup", new(health.RunPopupAction)).
|
||||||
|
Post("/health/checkDomain", new(health.CheckDomainAction)).
|
||||||
|
|
||||||
// 缓存
|
// 缓存
|
||||||
GetPost("/cache", new(cache.IndexAction)).
|
GetPost("/cache", new(cache.IndexAction)).
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
Vue.component("health-check-config-box", {
|
Vue.component("health-check-config-box", {
|
||||||
props: ["v-health-check-config"],
|
props: ["v-health-check-config", "v-check-domain-url"],
|
||||||
data: function () {
|
data: function () {
|
||||||
let healthCheckConfig = this.vHealthCheckConfig
|
let healthCheckConfig = this.vHealthCheckConfig
|
||||||
let urlProtocol = "http"
|
let urlProtocol = "http"
|
||||||
@@ -76,7 +76,9 @@ Vue.component("health-check-config-box", {
|
|||||||
urlHost: urlHost,
|
urlHost: urlHost,
|
||||||
urlPort: urlPort,
|
urlPort: urlPort,
|
||||||
urlRequestURI: urlRequestURI,
|
urlRequestURI: urlRequestURI,
|
||||||
urlIsEditing: healthCheckConfig.url.length == 0
|
urlIsEditing: healthCheckConfig.url.length == 0,
|
||||||
|
|
||||||
|
hostErr: ""
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
@@ -100,6 +102,7 @@ Vue.component("health-check-config-box", {
|
|||||||
},
|
},
|
||||||
urlHost: function () {
|
urlHost: function () {
|
||||||
this.changeURL()
|
this.changeURL()
|
||||||
|
this.hostErr = ""
|
||||||
},
|
},
|
||||||
"healthCheck.countTries": function (v) {
|
"healthCheck.countTries": function (v) {
|
||||||
let count = parseInt(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 () {
|
editURL: function () {
|
||||||
this.urlIsEditing = !this.urlIsEditing
|
this.urlIsEditing = !this.urlIsEditing
|
||||||
}
|
}
|
||||||
@@ -185,8 +206,8 @@ Vue.component("health-check-config-box", {
|
|||||||
<tr>
|
<tr>
|
||||||
<td>域名</td>
|
<td>域名</td>
|
||||||
<td>
|
<td>
|
||||||
<input type="text" v-model="urlHost"/>
|
<input type="text" v-model="urlHost" @change="onChangeURLHost"/>
|
||||||
<p class="comment">已经部署到当前集群的一个域名;如果为空则使用节点IP作为域名。<span class="red" v-if="urlProtocol == 'https' && urlHost.length == 0">如果协议是https,这里必须填写一个已经设置了SSL证书的域名。</span></p>
|
<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>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<div class="right-box with-menu">
|
<div class="right-box with-menu">
|
||||||
<form method="post" class="ui form" data-tea-action="$" data-tea-success="success">
|
<form method="post" class="ui form" data-tea-action="$" data-tea-success="success">
|
||||||
<input type="hidden" name="clusterId" :value="clusterId"/>
|
<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> <a href="" @click.prevent="run()" v-if="healthCheckConfig != null && healthCheckConfig.isOn">立即检查</a>
|
<submit-btn></submit-btn> <a href="" @click.prevent="run()" v-if="healthCheckConfig != null && healthCheckConfig.isOn">立即检查</a>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
Reference in New Issue
Block a user