柚子快报邀请码778899分享:zabbix 监控域名到期时间
cat 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
cat /etc/zabbix/scripts/base/http_list
baidu.com 443
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/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
模板
Template http expire date
柚子快报邀请码778899分享:zabbix 监控域名到期时间
发表评论