diff options
author | Christian Hesse <mail@eworm.de> | 2019-01-09 10:38:41 +0100 |
---|---|---|
committer | Christian Hesse <mail@eworm.de> | 2019-01-09 10:38:41 +0100 |
commit | 5539233417e0bcf9f2c16b12bf25ba5afc13020a (patch) | |
tree | d79795e4188ff268f2e2e82929113cbf054e5a52 /check-certificates | |
parent | 6b6c3d5119b8e5b81563fbc2b7460611b212c11d (diff) |
check-certificates: send notification on renewal
Diffstat (limited to 'check-certificates')
-rw-r--r-- | check-certificates | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/check-certificates b/check-certificates index 41d35cd..24e0559 100644 --- a/check-certificates +++ b/check-certificates @@ -22,12 +22,13 @@ :foreach Cert in=[ / certificate find where !revoked ] do={ :local CertName [ / certificate get $Cert name ]; - :local InvalidDate [ / certificate get $Cert invalid-after ]; + :local InvalidBefore [ / certificate get $Cert invalid-before ]; + :local InvalidAfter [ / certificate get $Cert invalid-after ]; - :if ([ :len $InvalidDate ] > 0) do={ - :local InvalidDay [ :pick $InvalidDate 4 6 ]; - :local InvalidYear [ :pick $InvalidDate 7 11 ]; - :local InvalidMonth ([ :find $Months [ :pick $InvalidDate 0 3 ] ] + 1); + :if ([ :len $InvalidAfter ] > 0) do={ + :local InvalidDay [ :pick $InvalidAfter 4 6 ]; + :local InvalidYear [ :pick $InvalidAfter 7 11 ]; + :local InvalidMonth ([ :find $Months [ :pick $InvalidAfter 0 3 ] ] + 1); :local InvalidStamp ($InvalidYear * 365 + $InvalidMonth * 30 + $InvalidDay); :local Remaining ($InvalidStamp - $CurrentStamp); @@ -62,10 +63,19 @@ / certificate remove $Cert; / certificate set $CertNew name=$CertName; - } on-error={ - :local InvalidBefore [ / certificate get $Cert invalid-before ]; - :local InvalidAfter [ / certificate get $Cert invalid-after ]; + :set InvalidBefore [ / certificate get $CertNew invalid-before ]; + :set InvalidAfter [ / certificate get $CertNew invalid-after ]; + :set FingerPrint [ / certificate get $CertNew fingerprint ]; + + $SendNotification ("Certificate renewed") \ + ("A certificate on " . $Identity . " has been renewed.\n\n" . \ + "Certificate Name: " . $CertName . "\n" . \ + "Common Name: " . $CommonName . "\n" . \ + "Fingerprint: " . $FingerPrint . "\n" . \ + "Validity: " . $InvalidBefore . " to " . $InvalidAfter); + :log info ("The certificate " . $CertName . " has been renewed."); + } on-error={ $SendNotification ("Certificate warning!") \ ("A certificate on " . $Identity . " is about to expire.\n\n" . \ "Certificate Name: " . $CertName . "\n" . \ |