Monitor Let's Encrypt expiry and get alerts with cron,
Certificate expiries are a real headache, and they usually only show up once something has already expired and gone sideways. With this small script and Signalgrid, you get a simple Let's Encrypt expiry alert before that turns into downtime, a broken HTTPS endpoint, or an annoying production surprise.
The example keeps the Signalgrid credentials directly inside the script for quick deployment. It is mainly aimed at Let's Encrypt-backed websites, reverse proxies, and HTTPS endpoints, but it also works as a general certificate expiration monitoring and alerting script for other TLS certificates exposed on a host and port.
What this script does
- connects to each target with
openssl s_client - reads the expiration date from the live Let's Encrypt certificate served by the endpoint
- sends a
WARNSignalgrid notification and expiration warning when the certificate is below the warning threshold - sends a
CRITalert when the certificate is below the critical threshold, already expired, or the certificate could not be read
Download and install
You can download the script directly from this page and place it somewhere like /usr/local/bin.
Replace the placeholder Signalgrid credentials and the example targets at the top of the file before you put it into cron or a crontab entry.
Configuration block
SIGNALGRID_CLIENT_KEYSIGNALGRID_CHANNELWARNING_DAYSCRITICAL_DAYSTARGETShost:port pairs to checkFull source code
The downloadable script is shown below exactly as provided.
Cron job example
Run the script once every morning. If a Let's Encrypt certificate is below your threshold, the script sends a notification and expiry alert. If it is still healthy, it stays quiet.
Notes
- The script checks the certificate that is actually served by the remote host, which is usually more useful for Let's Encrypt setups than checking a local certificate file.
- This works well even if you already use Certbot for automatic Let's Encrypt renewals, because it monitors the live certificate that users actually hit.
- The
-servernameoption is important for SNI, especially when multiple certificates are hosted on the same IP. - This example uses
date -d, so it is aimed at typical Linux cron environments with GNU date.