Skip to content

Instantly share code, notes, and snippets.

@Salamafet
Created August 30, 2022 12:26
Show Gist options
  • Save Salamafet/d04135ec2eb73135672e564eeb2bdf8d to your computer and use it in GitHub Desktop.
Save Salamafet/d04135ec2eb73135672e564eeb2bdf8d to your computer and use it in GitHub Desktop.
Gotify notification when certificate expire
#!/bin/bash
certificat=/usr/certificate/example.com/cert.pem
gotify_url="https://push.example.com/message?token=xxxxx"
gotify_title="Synology Certificate Expiry"
function check_certificat () {
if openssl x509 -checkend $((${1}*86400)) -noout -in $certificat; then
return 1
else
return 0
fi
}
function notification () {
curl $gotify_url -F "title=${gotify_title}" -F "message=${1}"
}
# Certificate already expired
if check_certificat 0; then
notification "Certificate expired"
# 1 day remaining
elif check_certificat 1; then
notification "Less than 24 hours remaining before expiration of the certificate"
# 2 days remaining
elif check_certificat 2; then
notification "2 days remaining before expiration of the certificate"
# 5 days remaining
elif check_certificat 5; then
notification "5 days remaining before expiration of the certificate"
# 10 days remaining
elif check_certificat 10; then
notification "10 days remaining before expiration of the certificate"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment