add metric: cert_expire_timestamp
This commit is contained in:
parent
93c88c32cc
commit
a2626576df
|
@ -309,6 +309,11 @@ func (ins *Instance) httpGather(target string) (map[string]string, map[string]in
|
|||
fields["result_code"] = Success
|
||||
}
|
||||
|
||||
// check tls cert
|
||||
if strings.HasPrefix(target, "https://") && resp.TLS != nil {
|
||||
fields["cert_expire_timestamp"] = getEarliestCertExpiry(resp.TLS).Unix()
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
// metric: response_code
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package http_response
|
||||
|
||||
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
|
||||
}
|
Loading…
Reference in New Issue