shell脚本之证书到期监控和企微告警
shell脚本之证书到期监控和企微告警
shell脚本实现ssl证书过期及webhook推送,实战运维脚本。也实现基于fastapi接口方式检查域名证书有需要下次展示。
脚本
https.sh
检测和告警脚本, https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxxxxxxxxxxx替换为自己企微的webhook地址即可
#!/bin/bash #**************************************************************************************** #Author: wei #*************************************************************************************** #!/bin/bash # 检测https证书有效期 source /etc/profile while read line; do end_time=$(echo | timeout 1 openssl s_client -servername $line -connect $line:443 2>/dev/null | openssl x509 -noout -enddate 2> /dev/null | awk -F '=' '{print $2}') end_times=$(date -d "$end_time" +%s) current_times=$(date -d "$(date -u '+%b %d %T %Y GMT')" +%s) echo $end_times $current_times &> /dev/null let left_time="$end_times - $current_times" days=$(expr $left_time / 86400) #echo "$line 剩余天数: ${days}" #[[ ${days} -lt 30 ]] && echo "https ssl cert 少于 30 days" || echo "${line} 剩余时间是 $days" if [[ ${days} -eq 0 ]];then echo "$line DNS解析异常" elif [[ "${days}" -lt 0 ]];then echo "$line 证书已过期" elif [[ "${days}" -lt 40 ]];then echo "$line 剩余天数: ${days}" curl -X POST -H "Content-Type: application/json" \ -d '{"msgtype": "text", "text": {"content": "'$line' 证书过期剩余天数: '$days' , 请及时更换!!"}}' \ https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxxxxxxxxxxx elif [[ "${days}" -lt 4 ]];then echo "$line 剩余天数: ${days}" curl -X POST -H "Content-Type: application/json" \ -d '{"msgtype": "text", "text": {"content": "'$line' 证书过期剩余天数: '$days' , 请持续观察和验证证书!!"}}' \ https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=xxxxxxxxxxxxx fi done < ./https_list
https_list
检查域名证书列表文件
api.wqyfchina.com
k8s.wqyfchina.com
api.wqyfchina.com
执行告警
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· CSnakes vs Python.NET:高效嵌入与灵活互通的跨语言方案对比
· DeepSeek “源神”启动!「GitHub 热点速览」
· 我与微信审核的“相爱相杀”看个人小程序副业
· Plotly.NET 一个为 .NET 打造的强大开源交互式图表库
· 上周热点回顾(2.17-2.23)
2020-06-06 压缩和解压缩、打包和解包