Skip to content

Commit

Permalink
merging version3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
zachhilbert committed Apr 9, 2017
2 parents 8bc7371 + 1145eff commit 2c91048
Show file tree
Hide file tree
Showing 34 changed files with 1,903 additions and 344 deletions.
63 changes: 63 additions & 0 deletions Monitors/DNSclient.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env python2
# requires: https://pypi.python.org/pypi/http-parser
from twisted.internet import reactor, protocol, ssl
from twisted.names import dns
from Jobs import Jobs
import sys


class DNSclient(object):

def __init__(self, job, timeout=30):
self.proto = dns.DNSDatagramProtocol(controller=None)
reactor.listenUDP(0, self.proto)
self.job = job
self.fqdn = self.job.get_hostname()
self.dnssvr = self.job.get_dns()[0]
self.timeout = timeout

def query(self):
#print "Querying %s for %s" % (self.dnssvr, self.fqdn)
self.d = self.proto.query((self.dnssvr, 53), [dns.Query(self.fqdn, dns.A)], timeout=self.timeout)
self.d.addCallback(self.getResults)
return self.d

def getResults(self, res):
if len(res.answers):
answer_str = '%s' % res.answers[0].payload
ip_addr = answer_str.split(" ")[1].split("=")[1]
self.job.set_ip(ip_addr)
# todo make this a proper debug statement
sys.stderr.write("Job %s: DNS lookup for %s gave %s\n" % \
(self.job.get_job_id(), res.answers[0].name, self.job.get_ip()))
else:
raise Exception("No results obtained")

def errorHandler(self, failure):
# Need to implement error handling
sys.stderr.write(str(failure))
pass



if __name__ == "__main__":
import sys
sys.stderr.write( "Testing %s\n" % sys.argv[0])
json_str1 = '{"pk": 120, "model": "scorebot.job", "fields": {"job_dns": ["10.100.101.60"], "job_host": {"host_services": [{"service_protocol": "tcp", "service_port": 80, "service_connect": "ERROR", "service_content": {}}], "host_ping_ratio": 50, "host_fqdn": "www.alpha.net"}}, "status": "job"}'
json_str2 = '{"pk": 120, "model": "scorebot.job", "fields": {"job_dns": ["10.100.101.60"], "job_host": {"host_services": [{"service_protocol": "tcp", "service_port": 80, "service_connect": "ERROR", "service_content": {}}], "host_ping_ratio": 50, "host_fqdn": "ftppub.alpha.net"}}, "status": "job"}'
json_str3 = '{"pk": 120, "model": "scorebot.job", "fields": {"job_dns": ["10.100.101.60"], "job_host": {"host_services": [{"service_protocol": "tcp", "service_port": 80, "service_connect": "ERROR", "service_content": {}}], "host_ping_ratio": 50, "host_fqdn": "mail.alpha.net"}}, "status": "job"}'
jobs_obj = Jobs()
jobs_obj.add(json_str1)
jobs_obj.add(json_str2)
jobs_obj.add(json_str3)
job = jobs_obj.get_job()
dnsobj = DNSclient(job)
query_defered = dnsobj.query()
job2 = jobs_obj.get_job()
dnsobj2 = DNSclient(job2)
query2_defered = dnsobj2.query()
job3 = jobs_obj.get_job()
dnsobj3 = DNSclient(job3)
query3_defered = dnsobj3.query()
reactor.callLater(5, reactor.stop)
reactor.run()
6 changes: 6 additions & 0 deletions Monitors/INSTALL.TXT
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Installation on an Arch Linux system

Requirements:
pacman -S python2 python2-pip openssl python2-pyopenssl
pip2 install twisted
pip2 install http_parser
Loading

0 comments on commit 2c91048

Please sign in to comment.