3 ms·
We use a daily Ruby script that puts data into InfluxDB and we use Grafana to warn us if a certificate is close to expire: tcp_client = TCPSocket.new(domai
by kawsper 7y ago
We use a daily Ruby script that puts data into InfluxDB and we use Grafana to warn us if a certificate is close to expire:
tcp_client = TCPSocket.new(domain, 443)
ssl_client = OpenSSL::SSL::SSLSocket.new(tcp_client)
ssl_client.hostname = domain
ssl_client.connect
cert = OpenSSL::X509::Certificate.new(ssl_client.peer_cert)
ssl_client.sysclose
tcp_client.close
certprops = OpenSSL::X509::Name.new(cert.issuer).to_a
issuer = certprops.select { |name, data, type| name == "O" }.first[1]
results = {
valid_on: cert.not_before.utc,
valid_until: cert.not_after.utc,
issuer: issuer,
days_left: (cert.not_after.utc - Time.now.utc).to_i / (24 * 60 * 60),
}