Skip to content

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 ​

Install ​

bash
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-client

pyyaml and prometheus-client are used by the tool but not listed in its package requirements, so install them alongside.

Configuration ​

yaml
exporter:
  port: 8000
urls:
  - url: chaintools.tech:443
  - url: explorer.chaintools.tech:443
  - url: rpc.bitsong.chaintools.tech:443

Each 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 ​

bash
cert_exp_check --mode cli --config config.yaml --log-level info
bash
cert_exp_check --mode exporter --config config.yaml --log-level info
OptionDefaultMeaning
--mode— (required)cli or exporter
--config— (required)Configuration file
--log-level— (required)info, or verbose to also list connection errors under the table
--log-filecert_exp_check.logLog 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:

txt
certificate_expiration_days{hostname="chaintools.tech",port="443"} 62

Unreachable hosts get no value. Example alert rule:

yaml
groups:
  - name: certificates
    rules:
      - alert: CertificateExpiresSoon
        expr: certificate_expiration_days < 14
        labels:
          severity: warning
        annotations:
          summary: "Certificate for {{ $labels.hostname }} expires in {{ $value }} days"