zabbix 监控openssl证书过期时间

生产环境如果域名绑定的ssl证书过期的话,整个入口都无法访问,会严重影响业务,所以,我们需要对ssl证书的过期时间进行监控。

获取证书过期时间

可以通过如下两个命令获取: 其中$1为目标网站的地址。

1、curl

nohup curl -Ivs https://$1 --connect-timeout 10 2>&1 >>test.log
expdate=$(grep "expire date" test.log |awk -F': ' '{print $2}')
expunix=$(date +%s -d "$expdate")
today=$(date +%s)
expday=$((expunix-today)/(86400))

2、OpenSSL

expdate=$( echo | openssl s_client  -connect  $1:443 2>/dev/null | openssl x509 -noout -dates |awk -F'=' 'NR==2{print $2}')
expunix=$(date +%s -d "$expdate")
today=$(date +%s)
expday=$((expunix-today)/(86400))

zabbix添加监控

如上两种脚本可以获取到还有几天证书过期,我们可以在zabbix上添加相应的监控项。

假设脚本名称为ssl_check.sh
在zabbix的配置文件中新增自定义监控项:
UserParameter=ssl_check.str[*],/opt/zabbix/script/ssl_check.sh '$1'

在页面上添加监控项,将域名作为参数传入。更新间隔为1天即可。
在这里插入图片描述

发布了48 篇原创文章 · 获赞 31 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/weixin_44723434/article/details/90176582