zabbix监控域名到期时间

版权声明:如需转载,请注明作者及出处 https://blog.csdn.net/qq_33317586/article/details/83902490

一、自定义监控项

先看下这个zabbix_agent.conf文件是否有子配置目录

root@david:/etc/zabbix# grep Include zabbix_agentd.conf 
### Option: Include
# Include=
Include=/etc/zabbix/zabbix_agentd.d/*.conf
# Include=/usr/local/etc/zabbix_agentd.userparams.conf
# Include=/usr/local/etc/zabbix_agentd.conf.d/
# Include=/usr/local/etc/zabbix_agentd.conf.d/*.conf

子配置目录为/etc/zabbix/zabbix_agentd.d/

在里面创建个监控项

root@david:/etc/zabbix# cd zabbix_agentd.d/
root@david:/etc/zabbix/zabbix_agentd.d# vim domain_certificate_check.conf
root@david:/etc/zabbix/zabbix_agentd.d# cat domain_certificate_check.conf 
UserParameter=https.remaining[*],/etc/zabbix/scripts/domain_certificate_check.sh $1

二、编写脚本

俗话说:君子性非异也。不会写还不会抄啊233

root@david:/etc/zabbix/zabbix_agentd.d# mkdir -p /etc/zabbix/scripts
root@david:/etc/zabbix/zabbix_agentd.d# cd /etc/zabbix/scripts/
root@david:/etc/zabbix/scripts# vim domain_certificate_check.sh
root@david:/etc/zabbix/scripts# cat domain_certificate_check.sh 
#/bin/bash
host=$1
port=443
end_date=`openssl s_client -host $host -port $port -showcerts </dev/null 2>/dev/null |
	sed -n '/BEGIN CERTIFICATE/,/END CERT/p' |
	openssl x509 -text 2>/dev/null |
	sed -n 's/ *Not After : *//p'`
if [ -n "$end_date" ]
then
	end_date_seconds=`date '+%s' --date "$end_date"`
	# date指令format字符串时间。
	now_seconds=`date '+%s'`
	echo "($end_date_seconds-$now_seconds)/24/3600" | bc
fi

三、重启zabbix_agent

root@david:/etc/zabbix/scripts# systemctl restart zabbix-agent.service

四、zabbix_server端测试

我这个zabbix_server和zabbix_agent在同一台机器上

安装zabbix-get

root@david:~# apt install zabbix-get

测试,提示权限拒绝

root@david:~# zabbix_get -s 127.0.0.1 -p10050 -k https.remaining[www.jd.com]
sh: 1: /etc/zabbix/scripts/domain_certificate_check.sh: Permission denied

给脚本赋予执行权限

root@david:~# chmod 755 /etc/zabbix/scripts/domain_certificate_check.sh

再次测试:

root@david:~# zabbix_get -s 127.0.0.1 -p10050 -k https.remaining[www.jd.com]
322
root@david:~# zabbix_get -s 127.0.0.1 -p10050 -k https.remaining[test.yiziruwo.cn]
89
root@david:~# zabbix_get -s 127.0.0.1 -p10050 -k https.remaining[www.yiziruwo.cn]
341
root@david:~# zabbix_get -s 127.0.0.1 -p10050 -k https.remaining[www.taobao.com]
12
root@david:~# zabbix_get -s 127.0.0.1 -p10050 -k https.remaining[www.jd.com]
322
root@david:~# zabbix_get -s 127.0.0.1 -p10050 -k https.remaining[www.taobao.com]
12
root@david:~# zabbix_get -s 127.0.0.1 -p10050 -k https.remaining[www.360.cn]
387
root@david:~# zabbix_get -s 127.0.0.1 -p10050 -k https.remaining[www.163.com]
340

淘宝的证书还有12天过期?让我看下

五、zabbix的web界面添加监控项

正好监控淘宝的证书一波

六、创建触发器

七、把这个模版应用到zabbix_server机器上

默认就有

八、看一下是否有报警

过了一会儿,迎来了报警

猜你喜欢

转载自blog.csdn.net/qq_33317586/article/details/83902490