diff --git a/src/service/host_manage.go b/src/service/host_manage.go index b51afc221f33b27532a7567c83318314ab6378d1..cc8c1dfd27a32547fb19ea746508d556fc31fcd5 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 结果导出