1、编写监控脚本。
# vim check_ssl_expiry.sh#!/bin/bashSTATE_OK=0STATE_WARNING=1STATE_CRITICAL=2Host=$1end_date=$(echo | openssl s_client -connect $Host:443 2>/dev/null -servername $Host | openssl x509 -noout -dates | sed -n 's/notAfter=//p' | sed -n 's/ GMT//p')if [ -n "$end_date" ];then end_date_seconds=$(date +%s -d "$end_date") now_seconds=$(date +%s) valid_days=$[($end_date_seconds-$now_seconds)/24/3600]fiif [ $valid_days -lt 60 ];then echo "WARNING: SSL cert of $Host will be expired after $valid_days days." exit $STATE_WARNINGelif [ $valid_days -lt 30 ];then echo "CRITICAL: SSL cert of $Host will be expired after $valid_days days." exit $STATE_CRITICALelse echo "OK: SSL cert of $Host will be expired after $valid_days days." exit $STATE_OKfi
2、添加command配置。
# vim command.cfg#check_ssl_expiry command definitiondefine command { command_name check_ssl_expiry command_line /usr/lib/nagios/plugins/check_ssl_expiry $ARG1$}
3、定义监控项service。
# vim ssl.cfgdefine service{ use oupeng-svc contact_groups group-sa service_description check_ssl_www.opgirl.cn check_command check_ssl_expiry!www.opgirl.cn}
4、重载配置。
# /etc/init.d/nagios reload
联系客服