Skip to content

Commit

Permalink
Merge pull request #1 from greg-solutions/feature/extend_cert_expire_…
Browse files Browse the repository at this point in the history
…data

Extend information about last cert of chain
  • Loading branch information
vadymlab authored Apr 23, 2020
2 parents 589f4d5 + 3619688 commit b869cef
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions prober/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ func ProbeHTTP(ctx context.Context, target string, module config.Module, registr
Name: "probe_ssl_earliest_cert_expiry",
Help: "Returns earliest SSL cert expiry in unixtime",
})
probeSSLLastCertExpiry = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "probe_ssl_last_cert_expiry",
Help: "Returns last SSL cert expiry date",
})

probeHTTPVersionGauge = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "probe_http_version",
Expand Down Expand Up @@ -490,7 +494,9 @@ func ProbeHTTP(ctx context.Context, target string, module config.Module, registr
if resp.TLS != nil {
isSSLGauge.Set(float64(1))
registry.MustRegister(probeSSLEarliestCertExpiryGauge)
registry.MustRegister(probeSSLLastCertExpiry)
probeSSLEarliestCertExpiryGauge.Set(float64(getEarliestCertExpiry(resp.TLS).Unix()))
probeSSLLastCertExpiry.Set(float64(getLastCertExpiry(resp.TLS).Unix()))
if httpConfig.FailIfSSL {
level.Error(logger).Log("msg", "Final request was over SSL")
success = false
Expand Down
8 changes: 8 additions & 0 deletions 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",
})
probeSSLLastCertExpiry := prometheus.NewGauge(prometheus.GaugeOpts{
Name: "probe_ssl_last_cert_expiry",
Help: "Returns last SSL cert expiry date",
})
probeFailedDueToRegex := prometheus.NewGauge(prometheus.GaugeOpts{
Name: "probe_failed_due_to_regex",
Help: "Indicates if probe failed due to regex",
Expand All @@ -119,7 +123,9 @@ func ProbeTCP(ctx context.Context, target string, module config.Module, registry
if module.TCP.TLS {
state := conn.(*tls.Conn).ConnectionState()
registry.MustRegister(probeSSLEarliestCertExpiry)
registry.MustRegister(probeSSLLastCertExpiry)
probeSSLEarliestCertExpiry.Set(float64(getEarliestCertExpiry(&state).Unix()))
probeSSLLastCertExpiry.Set(float64(getLastCertExpiry(&state).Unix()))
}
scanner := bufio.NewScanner(conn)
for i, qr := range module.TCP.QueryResponse {
Expand Down Expand Up @@ -187,7 +193,9 @@ func ProbeTCP(ctx context.Context, target string, module config.Module, registry
// Get certificate expiry.
state := tlsConn.ConnectionState()
registry.MustRegister(probeSSLEarliestCertExpiry)
registry.MustRegister(probeSSLLastCertExpiry)
probeSSLEarliestCertExpiry.Set(float64(getEarliestCertExpiry(&state).Unix()))
probeSSLLastCertExpiry.Set(float64(getLastCertExpiry(&state).Unix()))
}
}
return true
Expand Down
2 changes: 2 additions & 0 deletions prober/tcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ func TestTCPConnectionWithTLS(t *testing.T) {
}
expectedResults := map[string]float64{
"probe_ssl_earliest_cert_expiry": float64(certExpiry.Unix()),
"probe_ssl_last_cert_expiry": float64(certExpiry.Unix()),
}
checkRegistryResults(expectedResults, mfs, t)
}
Expand Down Expand Up @@ -288,6 +289,7 @@ func TestTCPConnectionQueryResponseStartTLS(t *testing.T) {
}
expectedResults := map[string]float64{
"probe_ssl_earliest_cert_expiry": float64(certExpiry.Unix()),
"probe_ssl_last_cert_expiry": float64(certExpiry.Unix()),
}
checkRegistryResults(expectedResults, mfs, t)
}
Expand Down
3 changes: 3 additions & 0 deletions prober/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ func getEarliestCertExpiry(state *tls.ConnectionState) time.Time {
}
return earliest
}
func getLastCertExpiry(state *tls.ConnectionState) time.Time {
return state.PeerCertificates[0].NotAfter
}

0 comments on commit b869cef

Please sign in to comment.