SSL Certificate Expiry Monitoring Tool: Setup, Commands, and Comparison
An SSL certificate expiry monitoring tool should alert at 21–30 days before expiry, not on the expiry day: for 90-day Let's Encrypt certificates, a 21-day warning leaves three weeks to fix automation, DNS-01 challenges, or rate-limit issues. The smallest useful setup is a cron job that runs `openssl s_client -connect example.com:443 -servername example.com` and `openssl x509 -checkend 1814400`; exit code 1 means the certificate expires within 21 days. Prometheus blackbox_exporter 0.25.0+ exposes `probe_ssl_earliest_cert_expiry` as a Unix timestamp; alert with `(probe_ssl_earliest_cert_expiry - time()) < 86400 * 21`. SaaS SSL certificate expiry monitoring tools typically cost $1–$5 per certificate per month for small inventories, while enterprise platforms such as Venafi and Keyfactor are quote-based and often $10k+/year. Test the monitor against `expired.badssl.com` and a staging certificate with `duration: 24h`; a monitor that has never fired is not verified.
Why does an SSL certificate expiry monitoring tool matter, and what causes expired certificates?
Why does an SSL certificate expiry monitoring tool matter? Because certificate lifetimes are shrinking faster than most manual processes. Let’s Encrypt issues 90-day certificates, and Certbot renews when less than 30 days remain, per Let’s Encrypt documentation. The CA/Browser Forum Baseline Requirements cap public TLS certificates at 398 days for certificates issued after 2020-09-01, and ballot SC-081 schedules 200 days from 2026-03-15, 100 days from 2027-03-15, and 47 days from 2029-03-15. At 47 days, a monthly calendar reminder is already too slow; automated checks every 6 hours or less are the practical minimum.
The root causes are boring and repeatable: a disabled cron job or systemd timer, an ACME HTTP-01 challenge blocked by a CDN/WAF, an expired DNS API token for DNS-01, a manual certificate upload to a load balancer, or Let’s Encrypt rate limits (5 duplicate certificates per week and 50 certificates per registered domain per week, per Let’s Encrypt docs). That is why an SSL certificate expiry monitoring tool must alert on renewal failures, not only on expiry dates. Certbot’s packaged systemd timer normally runs twice daily with a randomized delay; verify it and rehearse renewal with:
# Certbot 2.x/3.x: list the timer, then test renewal without changing certs
systemctl list-timers --all | grep -E 'certbot|snap.certbot'
sudo certbot renew --dry-run
Expiry symptoms are easy to recognize: browsers show NET::ERR_CERT_DATE_INVALID, Go clients return x509: certificate has expired or is not yet valid, Java returns PKIX path validation failed, and curl exits 60 with SSL certificate problem: certificate has expired. If your SSL certificate expiry monitoring tool only checks the homepage, API and mTLS endpoints can expire unnoticed.
Internal CAs are the blind spot: internal certificates often live 1–3 years and serve mTLS, Kubernetes admission webhooks, database connections, and VPNs. When an internal intermediate expires, every leaf it signed fails at once. Probe the leaf and the presented chain with OpenSSL 1.1.1/3.x; -servername sets SNI, which matters behind CDN/WAF per OpenSSL s_client docs:
# Check the certificate clients actually receive
openssl s_client -connect shop.example.com:443 -servername shop.example.com </dev/null 2>/dev/null
| openssl x509 -noout -subject -issuer -dates -ext subjectAltName
# Save and inspect every certificate in the presented chain, not just the leaf
openssl s_client -connect shop.example.com:443 -servername shop.example.com -showcerts </dev/null 2>/dev/null
| awk '/BEGIN CERTIFICATE/{n++} n{print > ("chain-" n ".pem")}'
for f in chain-*.pem; do echo "$f"; openssl x509 -in "$f" -noout -subject -dates; done
| View | Catches | Misses |
| External probe | What users/API clients see: CDN, WAF, SNI virtual host | Unused, staging, decommissioned-host certs |
| Inventory | What you own, including unused certificates | CDN terminating TLS with a different certificate |
| Chain check | Expired intermediates that break all leaves | Ownership gaps and renewal automation failures |
You need both views: an external probe shows what clients actually see, while an inventory shows what you own. An SSL certificate expiry monitoring tool that only does external probes will miss unused certificates; one that only does inventory will miss a CDN terminating TLS with a different certificate. The economic argument is simple: a SaaS SSL certificate expiry monitoring tool at $1–$5 per certificate per month is usually less than one hour of an e-commerce or API outage. The hard part is not buying the tool; it is assigning an owner and a runbook to every certificate.
What should an SSL certificate expiry monitoring tool check beyond days-to-expiry?
Days-to-expiry is the easy part. A real ssl certificate expiry monitoring tool must also answer: is the whole chain valid, does the name actually match, will a browser trust it, and is the clock telling the truth? Here is what to probe, with commands you can paste into a check script.
1. Leaf and chain, not just the leaf. openssl s_client prints every certificate the server sends, and -showcerts keeps the intermediates in the output:
openssl s_client -connect example.com:443 -servername example.com -showcerts </dev/null
# Then inspect each cert:
openssl x509 -noout -dates -subject -issuer -in cert.pem
# notBefore=Mar 1 00:00:00 2025 GMT
# notAfter=May 30 23:59:59 2025 GMT
Dates are always UTC (RFC 5280 §4.1.2.5), so never parse them as local time. Prometheus blackbox_exporter exposes probe_ssl_earliest_cert_expiry, which is the minimum expiry across the chain — the metric that catches an intermediate expiring before the leaf. Pair it with probe_ssl_last_chain_expiry_timestamp_seconds to see both ends.
2. Hostname coverage. openssl x509 -noout -ext subjectAltName -in cert.pem lists SANs. A wildcard *.example.com covers api.example.com but not api.staging.example.com (two labels) and not the apex example.com. For IDNs, check the A-label (punycode) form — xn--bcher-kva.example — because a monitor comparing Unicode strings can report a false OK. RFC 6125 §6.4.3 defines the wildcard rules; RFC 5280 §4.2.1.6 requires SANs, and CN-only matching is deprecated.
3. Trust and revocation. Verification must be explicit, not assumed:
openssl s_client -connect example.com:443 -servername example.com
-verify_return_error -CAfile /etc/ssl/certs/ca-certificates.crt </dev/null
# Look for: Verify return code: 0 (ok)
# OCSP stapling:
openssl s_client -connect example.com:443 -servername example.com -status </dev/null | grep -A2 "OCSP Response Status"
For internal CAs, point -CAfile at your internal root — never disable verification, or the check proves nothing. Per Let’s Encrypt’s documentation, its certificates chain to ISRG Root X1/X2; expired cross-signs are a classic cause of “valid leaf, broken chain” alerts.
4. Protocol and key parameters. TLS 1.2/1.3 enabled, TLS 1.0/1.1 disabled; RSA ≥ 2048 bits, ECDSA ≥ P-256; signatures SHA-256 or stronger. Check with openssl s_client -tls1_1 (expect failure) and openssl x509 -noout -text | grep -E "Public-Key|Signature Algorithm". Mozilla’s Server Side TLS guide is the reference baseline.
5. Clock sanity. openssl x509 -checkend 86400 compares against the local clock. Ten minutes of skew produces false alarms or misses a just-expired cert; confirm with chronyc tracking or timedatectl status and alert on offset > 60s.
| Check | Command / metric | Failure it catches |
|---|---|---|
| Earliest chain expiry | probe_ssl_earliest_cert_expiry |
Expired intermediate |
| SAN match | -ext subjectAltName |
Wildcard depth / apex miss |
| Trust path | -verify_return_error -CAfile |
Missing intermediate, wrong root |
| OCSP staple | -status |
Revoked or stale staple |
| Clock offset | chronyc tracking |
False expiry alarms |
Finally, attach metadata to every target — owner, environment, DNS name, issuing CA, renewal method (ACME vs manual vs internal). Without it, a 21-day alert sends someone hunting through spreadsheets, which defeats the purpose of an ssl certificate expiry monitoring tool.
Step-by-step: how do you build a minimal SSL certificate expiry monitoring tool with OpenSSL?
How do you build a minimal SSL certificate expiry monitoring tool with OpenSSL? Start with an inventory file that lives in Git — one host:port per line — because that file, not a vendor dashboard, becomes the source of truth your SSL certificate expiry monitoring tool reads on every run. Comments and blank lines are skipped, and every pull request that adds an endpoint is a reviewable change.
# /etc/ssl-monitor/endpoints.txt — committed to Git, reviewed via PR
example.com:443
api.example.com:8443
internal.example.com:443
What does a correct one-off probe look like? Always pass -servername (SNI). Omit it and you get the default virtual host’s certificate — the single most common false result in DIY monitoring, since SNI-less probes on shared IPs silently report the wrong expiry date. Per RFC 6066, SNI is how the client names the host it wants.
openssl s_client -connect example.com:443 -servername example.com -showcerts /dev/null
| openssl x509 -noout -enddate -subject -issuer
# notAfter=Mar 1 23:59:59 2026 GMT
# subject=CN = example.com
# issuer=C = US, O = Let's Encrypt, CN = R11
How do you turn that into a pass/fail gate? Save the leaf cert to cert.pem, then use openssl x509 -checkend <seconds> (present in OpenSSL 1.1.1 and 3.x). It exits 0 and prints Certificate will not expire when more than the threshold remains; otherwise exit 1 and Certificate will expire.
| Seconds | Days | Typical use |
|---|---|---|
| 2592000 | 30 | Let’s Encrypt renews at 30 days remaining — alert if still unrenewed |
| 1814400 | 21 | Warning tier; leaves time for manual issuance |
| 1209600 | 14 | Page on-call; renewal is clearly broken |
| 604800 | 7 | Hard failure — outage imminent |
openssl s_client -connect example.com:443 -servername example.com /dev/null
| openssl x509 -outform PEM > cert.pem
openssl x509 -checkend 1814400 -noout -in cert.pem; echo "exit=$?"
# Certificate will not expire
# exit=0
How do you feed Prometheus? Write a textfile the collector can scrape, using set -euo pipefail, absolute paths, and a temp file plus mv (atomic rename) so node_exporter never parses a half-written file:
#!/usr/bin/env bash
set -euo pipefail
INVENTORY=/etc/ssl-monitor/endpoints.txt
OUT=/var/lib/node_exporter/textfile_collector/ssl_cert_expiry.prom
TMP=$(mktemp "${OUT}.XXXXXX"); trap 'rm -f "$TMP"' EXIT
while IFS=: read -r host port; do
[[ -z "$host" || "$host" == #* ]] && continue
end=$(/usr/bin/openssl s_client -connect "${host}:${port}" -servername "$host" /dev/null
| /usr/bin/openssl x509 -noout -enddate 2>/dev/null) || { echo "probe failed ${host}:${port}" >&2; continue; }
epoch=$(date -u -d "${end#notAfter=}" +%s) # GNU date; BSD/macOS: date -j -f "%b %d %T %Y %Z"
printf 'ssl_cert_expiry_timestamp{host="%s",port="%s"} %sn' "$host" "$port" "$epoch" >> "$TMP"
done < "$INVENTORY"
mv "$TMP" "$OUT"
Note the version trap: OpenSSL 1.1.1’s s_client can exit 0 even after a failed handshake, while OpenSSL 3.x returns non-zero — the || continue guard above covers both, and a missing series is itself alertable (absent(ssl_cert_expiry_timestamp)). Alert with (ssl_cert_expiry_timestamp - time()) < 86400 * 21.
How often should it run, and from where? Every 6 hours, from the same network vantage point as users — a probe inside the VPC may see an internal CA certificate that public clients never receive. Use a systemd timer:
# /etc/systemd/system/ssl-monitor.timer
[Timer]
OnCalendar=*-*-* 00/6:00:00
Persistent=true
# crontab equivalent
0 */6 * * * /usr/local/bin/ssl-monitor.sh
Finally, route alerts to Alertmanager, PagerDuty, Slack, or email with a runbook URL and the certificate owner, then test the path against expired.badssl.com:443 — if nothing fires, your SSL certificate expiry monitoring tool is not finished.
Configuration examples for popular SSL certificate expiry monitoring tools
Most certificate monitoring failures are configuration failures, not detection failures: the prober follows a redirect to a different host, the check runs without SNI and validates the default vhost, or the alert only fires on expiry and stays silent when the handshake itself breaks. The examples below are the copy-paste versions that avoid those traps — RFC 5280 defines expiry via the notAfter field, but every tool surfaces it differently.
# blackbox_exporter 0.25.0+ — /etc/blackbox_exporter/config.yml
modules:
https_cert:
prober: http
timeout: 5s # module default is 10s; keep it under scrape_timeout
http:
preferred_ip_protocol: ip4 # default is ip6; pin it if egress is IPv4-only
follow_redirects: false # default true — a 301 to another host would swap the cert under test
tls_config:
insecure_skip_verify: false # default; never flip this in production
# scrape: /probe?module=https_cert&target=https://example.com (metrics_path: /probe)
probe_ssl_earliest_cert_expiry reports the minimum notAfter across the whole presented chain, so an expired intermediate is caught even when the leaf is valid. Pair it with probe_success, otherwise an expired cert that fails the handshake returns no expiry series at all:
- alert: SSLCertExpiresIn21Days
expr: (probe_ssl_earliest_cert_expiry - time()) < 86400 * 21
for: 1h
labels: { severity: warning }
annotations:
summary: 'TLS certificate for {{ $labels.instance }} expires in {{ $value | humanizeDuration }}'
- alert: SSLProbeFailing # silent-handshake guard
expr: probe_success == 0
for: 10m
labels: { severity: critical }
humanizeDuration expects seconds and renders 1814400 as 3 weeks. For Nagios/Icinga, Monitoring Plugins exit codes are 0 OK, 1 WARNING, 2 CRITICAL, 3 UNKNOWN — and --sni is mandatory on shared hosting, or you validate the wrong certificate and get a false OK:
check_http --ssl --sni -H example.com -C 21,7 # -C warn_days,crit_days; no expiry check by default
check_ssl_cert --host example.com --port 443 --sni --warning 21 --critical 7 --ocsp
# failure text: "SSL certificate expired" or "SSL error: certificate verify failed"
Zabbix 6.4/7.0 ships the Website certificate by Zabbix agent 2 template using web.certificate.get[example.com,443]. Create a dependent item with JSONPath $.not_after, convert the ISO-8601 string to a Unix timestamp in preprocessing if needed, then trigger on (last(/host/cert.not_after) - now()) < 21d. The template’s expiry macro defaults to 7 days — raise it before rolling out to hundreds of hosts. cert-manager 1.15+ is the lowest-effort SSL certificate expiry monitoring tool for Kubernetes teams, since it already knows about renewal:
(certmanager_certificate_expiration_timestamp_seconds{name="example-tls",namespace="default"} - time()) < 86400 * 21
certmanager_certificate_ready_status{condition="False"} == 1 # renewal failing
For AWS, EventBridge emits an ACM Certificate Expiration event 45 days before expiry per AWS docs, but only ACM-issued public certificates auto-renew — imported ones need a separate SSL certificate expiry monitoring tool:
aws acm list-certificates --certificate-statuses ISSUED
--query "CertificateSummaryList[?Type=='IMPORTED'].[DomainName,CertificateArn]" --output table
| Tool / version | Signal | Threshold control | Renewal-aware? | Gotcha |
|---|---|---|---|---|
| blackbox_exporter 0.25+ | probe_ssl_earliest_cert_expiry |
PromQL 86400 * 21 |
No | Needs follow_redirects: false |
| check_ssl_cert 2.x | leaf + chain + OCSP | --warning/--critical days |
No | No --sni = wrong vhost |
| Zabbix 6.4/7.0 template | web.certificate.get → $.not_after |
Template macro (7d default) | No | Date-format preprocessing |
| cert-manager 1.15+ | certmanager_certificate_expiration_timestamp_seconds |
PromQL | Yes | Only certs it issues |
| AWS ACM + EventBridge | Expiration event at 45 days | Fixed by AWS | AMAZON_ISSUED only | IMPORTED never renews |
Comparison table: open-source vs SaaS SSL certificate expiry monitoring tools
| Tool | Model | Key metric or command | Cost range | Best fit |
|---|---|---|---|---|
| Prometheus blackbox_exporter 0.25.0+ | Open source, Apache 2.0 | probe_ssl_earliest_cert_expiry |
$0 license + ops time | Prometheus shops |
| check_ssl_cert 2.x / check_http | Open source, GPLv3 | --warning 21 --critical 7 |
$0 | Nagios/Icinga |
| Zabbix 6.4 / 7.0 | Open source, GPLv2 | web.certificate.get |
$0 + server | Existing Zabbix |
| cert-manager 1.15+ | Open source, Apache 2.0 | certmanager_certificate_expiration_timestamp_seconds |
$0 | Kubernetes |
| SaaS certificate monitoring | Commercial | dashboard + API | $1–$5/cert/month; enterprise $10k+/year | Multi-cloud inventory |
| Venafi / Keyfactor | Enterprise CLM | policy + automation | quote-based, often $10k+/year | Regulated enterprises |
What does the license actually cost? Zero dollars, but budget 2–8 hours per month for upgrades, endpoint inventory, and alert tuning. The real cost of an open-source ssl certificate expiry monitoring tool is the person who owns the endpoint list — every new load balancer or internal CA you add is a config commit.
Two copy-pasteable starting points. In blackbox_exporter 0.25.0, the TLS probe returns probe_ssl_earliest_cert_expiry as a Unix timestamp, so the alert is arithmetic:
# blackbox.yml — module used by the Prometheus scrape job
modules:
https_cert:
prober: http
timeout: 10s
http:
preferred_ip_protocol: ip4
tls_config:
insecure_skip_verify: false # never true in prod; hides expiry
# prometheus rule: fires 21 days out
- alert: CertExpiringSoon
expr: probe_ssl_earliest_cert_expiry - time() < 86400 * 21
for: 1h
labels: { severity: warning }
For Nagios/Icinga, check_ssl_cert 2.x expresses thresholds in days, which is why it stays popular:
check_ssl_cert --host example.com --port 443 --sni
--warning 21 --critical 7 --altnames # fails on SAN mismatch too
# exit 2 -> CRITICAL; expired certs surface as "certificate has expired"
In Zabbix, the agent 2 item web.certificate.get[example.com,443] returns a JSON document; map the not_after field with a JSONPath preprocessor and trigger on the delta. In Kubernetes, cert-manager 1.15+ exposes certmanager_certificate_expiration_timestamp_seconds per Certificate object — no external probing needed, but it only sees certs cert-manager issued.
How does SaaS pricing break down? Roughly $1–$5 per certificate per month at 10–100 certs, $0.50–$2 at 500+, and $10k–$50k/year for enterprise CLM with CA integrations. Free tiers typically cap at 1–10 certificates. SaaS earns its price through inventory discovery, owner assignment, and ServiceNow/Slack/PagerDuty routing — open source gives you flexibility and no data egress.
Build or buy? Under 50 certificates on one cloud, blackbox_exporter or cert-manager metrics win. 100+ across multi-cloud plus internal CAs, SaaS or enterprise CLM. Regulated environments: self-hosted, or SaaS with private agents.
Data privacy: internal hostnames and cert metadata leak architecture. Confirm private agents, SOC 2 Type II, and data residency before signing. An ssl certificate expiry monitoring tool never needs your private keys — only the public chain and a TCP connection, per RFC 5280 validation semantics and OpenSSL’s
s_client -connect host:443 -servername hostbehaviour.
How do you scale SSL certificate expiry monitoring across Kubernetes, load balancers, and internal CAs?
At scale, the hard part isn’t parsing a certificate — it’s getting every certificate source into one queryable place with an owner attached. Here’s how each layer is actually enumerated.
Kubernetes / cert-manager. cert-manager stores intent as a Certificate object, so you can inventory without touching a socket:
# cert-manager 1.15/1.16: list every Certificate across namespaces
kubectl get certificates -A -o custom-columns=
NS:.metadata.namespace,NAME:.metadata.name,SECRET:.spec.secretName,
DNS:.spec.dnsNames[*],ISSUER:.spec.issuerRef.name
# Inspect one object's renewal state and last failure
kubectl describe certificate my-cert -n prod | grep -E 'Renewal Time|Not After|Events'
Then alert on the exported controller metrics (default scrape via the chart’s ServiceMonitor):
# Fires when cert-manager cannot issue/renew
certmanager_certificate_ready_status{condition="False"} == 1
# 21 days to expiry, per Certificate
(certmanager_certificate_expiration_timestamp_seconds - time()) < 86400 * 21
# ACME/HTTP01 debugging (1.15+)
rate(certmanager_http_acme_client_request_count{status!="200"}[10m]) > 0
Ingress-nginx. The controller exports per-host expiry, which is more useful than cert-manager alone because it reflects what is actually served:
# days-to-expiry per ingress host
(nginx_ingress_controller_ssl_expire_time_seconds - time()) / 86400 < 21
Confirm the metric exists before building dashboards — kubectl exec into the controller and curl -s localhost:10254/metrics | grep ssl_expire, since the name changed across chart generations.
Load balancers. None of these speak Prometheus natively; export to textfile/Pushgateway or a CSV the SSL certificate expiry monitoring tool ingests:
echo 'show ssl cert' | socat stdio /var/run/haproxy.sock # HAProxy 2.x, lists .pem paths
curl -sku admin:pass https://f5/mgmt/tm/sys/file/ssl-cert # F5 iControl REST
show ssl cert # Citrix ADC CLI
Internal CAs. Vault PKI: vault list pki/certs, then vault read pki/cert/<serial> for expiration. step-ca exposes /admin/certificates. Track root and intermediate expiry as separate alerts — an expired intermediate silently breaks every leaf it signed, and leaf-only monitoring won’t tell you.
| Source | Enumeration | Granularity | Gotcha |
|---|---|---|---|
| cert-manager | certmanager_certificate_expiration_timestamp_seconds |
per Certificate CR | Desired state, not served state |
| ingress-nginx | nginx_ingress_controller_ssl_expire_time_seconds |
per host | Name varies by chart version |
| HAProxy / F5 / Citrix | socket, REST, CLI | per cert file | Needs an exporter |
| Vault PKI | pki/certs |
per serial | Revoked ≠ removed |
Centralize with Prometheus federation, Thanos, or Mimir; deduplicate on (host,port,serial) so a certificate behind both a CDN and an origin doesn’t page twice. Finally, label every series with team, service, env, and renewal_method (cert-manager, ACME, manual), and route by label. Per Let’s Encrypt’s own guidance, automation plus a short renewal window beats long-lived certs — but only if someone owns the alert when automation fails.
Common errors and troubleshooting when an SSL certificate expiry monitoring tool fails
Why is probe_ssl_earliest_cert_expiry 0 or missing entirely?
Zero is not “expires now” — it is blackbox_exporter reporting that no TLS handshake completed, so no certificate was ever parsed. Check the sibling metric first: if probe_success == 0, the failure is DNS, a firewall dropping 443, SNI routing to a default vhost, or a certificate that already expired (OpenSSL aborts the handshake before exposing dates). Reproduce it by hand from the exporter host, not your laptop:
# 1. Confirm the exporter's own view of the probe
curl -s 'http://localhost:9115/probe?target=https://example.com&module=https_2xx'
| grep -E 'probe_success|probe_ssl_earliest_cert_expiry|probe_duration_seconds'
# 2. Handshake manually, with SNI, and print the real error
openssl s_client -connect example.com:443 -servername example.com -showcerts &1
| openssl x509 -noout -subject -issuer -dates
# Typical outputs:
# verify error:num=10:certificate has expired
# connect: Connection refused (firewall / listener)
# no peer certificate available (SNI mismatch or plain-HTTP port)
Why does the tool show the wrong certificate? Almost always missing SNI (RFC 6066). Without it the server returns the first vhost in its config, which may be valid for years while your real cert is 3 days from expiry. In blackbox_exporter’s module:
modules:
https_2xx:
prober: http
timeout: 10s
http:
preferred_ip_protocol: ip4
tls_config:
server_name: example.com # REQUIRED behind SNI-based LBs
ca_file: /etc/ssl/internal-root.pem # internal CA trust anchor
min_version: TLS12 # TLS10/TLS11 rejected by modern stacks
# insecure_skip_verify: true # DO NOT — see below
Why does an internal CA fail verification, and why not just skip it? insecure_skip_verify: true disables chain, hostname, and expiry validation together — an SSL certificate expiry monitoring tool that skips verification cannot detect an expired or wrong-host certificate, which is precisely its job. Point ca_file at the root instead (Prometheus blackbox_exporter docs, tls_config block) and pin min_version: TLS12 per Mozilla’s server-side TLS guidance.
Why does the script work manually but not under cron? cron runs with a minimal environment and /bin/sh. Use absolute paths (/usr/bin/openssl), declare SHELL=/bin/bash and a PATH in the crontab, log to journald or a file, and prove it with env -i /bin/bash -c '/usr/local/bin/check-cert.sh'.
Why does Let’s Encrypt renewal keep failing? Run certbot renew --dry-run --debug-challenges, then read /var/log/letsencrypt/letsencrypt.log; HTTP-01 needs inbound port 80 reachable from the internet, DNS-01 needs API credentials with the right zone scope. Mind the published rate limits — 5 duplicate certificates per week and 50 certificates per registered domain per week — because retry loops burn them fast.
| Symptom | Root cause | Fix |
|---|---|---|
probe_ssl_earliest_cert_expiry 0 |
Handshake never completed | Fix DNS/firewall; check probe_success |
| Date matches the wrong vhost | No SNI sent | server_name / -servername |
x509: certificate signed by unknown authority |
Private CA untrusted | ca_file, never insecure_skip_verify |
| Silent cron job | PATH / SHELL mismatch | Absolute paths, env -i test |
Why do alerts fire daily? Group by alertname,host, set repeat_interval: 4h, stage thresholds at 30/14/7 days, and silence during planned migrations. An SSL certificate expiry monitoring tool that pages every day trains people to ignore it — the same fatigue that makes teams disable TLS verification in the first place.
How do you verify an SSL certificate expiry monitoring tool actually works?
A monitor is only trustworthy once you have watched it fail. Point your ssl certificate expiry monitoring tool at hosts whose certificates are deliberately broken, then assert on exit codes rather than on pretty dashboards. The public badssl.com suite is the standard fixture: per the project’s own docs, expired.badssl.com serves a certificate past its notAfter, self-signed.badssl.com serves an untrusted chain, and wrong.host.badssl.com serves a name that does not match the SANs.
# curl exits 60 (SSL peer certificate or SSH remote key was not OK) on all three
curl -sS -o /dev/null https://expired.badssl.com/ ; echo "exit=$?" # exit=60
curl -sS -o /dev/null https://self-signed.badssl.com/ ; echo "exit=$?" # exit=60
# OpenSSL names the specific failure — grep the numeric verify code
openssl s_client -connect expired.badssl.com:443 -servername expired.badssl.com </dev/null 2>&1
| grep -E 'verify error|Verify return code'
# verify error:num=10:certificate has expired
# Verify return code: 10 (certificate has expired)
openssl s_client -connect self-signed.badssl.com:443 -servername self-signed.badssl.com </dev/null 2>&1
| grep 'Verify return code' # Verify return code: 18 (self-signed certificate)
openssl s_client -connect wrong.host.badssl.com:443 -servername wrong.host.badssl.com </dev/null 2>&1
| grep 'Verify return code' # Verify return code: 62 (hostname mismatch)
Codes 10, 18 and 62 come from the X509_V_ERR table in OpenSSL’s verify(1); a tool that reports only “certificate invalid” without the numeric code will hide hostname and chain problems behind expiry alerts. The -checkend probe is the cheapest threshold test you can automate — it takes a seconds argument and exits 1 when the certificate expires inside that window (OpenSSL x509(1)):
openssl s_client -connect expired.badssl.com:443 -servername expired.badssl.com </dev/null 2>/dev/null
| openssl x509 -checkend 0 -noout; echo $?
# Certificate will expire
# 1 <- non-zero = inside the window; use 1814400 (21d) for real thresholds
| Test target | Failure simulated | curl exit | openssl verify code | -checkend 0 |
|---|---|---|---|---|
| expired.badssl.com | notAfter in the past | 60 | 10 | 1 “will expire” |
| self-signed.badssl.com | untrusted root | 60 | 18 | 0 (still valid) |
| wrong.host.badssl.com | hostname mismatch | 60 | 62 | 0 (still valid) |
Next, prove the alert path, not just the probe. cert-manager issues short-lived certificates when duration and renewBefore are set; note that Let’s Encrypt ignores requested durations and always issues 90 days, so use a SelfSigned or private CA issuer to genuinely get 24h. renewBefore defaults to one third of duration per cert-manager docs, and must be strictly less than it:
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: expiry-probe
namespace: cert-test # isolated namespace; silence prod routes while testing
spec:
secretName: expiry-probe-tls
duration: 24h # short-lived on purpose
renewBefore: 12h # default = duration/3
dnsNames: [probe.test.example.com]
issuerRef: {name: test-selfsigned, kind: ClusterIssuer}
With a 21-day threshold this certificate is already “expiring”, so the alert should fire on the first scrape. Verify delivery by injecting an alert directly with amtool, which bypasses the probe and tests routing only:
amtool alert add alertname=SSLCertExpiresIn21Days instance=test.example.com:443 severity=warning
--annotation=summary="synthetic expiry probe"
--alertmanager.url=http://alertmanager.monitoring.svc:9093
# then confirm it reached Slack/PagerDuty/email and that it auto-resolved after ~5m
Finally, audit coverage: reconcile the certificate count in your inventory or CA report against the monitored set, and hand-check a 10% sample with openssl s_client ... | openssl x509 -noout -enddate -subject. Below 95% coverage, the ssl certificate expiry monitoring tool is not authoritative and should not own the pager. After each real renewal, log detection time, alert delivery time, and time-to-renew, and review quarterly — a monitor that has never fired in staging has not been verified, and an ssl certificate expiry monitoring tool that only fires in production is an outage generator.
There is no single best; choose by environment. Prometheus shops usually get the lowest friction from blackbox_exporter 0.25.0+ because `probe_ssl_earliest_cert_expiry` is a native metric. Nagios/Icinga teams can use `check_http -C 21,7` or `check_ssl_cert –warning 21 –critical 7`. Kubernetes teams should start with cert-manager metrics before buying a SaaS SSL certificate expiry monitoring tool.
For 90-day Let's Encrypt certificates, alert at 21–30 days before expiry, then again at 14 and 7 days. For 398-day public certificates, 30 days is still a reasonable first warning. For the planned 47-day certificates under CA/Browser Forum SC-081, use 14/7/3-day thresholds so the alert leaves time to act.
The most common cause is SNI: without `-servername` or `tls_config.server_name`, OpenSSL and blackbox_exporter may see the default virtual host certificate. Other causes include a CDN terminating TLS with a different certificate, checking the leaf when the intermediate expires first, or comparing UTC `notAfter` against a local-time display.
Yes for a small inventory, roughly under 50 endpoints. Use `openssl s_client -connect host:443 -servername host` plus `openssl x509 -checkend 1814400`, write Prometheus textfile metrics, and schedule it every 6 hours. OpenSSL alone gives no inventory, ownership, or alert routing, so you still need cron/systemd, node_exporter, and Alertmanager around it.
Distribute the internal root to the monitoring host and use `-CAfile /etc/ssl/internal-root.pem` with OpenSSL, or `tls_config.ca_file` in blackbox_exporter. Enumerate issued certificates from Vault PKI (`vault list pki/certs`) or step-ca, and monitor root and intermediate expiry separately because an intermediate expiry breaks all leaf certificates.
That metric is absent when the TLS handshake fails, so check `probe_success` first. Typical causes are DNS resolution failure, a firewall blocking the exporter, missing SNI, an expired certificate, or an untrusted internal CA. Run `openssl s_client -connect host:443 -servername host` from the exporter host to reproduce the failure.
Open-source tools such as blackbox_exporter, check_ssl_cert, Zabbix, and cert-manager cost $0 in license fees but need 2–8 hours per month of operations time. SaaS monitoring typically costs $1–$5 per certificate per month for small inventories and $0.50–$2 at 500+ certificates. Enterprise CLM platforms such as Venafi and Keyfactor are quote-based and often exceed $10k per year.
本文由 sslgood.com 安全团队基于生产环境实战经验撰写,关键结论均经过技术复核。