k8s的证书过期监控脚本


k8s中的证书zabbix监控脚本

脚本

参考ssl证书的监控脚本,进行修改

# cat userparameter_script/ssl_check_for_k8s.sh 
#!/bin/bash


K8S_CERTS_DIR="/etc/kubernetes/pki"
K8S_CERT_FILENAME=$1

end_date="$(openssl x509 -in ${K8S_CERTS_DIR}/${K8S_CERT_FILENAME} -enddate -noout 2>/dev/null | sed -e 's/^.*\=//')"

if [ -n "$end_date" ]
then
end_date_seconds=$(date "+%s" --date "$end_date")
now_seconds=$(date "+%s")
CALC=$((($end_date_seconds-$now_seconds)/24/3600))
echo $CALC
else
echo -1
exit 124
fi

agent中的监控项配置

# cat etc/zabbix_agentd.conf.d/userparameter_certs_k8s.conf 
UserParameter=k8s_certs_status[*],/webser/zabbix/userparameter_script/ssl_check_for_k8s.sh $1

zabbix中模板配置

模板名称Template k8s ssl check。