#!/bin/bash # Retrieve X.509 certificate expiry information for a given host and port # # Copyright (C) 2021 Mike Gerwitz # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # # This will produce `x509_expire_seconds`, `x509_expire_success`, and #`x509_expire_scrape_duration_seconds`. # # WARNING: This script assumes trusted input and does not perform escaping # of label values. set -uo pipefail cd "$(dirname "$0")" main() { local host="${1?Missing domain}" local -i port="${2?Missing port}" local -ri start=$( date +%s%3N ) local expire_date expire_ts=0 ok=0 expire_date=$( openssl s_client -showcerts \ -connect "$host":"$port" \ 2>/dev/null \