Cert Expiry Checker
Cert Expiry Checker reports how many days are left before the TLS certificates of a list of hosts expire — as a table in the terminal or as a Prometheus metric for alerting.
Source on GitHub · Summary on chaintools.tech · MIT licence
Requirements
- Python 3.9 or newer
Install
git clone https://github.com/qf3l3k/cert_expiry_checker.git && cd cert_expiry_checker
python3 -m venv .venv && . .venv/bin/activate
pip install . pyyaml prometheus-clientpyyaml and prometheus-client are used by the tool but not listed in its package requirements, so install them alongside.
Configuration
exporter:
port: 8000
urls:
- url: chaintools.tech:443
- url: explorer.chaintools.tech:443
- url: rpc.bitsong.chaintools.tech:443Each entry must be host:port. exporter.port is optional (default 8000). Set another port when Orbit Metrics or Delegator Tracker runs on the same host: both use 8000 and can't be changed.
Usage
cert_exp_check --mode cli --config config.yaml --log-level infocert_exp_check --mode exporter --config config.yaml --log-level info| Option | Default | Meaning |
|---|---|---|
--mode | — (required) | cli or exporter |
--config | — (required) | Configuration file |
--log-level | — (required) | info, or verbose to also list connection errors under the table |
--log-file | cert_exp_check.log | Log file |
Output
The table lists each host with its port, the certificate's expiry date and the days left. Hosts that can't be reached show Unable to connect.
The exporter listens on exporter.port, checks all hosts every 5 minutes, and exposes:
certificate_expiration_days{hostname="chaintools.tech",port="443"} 62Unreachable hosts get no value. Example alert rule:
groups:
- name: certificates
rules:
- alert: CertificateExpiresSoon
expr: certificate_expiration_days < 14
labels:
severity: warning
annotations:
summary: "Certificate for {{ $labels.hostname }} expires in {{ $value }} days"