From 3d02b9c1544363c6bd8f3aa848766e3bbd642423 Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Wed, 23 Jan 2019 16:50:34 +0100 Subject: Seperate config from the python script Seperate the server calls in a config file. Small thrift call bugfix Small layout fixes --- bwLpStatus.py | 56 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 21 deletions(-) (limited to 'bwLpStatus.py') diff --git a/bwLpStatus.py b/bwLpStatus.py index d9c20c6..882ec1f 100755 --- a/bwLpStatus.py +++ b/bwLpStatus.py @@ -31,7 +31,7 @@ class Status: # Status of the check. (Online, Offline, Temporaily not available, Some services unavailable, ...) <-- This text is shown on the website self.status = status - # Type of the service. (ping, https, http, mysql, ...) + # Type of the service. (ping, https, tftp, thrift, ...) self.service = service # Message e.g. error message @@ -124,19 +124,22 @@ def thrift(name, ip, port, server): organisations = [] # Different clients for SAT / Master is needed. try: - if server is 'SAT': + if server == 'SAT': satserver = make_client(bwlp_thrift.SatelliteServer, ip, port, trans_factory=TFramedTransportFactory()) organisations = satserver.getAllOrganizations() - elif server is 'MASTER': + elif server == 'MASTER': masterserver = make_client(bwlp_thrift.MasterServer, ip, port, trans_factory=TFramedTransportFactory()) organisations = masterserver.getOrganizations() - + print(organisations) organisationList = [] for org in organisations: organisationList.append(Organisation(org.organizationId, org.displayName)) - statusList.append(Status(name, host, 'success', 'Online (' + str(len(organisationList)) + ')', 'thrift', msg=str(len(organisationList)) + " organizations",data=organisationList)) + if len(organisationList) == 0: + statusList.append(Status(name, host, 'warning', 'Online (' + str(len(organisationList)) + ')', 'thrift', msg=str(len(organisationList)) + " organizations found",data=organisationList)) + else: + statusList.append(Status(name, host, 'success', 'Online (' + str(len(organisationList)) + ')', 'thrift', msg=str(len(organisationList)) + " organizations found",data=organisationList)) print('\033[92m' + 'success' + '\033[0m') except ConnectionResetError: statusList.append(Status(name, host, 'error', 'Offline', 'thrift', msg="ConnectionResetError: [Errno 104] Connection reset by peer")) @@ -177,26 +180,37 @@ def logStatus(status): date = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') logEntries.append(LogEntry(date, status.service, status.state, status.host, status.msg, status.data)) +# Reads the config and executes the calls. +def readConfig(): + if not (os.path.exists('bwlp.config')): + return + with open('bwlp.config', 'r') as config: + for line in config: + line = line.strip() + entry = line.split('\t') + if entry[0] == '#': continue + check(entry) + +# Calls the check method. +def check(entry): + if entry[0] == 'ping': + if (len(entry) < 3): return + ping(entry[1], entry[2]) + elif entry[0] == 'https': + if (len(entry) < 3): return + https(entry[1], entry[2]) + elif entry[0] == 'thrift': + if (len(entry) < 5): return + thrift(entry[1], entry[2], int(entry[3]), entry[4]) + elif entry[0] == 'tftp': + if (len(entry) < 5): return + tftp(entry[1], entry[2], int(entry[3]), entry[4]) + # Parse the logfile. parseLog() # Call the checks. -https('Masterserver HTTPS Service', 'https://bwlp-masterserver.ruf.uni-freiburg.de') -https('Fail Test', '5121236') -https('Fail Test', 'https://www.amazony.de/') -ping('Masterserver IP Ping', '132.230.4.16') -ping('Fileserver Ping', 'files.bwlp.ks.uni-freiburg.de') -ping('Backup fileserver Ping', 'bwlp-backup.ruf.uni-freiburg.de') -ping('Ping Fail', '0.0.0.1') -thrift('Thrift SAT', '132.230.8.192', 9090, 'SAT') -thrift('Thrift MASTER', '132.230.4.16', 9090, 'MASTER') -thrift('Thrift MASTER', '132.230.4.16', 9091, 'MASTER') -ping('BAS Ping', 'bas.intra.uni-freiburg.de') -ping('yc', '127.0.0.2') -ping('yx', '127.0.0.3') -tftp('TFTP bwlp lpxelinux', 'bwlp-pxe.ruf.uni-freiburg.de', 69, 'lpxelinux.0') -tftp('TFTP bas ipxe', 'bas.intra.uni-freiburg.de', 69, 'ipxe.0') -tftp('TFTP bas fail test', 'bas.intra.uni-freiburg.de', 69, 'failtest.0') +readConfig() # Write the new logfile. writeLog() -- cgit v1.2.3-55-g7522