From 0dc7a0c7d44fd03c32cb0aca4a2cd7fdd71e6b96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=AD=90=E9=BE=99?= Date: Fri, 14 Jul 2023 15:55:58 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BB=E6=9C=BA=E7=8A=B6=E6=80=81=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=20fix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/service/host_manage.go | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/src/service/host_manage.go b/src/service/host_manage.go index b51afc2..cc8c1df 100644 --- a/src/service/host_manage.go +++ b/src/service/host_manage.go @@ -465,7 +465,7 @@ func (h *HostManageSvc) ListStateHostManage(req request.StateHostManageReq) (err for i := 0; i < len(hostManageList); i++ { go func(i int) { //检测ip连通性 - connStatus := StatusDetection(hostManageList[i].Ip) + connStatus := StatusDetection(cast.ToString(hostManageList[i].Id)) if connStatus == 1 { lock.Lock() fail = append(fail, hostManageList[i].Id) @@ -679,25 +679,13 @@ func (h *HostManageSvc) SaveIpExceptionList(req request.HostIpExceptionListReq) func StatusDetection(ip string) (ipConn int) { var cmd *exec.Cmd cmd = exec.Command("ansible", fmt.Sprintf("%s", AnsibleIp+ip), "-m", "ping") - err := cmd.Run() + output, err := cmd.Output() if err != nil { conf.Logger.Error("测试 "+ip+" 连通性失败", zap.Error(err)) return 1 } - if cmd.ProcessState.Success() { - return 0 - } else { - return 1 - } - - //output, err := cmd.Output() - //if err != nil { - // fmt.Println("ping:", string(output)) - // fmt.Println("err:", err) - // return 1 - //} - //fmt.Println("ping:", string(output)) - //return 0 + conf.Logger.Debug("测试 "+ip+" 连通性成功", zap.String("output", string(output))) + return 0 } // ExportIpStr 结果导出 -- 2.26.0