zabbix监控域名到期时间
# 获取域名过期时间脚本
cat /etc/zabbix/scripts/base/check-http-expire.sh #!/bin/bash host=$1 #end_date=`whois -H $host|grep "Registry Expiry Date"|awk '{print $NF}'` end_date=`whois -H $host|egrep "Registry Expiry Date|Expiration Time"|awk '{print $3,$4}'|sed 's#Date: ##g'` #echo "$end_date" if [ -n "$end_date" ] then end_date_seconds=`date '+%s' --date "$end_date"` now_seconds=`date '+%s'` echo "($end_date_seconds-$now_seconds)/24/3600" | bc fi
# 域名自动发现脚本:
cat /etc/zabbix/scripts/base/http_discovery.py #!/usr/bin/env python #coding:utf-8 import os import sys import json #这个函数主要是构造出一个特定格式的字典,用于zabbix def ssl_cert_discovery(): web_list=[] web_dict={"data":None} with open("/etc/zabbix/scripts/base/http_list","r") as f: for sslcert in f: dict={} dict["{#DOMAINNAME}"]=sslcert.strip().split()[0] dict["{#PORT}"]=sslcert.strip().split()[1] dict["{#OLDNS}"]=sslcert.strip().split()[2] web_list.append(dict) web_dict["data"]=web_list jsonStr = json.dumps(web_dict,indent=4) return jsonStr if __name__ == "__main__": print ssl_cert_discovery()
# 域名列表
cat /etc/zabbix/scripts/base/http_list baidu.com 443 volunteer.dnspod.net.;jane.dnspod.net. jd.cn 443 jane.dnspod.net.;volunteer.dnspod.net.
# zabbix配置
cat /etc/zabbix/zabbix_agent2.d/userparameter_http.conf UserParameter=http_discovery,/usr/bin/python /etc/zabbix/scripts/base/http_discovery.py UserParameter=http.info[*],/bin/bash /etc/zabbix/scripts/base/check-http-expire.sh $1
# zabbix添加监控模版
zabbix_export: version: '5.2' date: '2024-06-04T07:31:05Z' groups: - name: Templates templates: - template: 'Template http expire date' name: 'Template http expire date' groups: - name: Templates applications: - name: 域名过期剩余时间 discovery_rules: - name: 域名到期_Discovery type: ZABBIX_ACTIVE key: http_discovery delay: 24h lifetime: '0' item_prototypes: - name: '[{#DOMAINNAME}]域名过期剩余时间:' type: ZABBIX_ACTIVE key: 'http.info[{#DOMAINNAME},{#PORT}]' delay: 3h history: 2d trends: 7d units: 天 applications: - name: 域名过期剩余时间 preprocessing: - type: MULTIPLIER parameters: - '1' trigger_prototypes: - expression: '{last()}<33' name: '[{#DOMAINNAME}] 域名过期剩余时间小于33天' priority: HIGH manual_close: 'YES'