動作未検証
そのうちやる
#!/bin/bash
DOMAIN='example.com'
SLACK_INCOMING_HOOK='https://hooks.slack.com/services/{hook_id}'
CERTBOT_AUTO='/usr/bin/certbot-auto'
POST_HOOK='sudo /opt/bitnami/ctlscript.sh restart apache'
EXPIRATION=`openssl s_client -connect ${DOMAIN}:443 < /dev/null 2> /dev/null | openssl x509 -text | grep Not | grep -v Before | awk '/Not After : / {print $4, $5, $6, $7, $8}'`
curl -X POST -H 'Content-type: application/json' --data "{'attachments':[{'title':'Start:${DOMAIN} 期限:${EXPIRATION}', 'color':'#0000FF'}]}" ${SLACK_INCOMING_HOOK}
sudo ${CERTBOT_AUTO} renew --post-hook ${POST_HOOK}
if [ $? -eq 0 ] ;then
curl -X POST -H 'Content-type: application/json' --data "{'attachments':[{'title':'Success:${DOMAIN}', 'color':'#00FF00'}]}" ${SLACK_INCOMING_HOOK}
else
curl -X POST -H 'Content-type: application/json' --data "{'attachments':[{'title':'Failed:${DOMAIN}', 'color':'#FF0000'}]}" ${SLACK_INCOMING_HOOK}
fi