|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# This check was written in response to the poorly communicated expiration |
| 4 | +# of the 2016 PEM file required to make SSL-encrypted connections to Rackspace |
| 5 | +# cloud databases, including MySQL and Redis (from Object Rocket). This blew |
| 6 | +# up on us in February 2021 when the 2016 PEM file was replaced with the 2021 |
| 7 | +# PEM file. |
| 8 | +# |
| 9 | +# The idea here is that we want to be able to get alerted about 4-6 weeks before |
| 10 | +# the CA cert expires again, which will be in 5+ years and we won't remember |
| 11 | +# it without an alert. Then we can proactively reach out to Rackspace, maybe |
| 12 | +# accept the new cert for 2026 before they switch over and not experience |
| 13 | +# downtime. |
| 14 | +# |
| 15 | +# See: |
| 16 | +# https://docs.objectrocket.com/redis_stunnel.html |
| 17 | +# http://ssl.rackspaceclouddb.com/rackspace-ca-2021.pem |
| 18 | +# |
| 19 | + |
| 20 | +if [ $# -ne 1 ]; then |
| 21 | + echo "Usage: $0 </path/to/ca/certificate.pem>" |
| 22 | + exit 100 |
| 23 | +fi |
| 24 | + |
| 25 | +CA_FILE=$1 |
| 26 | +NOW=$(TZ=UTC date '+%s') |
| 27 | + |
| 28 | +CMD="openssl x509 -noout -in $CA_FILE -dates" |
| 29 | +NOT_BEFORE=$($CMD | grep notBefore | sed 's/^not.*\=//') |
| 30 | +NOT_AFTER=$($CMD | grep notAfter | sed 's/^not.*\=//') |
| 31 | + |
| 32 | +NOT_BEFORE_AT=$(TZ=UTC date '+%s' --date "$NOT_BEFORE") |
| 33 | +NOT_AFTER_AT=$(TZ=UTC date '+%s' --date "$NOT_AFTER") |
| 34 | +NOT_BEFORE_LOCAL=$(date --date "$NOT_BEFORE") |
| 35 | +NOT_AFTER_LOCAL=$(date --date "$NOT_AFTER") |
| 36 | + |
| 37 | +echo "metric not_before string $NOT_BEFORE" |
| 38 | +echo "metric not_before_local string $NOT_BEFORE_LOCAL" |
| 39 | +echo "metric not_before_at uint64 $NOT_BEFORE_AT" |
| 40 | +echo "metric now uint64 $NOW" |
| 41 | +echo "metric not_after string $NOT_AFTER" |
| 42 | +echo "metric not_after_local string $NOT_AFTER_LOCAL" |
| 43 | +echo "metric not_after_at uint64 $NOT_AFTER_AT" |
| 44 | +exit 0 |
0 commit comments