Zabbix监控万物4--监控SSL证书有效期

背景

项目需要,需要监控所有的SSL证书的有效期,因此需要自定义一个监控项

实现

创建自定义脚本

在Zabbix的scripts目录(/etc/zabbix/scripts/)下创建一个新的shell脚本check_ssl.sh,内容如下

1
2
3
4
#!/bin/bash
time=$(echo | openssl s_client -connect $1:443 2>/dev/null | openssl x509 -noout -dates |awk -F'=' 'NR==2{print $2}')
times=$((($(date +%s -d "$time")-$(date +%s))/(60*60*24)))
echo $times

修改agent配置文件

1
UserParameter=check_ssl[*],/etc/zabbix/scripts/check_ssl.sh $1

在Zabbix console中配置

创建如下item
name值为SSL certification expire date of
key值为check_ssl[domain]
都需要填入自己要监控的domain

在latest data中即可看到具体的有效期