Created
April 7, 2023 11:48
-
-
Save jcgruenhage/8ef2f2fbc0af48189ee4585fb8054e40 to your computer and use it in GitHub Desktop.
node_exporter compatible textfile generator for certificate expiry
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
#!/usr/bin/python3 | |
from pathlib import Path | |
from cryptography import x509 | |
import time | |
textfile = open('/path/to/metrics', 'w') | |
textfile.write('# HELP ssl_certificate_expiry Unix timestamp of certificate expiry\n') | |
textfile.write('# TYPE ssl_certificate_expiry gauge\n') | |
certs_path = Path('/path/to/certificates') | |
for certificate_path in certs_path.glob('*.crt'): | |
if certificate_path.match('*.issuer.crt'): | |
continue | |
certificate_bytes = open(certificate_path, 'rb').read() | |
certificate = x509.load_pem_x509_certificate(certificate_bytes) | |
textfile.write('ssl_certificate_expiry{path="' + str(certificate_path) + '"} ' + certificate.not_valid_after.strftime('%s') + '\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment