diff --git a/whois/example.host.name.json b/whois/example.host.name.json new file mode 100644 index 0000000..b754055 --- /dev/null +++ b/whois/example.host.name.json @@ -0,0 +1,7 @@ +{ + "domains": [ + "example.com", + "example.org", + "example.net" + ] +} diff --git a/zabbix-whois-check.py b/zabbix-whois-check.py new file mode 100644 index 0000000..f8f7e36 --- /dev/null +++ b/zabbix-whois-check.py @@ -0,0 +1,31 @@ +#!/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']: + w = whois.whois(domain) + if isinstance(w.expiration_date, list): + packet = ZabbixMetric(wwwhost, 'domain.expiry['+domain+']', w.expiration_date[0].timestamp()), + else: + packet = ZabbixMetric(wwwhost, 'domain.expiry['+domain+']', w.expiration_date.timestamp()), + result = ZabbixSender(use_config=True).send(packet) + + ## some tests + #print(w) + #print(w.domain_name, w.expiration_date) + #print(packet) + #print(result) diff --git a/zabbix-whois-discovery.py b/zabbix-whois-discovery.py new file mode 100644 index 0000000..2eb6531 --- /dev/null +++ b/zabbix-whois-discovery.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 + +# read domains from a json array +# and feed them into zabbix + +import sys +import os +import json +from pyzabbix import ZabbixMetric, ZabbixSender + +wwwhost = sys.argv[1] +asdf = '' +idx = 0 +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 idx, thing in enumerate(domains['domains']): + if idx == 0: + asdf += '{"{#WHOISDOMAIN}":"'+thing+'"}' + else: + asdf += ',{"{#WHOISDOMAIN}":"'+thing+'"}' + +done = '{"data":['+asdf+']}' + + +packet = ZabbixMetric(wwwhost, 'domain.expiry.item', done), +result = ZabbixSender(use_config=True).send(packet) + +## some tests +#print(done) +#print(packet) +#print(result) + +## another test +#f = open('/tmp/zabbix-whois.txt', 'w') +#f.write(done) +#f.close() diff --git a/zabbix-whois-template.xml b/zabbix-whois-template.xml new file mode 100644 index 0000000..a38ac48 --- /dev/null +++ b/zabbix-whois-template.xml @@ -0,0 +1,131 @@ + + + 3.4 + 2018-06-04T11:01:41Z + + + Templates + + + + + +