Use net/http, time package constants (#266)
authorDaniel Swarbrick <daniel.swarbrick@gmail.com>
Tue, 21 Nov 2017 12:07:04 +0000 (13:07 +0100)
committerBrian Brazil <brian.brazil@robustperception.io>
Tue, 21 Nov 2017 12:07:04 +0000 (12:07 +0000)
main.go
prober/http.go
prober/tcp.go

diff --git a/main.go b/main.go
index fc9f813225563b032264dfb70ae4880963010819..e0d586f68022548359751d0d95a491de92f16e15 100644 (file)
--- 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
        }
 
index a4100b3571735e0753b3e720d12634f303bffd4e..88bbb1afcefc777b0311c9aedc397aee33313c10 100644 (file)
@@ -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
index 65174b6db9c8b4eddd49ecafc336bb1981306319..7368d41717d533c328baff1322fc1437e64e14f9 100644 (file)
@@ -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