Catching TLS certificate expiry before it becomes an outage
What happened
I wasn't checking certificate expiry directly. An expired certificate is a full outage, and it is completely preventable, so I wanted a check that warns well before it happens.
The fix / What I built
I added a daily job that does the following for every active site:
- Opens a TLS connection to the site.
- Reads the certificate's
notAfterdate. - Works out how many days are left.
- Raises an alert when fewer than 14 days remain.
The job reuses the alerting pipeline I already had. It uses only the standard library's ssl module, so it needs no new credentials and no new dependencies.
Why it works
The check looks at the certificate itself instead of waiting for a failure, so it gives warning ahead of time. A 14-day threshold leaves room to fix a broken renewal before anyone is affected.
After the first run, the check reported days-left for every active site, with comfortable margins. I kept the change because it works as intended and costs almost nothing to run.
Takeaway
Check certificate expiry directly and alert well ahead of the deadline. Don't rely on failures to tell you a certificate has lapsed.