Add left certificate's "subject", "issuer", "subjectalternative" labels in `probe_tls_certificate_info` metric.
See relevent discussion in #892
Co-authored-by: Daniel Jolly <code@danieljolly.com>
},
[]string{"version"},
)
+
+ probeSSLLastInformation = prometheus.NewGaugeVec(
+ prometheus.GaugeOpts{
+ Name: "probe_ssl_last_chain_info",
+ Help: "Contains SSL leaf certificate information",
+ },
+ []string{"fingerprint_sha256", "subject", "issuer", "subjectalternative"},
+ )
)
for _, lv := range []string{"resolve"} {
registry.MustRegister(healthCheckResponseGaugeVec)
registry.MustRegister(probeSSLEarliestCertExpiryGauge)
registry.MustRegister(probeTLSVersion)
+ registry.MustRegister(probeSSLLastInformation)
if !strings.HasPrefix(target, "http://") && !strings.HasPrefix(target, "https://") {
target = "http://" + target
isSSLGauge.Set(float64(1))
probeSSLEarliestCertExpiryGauge.Set(float64(getEarliestCertExpiry(&tlsInfo.State).Unix()))
probeTLSVersion.WithLabelValues(getTLSVersion(&tlsInfo.State)).Set(1)
+ probeSSLLastInformation.WithLabelValues(getFingerprint(&tlsInfo.State), getSubject(&tlsInfo.State), getIssuer(&tlsInfo.State), getDNSNames(&tlsInfo.State)).Set(1)
} else {
isSSLGauge.Set(float64(0))
}
Name: "probe_ssl_last_chain_info",
Help: "Contains SSL leaf certificate information",
},
- []string{"fingerprint_sha256"},
+ []string{"fingerprint_sha256", "subject", "issuer", "subjectalternative"},
)
probeTLSVersion = prometheus.NewGaugeVec(
probeSSLEarliestCertExpiryGauge.Set(float64(getEarliestCertExpiry(resp.TLS).Unix()))
probeTLSVersion.WithLabelValues(getTLSVersion(resp.TLS)).Set(1)
probeSSLLastChainExpiryTimestampSeconds.Set(float64(getLastChainExpiry(resp.TLS).Unix()))
- probeSSLLastInformation.WithLabelValues(getFingerprint(resp.TLS)).Set(1)
+ probeSSLLastInformation.WithLabelValues(getFingerprint(resp.TLS), getSubject(resp.TLS), getIssuer(resp.TLS), getDNSNames(resp.TLS)).Set(1)
if httpConfig.FailIfSSL {
level.Error(logger).Log("msg", "Final request was over SSL")
success = false
Name: "probe_ssl_last_chain_info",
Help: "Contains SSL leaf certificate information",
},
- []string{"fingerprint_sha256"},
+ []string{"fingerprint_sha256", "subject", "issuer", "subjectalternative"},
)
probeTLSVersion := prometheus.NewGaugeVec(
prometheus.GaugeOpts{
probeSSLEarliestCertExpiry.Set(float64(getEarliestCertExpiry(&state).Unix()))
probeTLSVersion.WithLabelValues(getTLSVersion(&state)).Set(1)
probeSSLLastChainExpiryTimestampSeconds.Set(float64(getLastChainExpiry(&state).Unix()))
- probeSSLLastInformation.WithLabelValues(getFingerprint(&state)).Set(1)
+ probeSSLLastInformation.WithLabelValues(getFingerprint(&state), getSubject(&state), getIssuer(&state), getDNSNames(&state)).Set(1)
}
scanner := bufio.NewScanner(conn)
for i, qr := range module.TCP.QueryResponse {
probeSSLEarliestCertExpiry.Set(float64(getEarliestCertExpiry(&state).Unix()))
probeTLSVersion.WithLabelValues(getTLSVersion(&state)).Set(1)
probeSSLLastChainExpiryTimestampSeconds.Set(float64(getLastChainExpiry(&state).Unix()))
- probeSSLLastInformation.WithLabelValues(getFingerprint(&state)).Set(1)
+ probeSSLLastInformation.WithLabelValues(getFingerprint(&state), getSubject(&state), getIssuer(&state), getDNSNames(&state)).Set(1)
}
}
return true
"crypto/sha256"
"crypto/tls"
"encoding/hex"
+ "strings"
"time"
)
return hex.EncodeToString(fingerprint[:])
}
+func getSubject(state *tls.ConnectionState) string {
+ cert := state.PeerCertificates[0]
+ return cert.Subject.String()
+}
+
+func getIssuer(state *tls.ConnectionState) string {
+ cert := state.PeerCertificates[0]
+ return cert.Issuer.String()
+}
+
+func getDNSNames(state *tls.ConnectionState) string {
+ cert := state.PeerCertificates[0]
+ return strings.Join(cert.DNSNames, ",")
+}
+
func getLastChainExpiry(state *tls.ConnectionState) time.Time {
lastChainExpiry := time.Time{}
for _, chain := range state.VerifiedChains {
SubjectKeyId: []byte{1},
SerialNumber: big.NewInt(1),
Subject: pkix.Name{
+ CommonName: "Example",
Organization: []string{"Example Org"},
},
NotBefore: time.Now(),