-
Notifications
You must be signed in to change notification settings - Fork 9
/
zabbix-whois-check.py
35 lines (29 loc) · 1.1 KB
/
zabbix-whois-check.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python3
# checks when a domain is going to expire
# and sends the time to zabbix
# new version that reads from a json file
import sys
import os
import json
import whois
from pyzabbix import ZabbixMetric, ZabbixSender
wwwhost = sys.argv[1]
dir_path = os.path.dirname(os.path.realpath(__file__))
with open(dir_path+'/whois/'+wwwhost+'.json', 'r') as read_file:
domains = json.load(read_file)
for domain in domains['domains']:
try:
w = whois.whois(domain)
if isinstance(w.expiration_date, list):
packet = ZabbixMetric(wwwhost, 'domain.expiry['+domain+']', w.expiration_date[0].timestamp()),
else:
if w.expiration_date:
packet = ZabbixMetric(wwwhost, 'domain.expiry['+domain+']', w.expiration_date.timestamp()),
result = ZabbixSender(use_config=True).send(packet)
except:
print("Error occurred while executing whois() for %s." % domain)
## some tests
#print(w)
#print(w.domain_name, w.expiration_date)
#print(packet)
#print(result)