Sha256: 90d1e8b5c682a4cb453fe9037d222767c3ddf98eb42eb6b4e0d34d421e66f918

Contents?: true

Size: 1.32 KB

Versions: 4

Compression:

Stored size: 1.32 KB

Contents

module WatchmonkeyCli
  module Checkers
    class SslExpiration < Checker
      self.checker_name = "ssl_expiration"

      def enqueue page, opts = {}
        opts = { threshold: 1.months }.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 = 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

4 entries across 4 versions & 1 rubygems

Version Path
watchmonkey_cli-1.8.1 lib/watchmonkey_cli/checkers/ssl_expiration.rb
watchmonkey_cli-1.8 lib/watchmonkey_cli/checkers/ssl_expiration.rb
watchmonkey_cli-1.7.1 lib/watchmonkey_cli/checkers/ssl_expiration.rb
watchmonkey_cli-1.7 lib/watchmonkey_cli/checkers/ssl_expiration.rb