Sha256: 65eaaee7bb6f00a527673b532e62ef2b93dcf9e25f3836e612882b64e23ee9bb
Contents?: true
Size: 1.47 KB
Versions: 6
Compression:
Stored size: 1.47 KB
Contents
module WatchmonkeyCli module Checkers class SslExpiration < Checker self.checker_name = "ssl_expiration" def enqueue page, opts = {} opts = { threshold: 1.months, verify: true, timeout: 20 }.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 http.open_timeout = opts[:timeout] http.read_timeout = opts[:timeout] 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
6 entries across 6 versions & 1 rubygems