Last active
August 26, 2016 06:08
-
-
Save kenzo0107/35fcc7df045d98aa9bd781daf6345320 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# SSL証明書の有効期限を確認したいドメイン一覧 | |
DOMAIN_LIST="www.jugemjugem.jp | |
gokono-surikire.jp | |
www.kaijarisuigyo.co.jp | |
blog.suigyomatsu.com | |
blog.unraimatsu.com | |
blog.furaimatsu.com" | |
# Slack Channel & Webhook URL | |
CHANNEL="#general" | |
WEBHOOKURL="https://hooks.slack.com/services/123456789/xxxxxxxx/yyyyyyyyyyzzzzzzzzzzzz" | |
# 現在時刻 | |
nowS=$(date "+%s") | |
# SSLの有効期限日を JST で取得 | |
function ssl_cert_limit() { | |
d=$1 | |
limit_date_gmt=$(openssl s_client -connect $d:443 < /dev/null 2> /dev/null | openssl x509 -text | grep 'Not After' | awk -F'Not After :' '{print $2}') | |
limit_date_jst=$(date +%s --date "$limit_date_gmt" | awk '{print strftime("%Y/%m/%d %H:%M:%S", $1)}') | |
echo $limit_date_jst | |
} | |
# 残り日数取得 | |
function remain_days() { | |
targetS=$(date -d "$1" '+%s') | |
r=$(expr "$targetS" - "$nowS") | |
r=$(expr $r / 86400 + 1) | |
echo $r | |
} | |
#Slackに通知 | |
function slack () { | |
MESSAGE="$1" | |
BOTNAME="Jenkins" | |
curl -s -S -X POST -d "payload={\"channel\": \"${CHANNEL}\", \"username\": \"${BOTNAME}\", \"text\": \"${MESSAGE}\" }" ${WEBHOOKURL} >/dev/null | |
} | |
msg=":loudspeaker: *SSL証明書有効期限* :loudspeaker:" | |
for d in $DOMAIN_LIST | |
do | |
limit_date=$(ssl_cert_limit $d) | |
remain_days=$(remain_days "$limit_date") | |
alert="" | |
if [ $remain_days -le 60 ]; then | |
alert=" | |
> :information_desk_person:残り60日を切りました! 更新手続きにお時間を要する場合はお早めにお願いします。:information_desk_person:" | |
elif [ $remain_days -le 31 ]; then | |
alert=" | |
> :bow:残り31日を切りました:bangbang:更新手続きお願いします:bow:" | |
fi | |
msg=$msg" | |
*$d* | |
> $limit_date | |
> 残り $remain_days 日 $alert" | |
done | |
slack "$msg" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment