码迷,mamicode.com
首页 > 其他好文 > 详细

检测证书过期并发送钉钉告警

时间:2021-06-30 18:14:38      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:one   ESS   mob   over   check   while   cti   timestamp   day   


#!/usr/bin/env bash
__Author__="liy"

# 发送钉钉告警
function DingDing(){
    curl ‘https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx‘     -H ‘Content-Type: application/json‘     -d ‘{"msgtype": "text",
        "text": {
        "content":" ‘$1‘ "
        },
        "at": {
        "atMobiles": [
            "1xxxxxxxxxx",
        ],
        "isAtAll": false
        }
        }‘
}

function checkCerts(){
    host=$1

    SSL_OVER_TIMESTAMP=$(date +%s -d "$(openssl s_client -servername ${host} -connect ${host}:443 2>/dev/null | openssl x509 -noout -dates|grep -Po "(?<=After=).*(?=GMT)")")
    NOW_TIMESTAMP=$(date +%s)
    OVER_TIMESTAMP=$(echo ${SSL_OVER_TIMESTAMP} - ${NOW_TIMESTAMP} | bc)
    OVER_DAYS=$(echo ${OVER_TIMESTAMP} / 86400 | bc)

    if [ $OVER_DAYS -le 30 ];then
        text="${host}的证书将于${OVER_DAYS}天后过期,注意续费和配置更新!\n报警源:192.168.171.201"
        DingDing ${text}
    fi
}

function main(){
    while read line
    do
        checkCerts $line
    done < ssl.list
}

main

检测证书过期并发送钉钉告警

标签:one   ESS   mob   over   check   while   cti   timestamp   day   

原文地址:https://www.cnblogs.com/liy36/p/14952901.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!