From 92e8080d7e2546e631f52df533ced7e579f2a29f Mon Sep 17 00:00:00 2001 From: naiba Date: Thu, 21 Jan 2021 09:37:29 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20agent=20v0.3.2:=20fix=20http=20s?= =?UTF-8?q?ervice=20check?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/agent/main.go | 15 +++++++++++---- cmd/playground/main.go | 17 +++++++++-------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/cmd/agent/main.go b/cmd/agent/main.go index b2fab17..dd3a975 100644 --- a/cmd/agent/main.go +++ b/cmd/agent/main.go @@ -52,9 +52,14 @@ var ( ctx = context.Background() delayWhenError = time.Second * 10 updateCh = make(chan struct{}, 0) - httpClient = &http.Client{Transport: &http.Transport{ - TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, - }} + httpClient = &http.Client{ + Transport: &http.Transport{ + TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, + }, + CheckRedirect: func(req *http.Request, via []*http.Request) error { + return http.ErrUseLastResponse + }, + } ) func doSelfUpdate() { @@ -179,7 +184,7 @@ func doTask(task *pb.Task) { resp, err := httpClient.Get(task.GetData()) if err == nil { result.Delay = float32(time.Now().Sub(start).Microseconds()) / 1000.0 - if resp.StatusCode > 299 || resp.StatusCode < 200 { + if resp.StatusCode > 399 || resp.StatusCode < 200 { err = errors.New("\n应用错误:" + resp.Status) } } @@ -192,6 +197,8 @@ func doTask(task *pb.Task) { result.Data = c.Issuer + "|" + c.NotAfter result.Successful = true } + } else { + result.Successful = true } } else { result.Data = err.Error() diff --git a/cmd/playground/main.go b/cmd/playground/main.go index 59ffa27..ceac57a 100644 --- a/cmd/playground/main.go +++ b/cmd/playground/main.go @@ -9,15 +9,14 @@ import ( "os/exec" "time" - "github.com/genkiroid/cert" "github.com/go-ping/ping" "github.com/shirou/gopsutil/v3/disk" ) func main() { - icmp() + // icmp() // tcpping() - // httpWithSSLInfo() + httpWithSSLInfo() // diskinfo() } @@ -48,12 +47,14 @@ func httpWithSSLInfo() { transCfg := &http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, } - httpClient := &http.Client{Transport: transCfg} - _, err := httpClient.Get("https://expired-ecc-dv.ssl.com") - fmt.Println(err) + httpClient := &http.Client{Transport: transCfg, CheckRedirect: func(req *http.Request, via []*http.Request) error { + return http.ErrUseLastResponse + }} + resp, err := httpClient.Get("http://mail.nai.ba") + fmt.Println(err, resp.StatusCode) // SSL 证书信息获取 - c := cert.NewCert("expired-ecc-dv.ssl.com") - fmt.Println(c.Error) + // c := cert.NewCert("expired-ecc-dv.ssl.com") + // fmt.Println(c.Error) } func icmp() {