Fix DF check

This commit is contained in:
Nico Schottelius 2019-04-14 20:30:04 +02:00
parent 7651c35cf7
commit cb17e8adae
3 changed files with 76 additions and 12 deletions

View file

@ -12,6 +12,7 @@ our new monitoring system that does not suck.
- history support -> possible grafana interface - history support -> possible grafana interface
- easy to create and extend checks - easy to create and extend checks
- Requirements: python3 + binaries for certain checks - Requirements: python3 + binaries for certain checks
- Minimal core logic - checks can check "anything"
### Planned features (game) ### Planned features (game)

View file

@ -2,18 +2,43 @@
import check import check
import argparse
import logging
checks = [] logging.basicConfig()
log = logging.getLogger(None)
checks.append(check.DNSCheck("www.ungleich.ch"))
checks.append(check.DNSCheck("www.ungleich.ch", expected_result="2a0a:e5c0:0:2:400:b3ff:fe39:795c"))
checks.append(check.DNSCheck("www.ungleich.ch", rr_type="A", expected_result="185.203.112.17"))
for num_server in range(1,6): def do_checks():
checks = []
checks.append(check.DNSCheck("www.ungleich.ch"))
checks.append(check.DNSCheck("www.ungleich.ch", expected_result="2a0a:e5c0:0:2:400:b3ff:fe39:795c"))
checks.append(check.DNSCheck("www.ungleich.ch", rr_type="A", expected_result="185.203.112.17"))
for num_server in range(1,6):
server="d{}.ungleich.ch".format(num_server) server="d{}.ungleich.ch".format(num_server)
checks.append(check.DNSCheck("www.ungleich.ch", server=server)) checks.append(check.DNSCheck("www.ungleich.ch", server=server))
checks.append(check.DFCheck(server))
for c in checks: for c in checks:
print("{} {}".format(c, c.check())) print("{} {}".format(c, c.check()))
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='checks')
parser.add_argument('--debug', help='Enable debug logging', action='store_true')
parser.add_argument('--verbose', help='Enable verbose logging', action='store_true')
args = parser.parse_args()
if args.debug:
log.setLevel(logging.DEBUG)
print("dbg")
elif args.verbose:
log.setLevel(logging.INFO)
else:
log.setLevel(logging.WARNING)
do_checks()

View file

@ -1,4 +1,8 @@
import subprocess import subprocess
import logging
logging.basicConfig()
log = logging.getLogger("checks")
class CheckException(Exception): class CheckException(Exception):
pass pass
@ -82,3 +86,37 @@ class DNSCheck(BaseCheck):
name = "{}@{}".format(name, self.server) name = "{}@{}".format(name, self.server)
return name return name
class DFCheck(BaseCheck):
def __init__(self, name, username="root", path="/"):
self.name = name
self.username = username
self.path = path
self.command = self.create_command()
log.info("Command = {}".format(self.command))
def create_command(self):
base_command ='ssh {}@{}'.format(self.username, self.name).split()
base_command.append("df {}".format(self.path))
return base_command
def check(self):
res = subprocess.run(self.command,
capture_output=True,
encoding="utf-8")
if not res.returncode == 0:
return (False, "")
return (True, res.stdout)
def __repr__(self):
return "<df {}>".format(self.__str__())
def __str__(self):
name = "{}:{}".format(self.name, self.path)
return name