Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new probe_ssl_latest_verified_chain_expiry metric #636

Merged
Merged
8 changes: 7 additions & 1 deletion prober/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,11 @@ func ProbeHTTP(ctx context.Context, target string, module config.Module, registr
Help: "Returns earliest SSL cert expiry in unixtime",
})

probeSSLLatestVerifiedChainExpiryGauge = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "probe_ssl_latest_verified_chain_expiry",
Help: "Returns latest SSL verified chain expiry in unixtime",
})

probeTLSVersion = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "probe_tls_version_info",
Expand Down Expand Up @@ -546,8 +551,9 @@ func ProbeHTTP(ctx context.Context, target string, module config.Module, registr

if resp.TLS != nil {
isSSLGauge.Set(float64(1))
registry.MustRegister(probeSSLEarliestCertExpiryGauge, probeTLSVersion)
registry.MustRegister(probeSSLEarliestCertExpiryGauge, probeSSLLatestVerifiedChainExpiryGauge, probeTLSVersion)
probeSSLEarliestCertExpiryGauge.Set(float64(getEarliestCertExpiry(resp.TLS).Unix()))
probeSSLLatestVerifiedChainExpiryGauge.Set(float64(getLatestVerifiedChainExpiry(resp.TLS).Unix()))
probeTLSVersion.WithLabelValues(getTLSVersion(resp.TLS)).Set(1)
if httpConfig.FailIfSSL {
level.Error(logger).Log("msg", "Final request was over SSL")
Expand Down
7 changes: 6 additions & 1 deletion prober/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ func ProbeTCP(ctx context.Context, target string, module config.Module, registry
Name: "probe_ssl_earliest_cert_expiry",
Help: "Returns earliest SSL cert expiry date",
})
probeSSLLatestVerifiedChainExpiry := prometheus.NewGauge(prometheus.GaugeOpts{
Name: "probe_ssl_latest_verified_chain_expiry",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a little of a mouthful, and naming conventions have matured since the previous one was named.

I'd go for something like probe_ssl_last_chain_expiry_timestamp_seconds.

Help: "Returns latest SSL verified chain expiry date",
})
probeTLSVersion := prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "probe_tls_version_info",
Expand Down Expand Up @@ -125,8 +129,9 @@ func ProbeTCP(ctx context.Context, target string, module config.Module, registry
}
if module.TCP.TLS {
state := conn.(*tls.Conn).ConnectionState()
registry.MustRegister(probeSSLEarliestCertExpiry, probeTLSVersion)
registry.MustRegister(probeSSLEarliestCertExpiry, probeSSLLatestVerifiedChainExpiry, probeTLSVersion)
probeSSLEarliestCertExpiry.Set(float64(getEarliestCertExpiry(&state).Unix()))
probeSSLLatestVerifiedChainExpiry.Set(float64(getLatestVerifiedChainExpiry(&state).Unix()))
probeTLSVersion.WithLabelValues(getTLSVersion(&state)).Set(1)
}
scanner := bufio.NewScanner(conn)
Expand Down
17 changes: 17 additions & 0 deletions prober/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,23 @@ func getEarliestCertExpiry(state *tls.ConnectionState) time.Time {
return earliest
}

func getLatestVerifiedChainExpiry(state *tls.ConnectionState) time.Time {
latestVerifiedChainExpiry := time.Time{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this output if there's no chains? You'll probably need insecure_skip_verify to test this.

for _, chain := range state.VerifiedChains {
earliestCertExpiry := time.Time{}
for _, cert := range chain {
if (earliestCertExpiry.IsZero() || cert.NotAfter.Before(earliestCertExpiry)) && !cert.NotAfter.IsZero() {
earliestCertExpiry = cert.NotAfter
}
}
if latestVerifiedChainExpiry.IsZero() || latestVerifiedChainExpiry.After(earliestCertExpiry) {
latestVerifiedChainExpiry = earliestCertExpiry
}

}
return latestVerifiedChainExpiry
}

func getTLSVersion(state *tls.ConnectionState) string {
switch state.Version {
case tls.VersionTLS10:
Expand Down