Class: WatchmonkeyCli::Checkers::SslExpiration
- Inherits:
-
WatchmonkeyCli::Checker
- Object
- WatchmonkeyCli::Checker
- WatchmonkeyCli::Checkers::SslExpiration
- Defined in:
- lib/watchmonkey_cli/checkers/ssl_expiration.rb
Constant Summary
Constants included from Helper
Instance Attribute Summary
Attributes inherited from WatchmonkeyCli::Checker
Instance Method Summary collapse
Methods inherited from WatchmonkeyCli::Checker
#_tolog, #blank_config, checker_name, checker_name=, #debug, descendants, #error, #info, inherited, #init, #initialize, #local, maxrt, maxrt=, #rsafe, #safe, #spawn_sub, #start, #stop
Methods included from Helper
#human_filesize, #human_number, #human_seconds
Constructor Details
This class inherits a constructor from WatchmonkeyCli::Checker
Instance Method Details
#check!(result, page, opts = {}) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/watchmonkey_cli/checkers/ssl_expiration.rb', line 11 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 |
#enqueue(page, opts = {}) ⇒ Object
6 7 8 9 |
# File 'lib/watchmonkey_cli/checkers/ssl_expiration.rb', line 6 def enqueue page, opts = {} opts = { threshold: 28.days, verify: true, timeout: 20 }.merge(opts) app.enqueue(self, page, opts) end |