package main
import (
- "crypto/tls"
"errors"
"fmt"
"io"
"net/http"
"regexp"
"strings"
- "time"
"github.com/prometheus/log"
)
return true
}
-func getEarliestCertExpiry(state *tls.ConnectionState) time.Time {
- earliest := time.Time{}
- for _, cert := range state.PeerCertificates {
- if (earliest.IsZero() || cert.NotAfter.Before(earliest)) && !cert.NotAfter.IsZero() {
- earliest = cert.NotAfter
- }
- }
- return earliest
-}
-
func probeHTTP(target string, w http.ResponseWriter, module Module) (success bool) {
var isSSL, redirects int
config := module.HTTP
"gopkg.in/yaml.v2"
"github.com/prometheus/client_golang/prometheus"
+ "github.com/prometheus/common/config"
"github.com/prometheus/log"
)
}
type TCPProbe struct {
- QueryResponse []QueryResponse `yaml:"query_response"`
+ QueryResponse []QueryResponse `yaml:"query_response"`
+ TLS bool `yaml:"tls"`
+ TLSConfig config.TLSConfig `yaml:"tls_config"`
}
type ICMPProbe struct {
import (
"bufio"
+ "crypto/tls"
"fmt"
"net"
"net/http"
"github.com/prometheus/log"
)
+func dialTCP(target string, module Module) (net.Conn, error) {
+ dialer := &net.Dialer{Timeout: module.Timeout}
+ if !module.TCP.TLS {
+ return dialer.Dial("tcp", target)
+ }
+ config, err := module.TCP.TLSConfig.GenerateConfig()
+ if err != nil {
+ return nil, err
+ }
+ return tls.DialWithDialer(dialer, "tcp", target, config)
+}
+
func probeTCP(target string, w http.ResponseWriter, module Module) bool {
deadline := time.Now().Add(module.Timeout)
- conn, err := net.DialTimeout("tcp", target, module.Timeout)
+ conn, err := dialTCP(target, module)
if err != nil {
return false
}
defer conn.Close()
+
// Set a deadline to prevent the following code from blocking forever.
// If a deadline cannot be set, better fail the probe by returning an error
// now rather than blocking forever.
if err := conn.SetDeadline(deadline); err != nil {
return false
}
+ if module.TCP.TLS {
+ state := conn.(*tls.Conn).ConnectionState()
+ fmt.Fprintf(w, "probe_ssl_earliest_cert_expiry %f\n",
+ float64(getEarliestCertExpiry(&state).UnixNano())/1e9)
+ }
scanner := bufio.NewScanner(conn)
for _, qr := range module.TCP.QueryResponse {
log.Debugf("Processing query response entry %+v", qr)
--- /dev/null
+package main
+
+import (
+ "crypto/tls"
+ "time"
+)
+
+func getEarliestCertExpiry(state *tls.ConnectionState) time.Time {
+ earliest := time.Time{}
+ for _, cert := range state.PeerCertificates {
+ if (earliest.IsZero() || cert.NotAfter.Before(earliest)) && !cert.NotAfter.IsZero() {
+ earliest = cert.NotAfter
+ }
+ }
+ return earliest
+}