Sha256: 3641dbf7a13a9d0912d9e216c3e83c8699aeee5c8735c65f456c801687bbaf0d
Contents?: true
Size: 1.38 KB
Versions: 3
Compression:
Stored size: 1.38 KB
Contents
module WatchmonkeyCli module Checkers class SslExpiration < Checker self.checker_name = "ssl_expiration" def enqueue page, opts = {} opts = { threshold: 1.months, verify: true }.merge(opts) app.enqueue(self, page, opts) end def check! result, page, opts = {} uri = URI.parse(page) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true http.verify_mode = opts[:verify] ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE cert = nil http.start do |h| cert = h.peer_cert end if cert.not_before > Time.current result.error! "Certificate is not yet valid (will in #{human_seconds(cert.not_before - Time.current)}, #{cert.not_before})!" return end if cert.not_after <= Time.current result.error! "Certificate is EXPIRED (since #{human_seconds(cert.not_after - Time.current)}, #{cert.not_after})!" return end if cert.not_after <= Time.current + opts[:threshold] result.error! "Certificate is about to expire within threshold (in #{human_seconds(cert.not_after - Time.current)}, #{cert.not_after})!" return else result.info! "Certificate for `#{page}' expires in #{human_seconds(cert.not_after - Time.current)} (#{cert.not_after})!" end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems