Last active
September 8, 2020 07:39
-
-
Save mrpatrick/6829734 to your computer and use it in GitHub Desktop.
Updated to use OpenSSL and cert tags as subprocess no longer works with latest dd-agent
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
import time | |
import datetime | |
from OpenSSL import crypto as c | |
from checks import AgentCheck | |
class SSLCheckExpireDays(AgentCheck): | |
def check(self, instance): | |
metric = "ssl.expire_in_days" | |
certfile = instance['cert'] | |
cert_tag = 'cert:%s' % (certfile.split('/')[-1:],) | |
date_format = "%Y%m%d%H%M%SZ" | |
cert = c.load_certificate(c.FILETYPE_PEM, file(certfile).read()) | |
output = cert.get_notAfter() | |
if output: | |
d0 = datetime.datetime.today() | |
d1 = datetime.datetime(*(time.strptime(output, date_format)[0:3])) | |
delta = d1 - d0 | |
self.gauge(metric, int(delta.days), tags=[cert_tag]) | |
else: | |
self.gauge(metric, -1, tags=[cert_tag]) |
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
init_config: | |
instances: | |
- cert: /etc/ssl/www.mywebsite1.com.crt | |
- cert: /etc/ssl/www.mywebsite2.com.crt | |
- cert: /etc/ssl/www.mywebsite3.com.crt |
Yeah i also need to get this working for a windows agent, is this possible?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi.
Will this work for the windows agent ?
I mean the path to certificates is in a "linux" format. If so how is the path to certificates formatted?