Use warn level for log messages about target communication errors
authorTobias Schmidt <tobidt@gmail.com>
Sat, 4 Mar 2017 14:55:15 +0000 (10:55 -0400)
committerTobias Schmidt <tobidt@gmail.com>
Sat, 4 Mar 2017 15:20:37 +0000 (11:20 -0400)
dns.go
http.go
icmp.go
tcp.go

diff --git a/dns.go b/dns.go
index ff4b4c4c5ea005acd0abc6ea36767c5e0d6dce41..90c898228ebc66f73d577a68c81e83966e8c3054 100644 (file)
--- a/dns.go
+++ b/dns.go
@@ -124,9 +124,9 @@ func probeDNS(target string, w http.ResponseWriter, module Module) bool {
        }
 
        if dialProtocol[len(dialProtocol)-1] == '6' {
-               fmt.Fprintf(w, "probe_ip_protocol 6\n")
+               fmt.Fprintln(w, "probe_ip_protocol 6")
        } else {
-               fmt.Fprintf(w, "probe_ip_protocol 4\n")
+               fmt.Fprintln(w, "probe_ip_protocol 4")
        }
 
        client := new(dns.Client)
diff --git a/http.go b/http.go
index a101831c9e1d2c9c60df612d13bf87209db4b3bb..d57b45579e396a27c0a68fcc79c97422dd8440e0 100644 (file)
--- a/http.go
+++ b/http.go
@@ -105,9 +105,9 @@ func probeHTTP(target string, w http.ResponseWriter, module Module) (success boo
        }
 
        if dialProtocol == "tcp6" {
-               fmt.Fprintf(w, "probe_ip_protocol 6\n")
+               fmt.Fprintln(w, "probe_ip_protocol 6")
        } else {
-               fmt.Fprintf(w, "probe_ip_protocol 4\n")
+               fmt.Fprintln(w, "probe_ip_protocol 4")
        }
 
        client := &http.Client{
diff --git a/icmp.go b/icmp.go
index 3f4db6290a91ae3011bd2bc34faa0f8df84a391c..60ae926a0735c6c87b7c5cda00bd770794520532 100644 (file)
--- a/icmp.go
+++ b/icmp.go
@@ -81,7 +81,7 @@ func probeICMP(target string, w http.ResponseWriter, module Module) (success boo
        fmt.Fprintf(w, "probe_dns_lookup_time_seconds %f\n", time.Since(resolveStart).Seconds())
 
        if err != nil {
-               log.Errorf("Error resolving address %s: %s", target, err)
+               log.Warnf("Error resolving address %s: %s", target, err)
                return
        }
 
@@ -89,33 +89,26 @@ func probeICMP(target string, w http.ResponseWriter, module Module) (success boo
                requestType = ipv6.ICMPTypeEchoRequest
                replyType = ipv6.ICMPTypeEchoReply
                socket, err = icmp.ListenPacket("ip6:ipv6-icmp", "::")
-               fmt.Fprintf(w, "probe_ip_protocol 6\n")
+               fmt.Fprintln(w, "probe_ip_protocol 6")
        } else {
                requestType = ipv4.ICMPTypeEcho
                replyType = ipv4.ICMPTypeEchoReply
                socket, err = icmp.ListenPacket("ip4:icmp", "0.0.0.0")
-               fmt.Fprintf(w, "probe_ip_protocol 4\n")
+               fmt.Fprintln(w, "probe_ip_protocol 4")
        }
 
        if err != nil {
-               log.Errorf("Error listening to socket: %s", err)
+               log.Errorf("Error listening to socket for %s: %s", target, err)
                return
        }
        defer socket.Close()
 
-       if err != nil {
-               log.Errorf("Error resolving address %s: %s", target, err)
-               return
-       }
-
-       seq := getICMPSequence()
-       pid := os.Getpid() & 0xffff
-
        wm := icmp.Message{
                Type: requestType,
                Code: 0,
                Body: &icmp.Echo{
-                       ID: pid, Seq: int(seq),
+                       ID:   os.Getpid() & 0xffff,
+                       Seq:  int(getICMPSequence()),
                        Data: []byte("Prometheus Blackbox Exporter"),
                },
        }
@@ -126,7 +119,7 @@ func probeICMP(target string, w http.ResponseWriter, module Module) (success boo
                return
        }
        if _, err := socket.WriteTo(wb, ip); err != nil {
-               log.Errorf("Error writing to socket for %s: %s", target, err)
+               log.Warnf("Error writing to socket for %s: %s", target, err)
                return
        }
 
@@ -147,7 +140,7 @@ func probeICMP(target string, w http.ResponseWriter, module Module) (success boo
                n, peer, err := socket.ReadFrom(rb)
                if err != nil {
                        if nerr, ok := err.(net.Error); ok && nerr.Timeout() {
-                               log.Infof("Timeout reading from socket for %s: %s", target, err)
+                               log.Warnf("Timeout reading from socket for %s: %s", target, err)
                                return
                        }
                        log.Errorf("Error reading from socket for %s: %s", target, err)
@@ -162,8 +155,7 @@ func probeICMP(target string, w http.ResponseWriter, module Module) (success boo
                        rb[3] = 0
                }
                if bytes.Compare(rb[:n], wb) == 0 {
-                       success = true
-                       return
+                       return true
                }
        }
 }
diff --git a/tcp.go b/tcp.go
index ec9f099b9cdc4167c8403a4f876058626147805e..ae272543ae991559552f11610fb8e9b80660aa4b 100644 (file)
--- a/tcp.go
+++ b/tcp.go
@@ -60,9 +60,9 @@ func dialTCP(target string, w http.ResponseWriter, module Module) (net.Conn, err
        }
 
        if dialProtocol == "tcp6" {
-               fmt.Fprintf(w, "probe_ip_protocol 6\n")
+               fmt.Fprintln(w, "probe_ip_protocol 6")
        } else {
-               fmt.Fprintf(w, "probe_ip_protocol 4\n")
+               fmt.Fprintln(w, "probe_ip_protocol 4")
        }
 
        if !module.TCP.TLS {