From: Daniel Swarbrick Date: Tue, 21 Nov 2017 12:07:04 +0000 (+0100) Subject: Use net/http, time package constants (#266) X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=260e080658f6f9c2a8f1b9e6d81f585eda062221;p=blackbox_exporter.git Use net/http, time package constants (#266) --- diff --git a/main.go b/main.go index fc9f813..e0d586f 100644 --- a/main.go +++ b/main.go @@ -65,7 +65,7 @@ func probeHandler(w http.ResponseWriter, r *http.Request, c *config.Config, logg } module, ok := c.Modules[moduleName] if !ok { - http.Error(w, fmt.Sprintf("Unknown module %q", moduleName), 400) + http.Error(w, fmt.Sprintf("Unknown module %q", moduleName), http.StatusBadRequest) return } @@ -87,7 +87,7 @@ func probeHandler(w http.ResponseWriter, r *http.Request, c *config.Config, logg timeoutSeconds = module.Timeout.Seconds() } timeoutSeconds -= *timeoutOffset - ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeoutSeconds*1e9)) + ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeoutSeconds*float64(time.Second))) defer cancel() r = r.WithContext(ctx) @@ -102,13 +102,13 @@ func probeHandler(w http.ResponseWriter, r *http.Request, c *config.Config, logg params := r.URL.Query() target := params.Get("target") if target == "" { - http.Error(w, "Target parameter is missing", 400) + http.Error(w, "Target parameter is missing", http.StatusBadRequest) return } prober, ok := Probers[module.Prober] if !ok { - http.Error(w, fmt.Sprintf("Unknown prober %q", module.Prober), 400) + http.Error(w, fmt.Sprintf("Unknown prober %q", module.Prober), http.StatusBadRequest) return } diff --git a/prober/http.go b/prober/http.go index a4100b3..88bbb1a 100644 --- a/prober/http.go +++ b/prober/http.go @@ -384,7 +384,7 @@ func ProbeHTTP(ctx context.Context, target string, module config.Module, registr if resp.TLS != nil { isSSLGauge.Set(float64(1)) registry.MustRegister(probeSSLEarliestCertExpiryGauge) - probeSSLEarliestCertExpiryGauge.Set(float64(getEarliestCertExpiry(resp.TLS).UnixNano() / 1e9)) + probeSSLEarliestCertExpiryGauge.Set(float64(getEarliestCertExpiry(resp.TLS).Unix())) if httpConfig.FailIfSSL { level.Error(logger).Log("msg", "Final request was over SSL") success = false diff --git a/prober/tcp.go b/prober/tcp.go index 65174b6..7368d41 100644 --- a/prober/tcp.go +++ b/prober/tcp.go @@ -108,7 +108,7 @@ func ProbeTCP(ctx context.Context, target string, module config.Module, registry if module.TCP.TLS { state := conn.(*tls.Conn).ConnectionState() registry.MustRegister(probeSSLEarliestCertExpiry) - probeSSLEarliestCertExpiry.Set(float64(getEarliestCertExpiry(&state).UnixNano()) / 1e9) + probeSSLEarliestCertExpiry.Set(float64(getEarliestCertExpiry(&state).Unix())) } scanner := bufio.NewScanner(conn) for i, qr := range module.TCP.QueryResponse { @@ -176,7 +176,7 @@ func ProbeTCP(ctx context.Context, target string, module config.Module, registry // Get certificate expiry. state := tlsConn.ConnectionState() registry.MustRegister(probeSSLEarliestCertExpiry) - probeSSLEarliestCertExpiry.Set(float64(getEarliestCertExpiry(&state).UnixNano()) / 1e9) + probeSSLEarliestCertExpiry.Set(float64(getEarliestCertExpiry(&state).Unix())) } } return true