Last active
September 6, 2018 09:46
-
-
Save sshastri/00b727bf57b67626029c2d9d099946ac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'date' | |
Facter.add(:cert_expire) do | |
confine :kernel => 'Linux' | |
setcode do | |
hostname = Facter.value(:hostname) | |
info = Facter::Core::Execution.execute("echo | openssl s_client -showcerts -connect #{hostname}:443 2>/dev/null | openssl x509 -noout -dates") | |
expire_info = {} | |
dates = info.split("\n") | |
if !dates[0].nil? | |
start_date = dates[0].gsub('notBefore=','') | |
end_date = dates[1].gsub('notAfter=','') | |
expire_info['start_date'] = start_date | |
expire_info['end_date'] = end_date | |
expire_info['days_to_expire'] = (Date.parse(end_date) - Date.today).to_i | |
else | |
expire_info = '' | |
end | |
expire_info | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here ya go @sshastri