From c38999070610727475017eabe29f2941729313db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=BE=E5=B9=BF=E5=AE=87?= <2374227950@qq.com> Date: Mon, 8 May 2023 10:05:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3Id=E4=B8=BAID=20=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3in18=E9=94=99=E8=AF=AF=20=E4=BF=AE=E6=AD=A3RunScript?= =?UTF-8?q?=E5=AE=BF=E4=B8=BB=E6=9C=BA=E6=9C=AA=E4=BD=BF=E7=94=A8=E9=94=99?= =?UTF-8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/server/api/monitor.go | 8 ++++---- cmd/server/task/monitor.go | 4 ++-- internal/monitor/monitor.go | 4 ++++ model/monitor.go | 24 ++++++++++++------------ web/components.d.ts | 2 -- web/src/lang/en.json | 1 + web/src/lang/zh-cn.json | 1 + web/src/views/monitor/index.vue | 4 ++-- 8 files changed, 26 insertions(+), 22 deletions(-) diff --git a/cmd/server/api/monitor.go b/cmd/server/api/monitor.go index 81c5aed..530f9d5 100644 --- a/cmd/server/api/monitor.go +++ b/cmd/server/api/monitor.go @@ -136,8 +136,8 @@ func (Monitor) Add(gp *server.Goploy) server.Response { Description: reqData.Description, FailScript: reqData.FailScript, SuccessScript: reqData.SuccessScript, - SuccessServerId: reqData.SuccessServerId, - FailServerId: reqData.FailServerId, + SuccessServerID: reqData.SuccessServerId, + FailServerID: reqData.FailServerId, }.AddRow() if err != nil { @@ -184,8 +184,8 @@ func (Monitor) Edit(gp *server.Goploy) server.Response { Description: reqData.Description, FailScript: reqData.FailScript, SuccessScript: reqData.SuccessScript, - SuccessServerId: reqData.SuccessServerId, - FailServerId: reqData.FailServerId, + SuccessServerID: reqData.SuccessServerId, + FailServerID: reqData.FailServerId, }.EditRow() if err != nil { diff --git a/cmd/server/task/monitor.go b/cmd/server/task/monitor.go index 05bc8a4..b5eefce 100644 --- a/cmd/server/task/monitor.go +++ b/cmd/server/task/monitor.go @@ -81,8 +81,8 @@ func monitorTask() { if int(now-monitorCache.time) >= m.Second { monitorCache.time = now ms, err := monitor.NewMonitorFromTarget(m.Type, m.Target, - monitor.NewScript(m.SuccessServerId, m.SuccessScript), - monitor.NewScript(m.FailServerId, m.FailScript), + monitor.NewScript(m.SuccessServerID, m.SuccessScript), + monitor.NewScript(m.FailServerID, m.FailScript), ) if err != nil { _ = m.TurnOff(err.Error()) diff --git a/internal/monitor/monitor.go b/internal/monitor/monitor.go index 12e0760..7eb6772 100644 --- a/internal/monitor/monitor.go +++ b/internal/monitor/monitor.go @@ -163,6 +163,8 @@ func (m Monitor) RunFailScript(serverId int64) error { if sId == -1 { if serverId == 0 { return errors.New("the executor is not clear") + } else { + sId = serverId } } session, err := NewSession(sId, m.Timeout*time.Second) @@ -179,6 +181,8 @@ func (m Monitor) RunSuccessScript(serverId int64) error { if sId == -1 { if serverId == 0 { return errors.New("the executor is not clear") + } else { + sId = serverId } } session, err := NewSession(sId, m.Timeout*time.Second) diff --git a/model/monitor.go b/model/monitor.go index 7b6b3aa..d15078a 100644 --- a/model/monitor.go +++ b/model/monitor.go @@ -26,9 +26,9 @@ type Monitor struct { SilentCycle int `json:"silentCycle"` NotifyType uint8 `json:"notifyType"` NotifyTarget string `json:"notifyTarget"` - SuccessServerId int64 `json:"successServerId"` + SuccessServerID int64 `json:"successServerId"` SuccessScript string `json:"successScript"` - FailServerId int64 `json:"failServerId"` + FailServerID int64 `json:"failServerId"` FailScript string `json:"failScript"` Description string `json:"description"` ErrorContent string `json:"errorContent"` @@ -41,7 +41,7 @@ type Monitors []Monitor func (m Monitor) GetList() (Monitors, error) { rows, err := sq. - Select("id, name, type, target, second, times, silent_cycle, notify_type, notify_target, description, error_content, state,success_script ,fail_script ,success_server_id ,fail_server_id, insert_time, update_time"). + Select("id, name, type, target, second, times, silent_cycle, notify_type, notify_target, description, error_content, state, success_script, fail_script, success_server_id, fail_server_id, insert_time, update_time"). From(monitorTable). Where(sq.Eq{ "namespace_id": m.NamespaceID, @@ -71,8 +71,8 @@ func (m Monitor) GetList() (Monitors, error) { &monitor.State, &monitor.SuccessScript, &monitor.FailScript, - &monitor.SuccessServerId, - &monitor.FailServerId, + &monitor.SuccessServerID, + &monitor.FailServerID, &monitor.InsertTime, &monitor.UpdateTime); err != nil { return nil, err @@ -92,7 +92,7 @@ func (m Monitor) GetData() (Monitor, error) { OrderBy("id DESC"). RunWith(DB). QueryRow(). - Scan(&monitor.ID, &monitor.Name, &monitor.Type, &monitor.Target, &monitor.Second, &monitor.Times, &monitor.SilentCycle, &monitor.NotifyType, &monitor.NotifyTarget, &monitor.State, &monitor.SuccessScript, &monitor.FailScript, &monitor.SuccessServerId, &monitor.FailServerId) + Scan(&monitor.ID, &monitor.Name, &monitor.Type, &monitor.Target, &monitor.Second, &monitor.Times, &monitor.SilentCycle, &monitor.NotifyType, &monitor.NotifyTarget, &monitor.State, &monitor.SuccessScript, &monitor.FailScript, &monitor.SuccessServerID, &monitor.FailServerID) if err != nil { return monitor, err } @@ -101,7 +101,7 @@ func (m Monitor) GetData() (Monitor, error) { func (m Monitor) GetAllByState() (Monitors, error) { rows, err := sq. - Select("id, name, type, target, second, times, silent_cycle, notify_type, notify_target,success_script ,fail_script ,success_server_id,fail_server_id , description, update_time"). + Select("id, name, type, target, second, times, silent_cycle, notify_type, notify_target, success_script, fail_script, success_server_id, fail_server_id, description, update_time"). From(monitorTable). Where(sq.Eq{ "state": m.State, @@ -127,8 +127,8 @@ func (m Monitor) GetAllByState() (Monitors, error) { &monitor.NotifyTarget, &monitor.SuccessScript, &monitor.FailScript, - &monitor.SuccessServerId, - &monitor.FailServerId, + &monitor.SuccessServerID, + &monitor.FailServerID, &monitor.Description, &monitor.UpdateTime, ); err != nil { @@ -144,7 +144,7 @@ func (m Monitor) AddRow() (int64, error) { result, err := sq. Insert(monitorTable). Columns("namespace_id", "name", "type", "target", "second", "times", "silent_cycle", "notify_type", "notify_target", "description", "error_content", "success_script", "fail_script", "success_server_id", "fail_server_id"). - Values(m.NamespaceID, m.Name, m.Type, m.Target, m.Second, m.Times, m.SilentCycle, m.NotifyType, m.NotifyTarget, m.Description, "", m.SuccessScript, m.FailScript, m.SuccessServerId, m.FailServerId). + Values(m.NamespaceID, m.Name, m.Type, m.Target, m.Second, m.Times, m.SilentCycle, m.NotifyType, m.NotifyTarget, m.Description, "", m.SuccessScript, m.FailScript, m.SuccessServerID, m.FailServerID). RunWith(DB). Exec() if err != nil { @@ -169,8 +169,8 @@ func (m Monitor) EditRow() error { "description": m.Description, "success_script": m.SuccessScript, "fail_script": m.FailScript, - "success_server_id": m.SuccessServerId, - "fail_server_id": m.FailServerId, + "success_server_id": m.SuccessServerID, + "fail_server_id": m.FailServerID, }). Where(sq.Eq{"id": m.ID}). RunWith(DB). diff --git a/web/components.d.ts b/web/components.d.ts index 97de3a6..80a17ab 100644 --- a/web/components.d.ts +++ b/web/components.d.ts @@ -25,7 +25,6 @@ declare module '@vue/runtime-core' { ElDropdown: typeof import('element-plus/es')['ElDropdown'] ElDropdownItem: typeof import('element-plus/es')['ElDropdownItem'] ElDropdownMenu: typeof import('element-plus/es')['ElDropdownMenu'] - ElEmpty: typeof import('element-plus/es')['ElEmpty'] ElForm: typeof import('element-plus/es')['ElForm'] ElFormItem: typeof import('element-plus/es')['ElFormItem'] ElIcon: typeof import('element-plus/es')['ElIcon'] @@ -50,7 +49,6 @@ declare module '@vue/runtime-core' { ElTabPane: typeof import('element-plus/es')['ElTabPane'] ElTabs: typeof import('element-plus/es')['ElTabs'] ElTag: typeof import('element-plus/es')['ElTag'] - ElTimeSelect: typeof import('element-plus/es')['ElTimeSelect'] ElTooltip: typeof import('element-plus/es')['ElTooltip'] ElUpload: typeof import('element-plus/es')['ElUpload'] Hamburger: typeof import('./src/components/Hamburger/index.vue')['default'] diff --git a/web/src/lang/en.json b/web/src/lang/en.json index 321d955..159bd28 100644 --- a/web/src/lang/en.json +++ b/web/src/lang/en.json @@ -307,6 +307,7 @@ "saveTemplate": "Save template" }, "monitorPage": { + "defaultServer": "Follow Host", "scriptMode": "Script mode", "typeOption": [ "Unknown", diff --git a/web/src/lang/zh-cn.json b/web/src/lang/zh-cn.json index 87e7c4b..c61abc1 100644 --- a/web/src/lang/zh-cn.json +++ b/web/src/lang/zh-cn.json @@ -291,6 +291,7 @@ }, "monitorPage": { "scriptMode": "脚本类型", + "defaultServer": "跟随宿主机", "typeOption": ["未知", "站点检测", "端口检测", "Ping检测", "进程检测", "自定义脚本检测"], "testState": "测试状态", "failTimes": "连续失败次数", diff --git a/web/src/views/monitor/index.vue b/web/src/views/monitor/index.vue index 4d2b9c2..c2af62e 100644 --- a/web/src/views/monitor/index.vue +++ b/web/src/views/monitor/index.vue @@ -233,7 +233,7 @@ @@ -263,7 +263,7 @@