+begin check

This commit is contained in:
Nico Schottelius 2019-04-14 19:13:22 +02:00
parent b5a6f0a94f
commit c533f9e02b
2 changed files with 54 additions and 0 deletions

View file

@ -5,3 +5,12 @@ ungleich register --name your-user-name --email your@email
ungleich play-game --game register --ip ungleich play-game --game register --ip
ungleich play-game --game dns-forward --ip ungleich play-game --game dns-forward --ip
## Documentation
- Rais CheckExc
## TODOs
- last result: select checkname where result = true
- last success: select checkname where result = true

45
check.py Normal file
View file

@ -0,0 +1,45 @@
class CheckException(Exception):
pass
class WrongParameterException(CheckException):
pass
class BaseCheck(object):
def check(self):
""" Should return tuple:
(true/false, data)
data is the raw result and can be saved in a database
"""
pass
class DNSCheck(BaseCheck):
def __init__(self, name, rr_type="AAAA", server=None):
self.rr_types = [ "AAAA", "A", "PTR", "TXT" ]
self.name = name
self.rr_type = rr_type
self.server = server
if not self.rr_type in self.rr_types:
raise WrongParameterException("Unsupported rr_type: {}".format(self.rr_type))
def rr_type_to_command(self):
base_cmd="dig +short"
if self.rr_type == "AAAA":
command = "{} {} aaaa".format(base_cmd, self.name)
elif self.rr_type == "A":
command = "{} {} a".format(base_cmd, self.name)
elif self.rr_type == "PTR":
command = "-x {}".format(base_cmd, self.name)
elif self.rr_type == "TXT":
command = "{} {} aaaa".format(base_cmd, self.name)
def check(self):