Fix DF check
This commit is contained in:
parent
7651c35cf7
commit
cb17e8adae
3 changed files with 76 additions and 12 deletions
|
@ -12,6 +12,7 @@ our new monitoring system that does not suck.
|
|||
- history support -> possible grafana interface
|
||||
- easy to create and extend checks
|
||||
- Requirements: python3 + binaries for certain checks
|
||||
- Minimal core logic - checks can check "anything"
|
||||
|
||||
### Planned features (game)
|
||||
|
||||
|
|
25
check-cli.py
25
check-cli.py
|
@ -2,7 +2,14 @@
|
|||
|
||||
import check
|
||||
|
||||
import argparse
|
||||
import logging
|
||||
|
||||
logging.basicConfig()
|
||||
log = logging.getLogger(None)
|
||||
|
||||
|
||||
def do_checks():
|
||||
checks = []
|
||||
|
||||
checks.append(check.DNSCheck("www.ungleich.ch"))
|
||||
|
@ -13,7 +20,25 @@ for num_server in range(1,6):
|
|||
server="d{}.ungleich.ch".format(num_server)
|
||||
|
||||
checks.append(check.DNSCheck("www.ungleich.ch", server=server))
|
||||
checks.append(check.DFCheck(server))
|
||||
|
||||
|
||||
for c in checks:
|
||||
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()
|
||||
|
|
38
check.py
38
check.py
|
@ -1,4 +1,8 @@
|
|||
import subprocess
|
||||
import logging
|
||||
|
||||
logging.basicConfig()
|
||||
log = logging.getLogger("checks")
|
||||
|
||||
class CheckException(Exception):
|
||||
pass
|
||||
|
@ -82,3 +86,37 @@ class DNSCheck(BaseCheck):
|
|||
name = "{}@{}".format(name, self.server)
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue