summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.txt1
-rwxr-xr-xbwLpStatus.py47
2 files changed, 23 insertions, 25 deletions
diff --git a/README.txt b/README.txt
index 9b7489f..911335a 100644
--- a/README.txt
+++ b/README.txt
@@ -1,5 +1,6 @@
Python modules needed:
pip3 install thriftpy
+pip3 install tftpy
bwlp.thrift needed:
wget http://git.openslx.org/bwlp/master-sync-shared.git/plain/src/main/thrift/bwlp.thrift
diff --git a/bwLpStatus.py b/bwLpStatus.py
index fbe5e09..076f879 100755
--- a/bwLpStatus.py
+++ b/bwLpStatus.py
@@ -2,13 +2,14 @@
import subprocess
import urllib.request
import urllib.error
-# import mysql.connector
import thriftpy
from thriftpy.rpc import make_client
from thriftpy.transport import TFramedTransportFactory
import shutil
import datetime
import os
+import tftpy
+import logging
# Global variables
statusList = []
@@ -66,7 +67,6 @@ def ping(name, hostname):
stderr=subprocess.PIPE
)
response = response.communicate()
- # output = response[0].decode('utf-8')
error = response[1].decode('utf-8')
# Error happend
@@ -99,23 +99,23 @@ def https(name, url):
finally:
logStatus(statusList[-1])
-def mysql(self, host, user, passwd, db):
- pass
- # TODO: Backend to check the mysql status needs to be implemented.
- # print('MYSQL request start ...')
- # db = mysql.connector.connect(
- # host='localhost',
- # user='openslx',
- # passwd='geheim',
- # database='openslx'
- # )
- # cursor = db.cursor()
- # cursor.execute('SELECT * FROM user')
- # result = cursor.fetchall()
- # for user in result:
- # print(user[1])
-
-# Creates the thrift client and proceeds the get Organisations call. Server can either be SAT or MASTER
+def tftp(name, host, port, filename):
+ print('TFTP request ' + host + ' ...', end='')
+ hostname = host + ':' + str(port)
+ try:
+ client = tftpy.TftpClient(host, port)
+ client.download(filename, 'tmp_tftp_file')
+ print('\033[92m' + 'success' + '\033[0m')
+ # Delete tmp tftp file
+ os.remove('tmp_tftp_file')
+ statusList.append(Status(name, hostname, 'success', 'Online', 'tftp', msg='File ' + filename + ' downloaded successfully.'))
+ except Exception as e:
+ print('\033[91m' + 'error' + '\033[0m')
+ statusList.append(Status(name, hostname, 'error', 'Offline', 'tftp', msg=str(e)))
+ finally:
+ logStatus(statusList[-1])
+
+# Creates the thrift client and prwlp-pxe.ruf.uni-freiburg.de .ceeds the get Organisations call. Server can either be SAT or MASTER
def thrift(name, ip, port, server):
host = ip + ':' + str(port)
print('THRIFT request ' + host + ' ...', end='')
@@ -123,7 +123,6 @@ def thrift(name, ip, port, server):
organisations = []
# Different clients for SAT / Master is needed.
- # TODO: TRY CATCH
try:
if server is 'SAT':
satserver = make_client(bwlp_thrift.SatelliteServer, ip, port, trans_factory=TFramedTransportFactory())
@@ -139,11 +138,9 @@ def thrift(name, ip, port, server):
statusList.append(Status(name, host, 'success', 'Online (' + str(len(organisationList)) + ')', 'thrift', msg=str(len(organisationList)) + " organizations",data=organisationList))
print('\033[92m' + 'success' + '\033[0m')
- #logStatus(statusList[-1])
except ConnectionResetError:
statusList.append(Status(name, host, 'error', 'Offline', 'thrift', msg="ConnectionResetError: [Errno 104] Connection reset by peer"))
print('\033[91m' + 'error' + '\033[0m')
- # statusList.append(Status(name, host, 'error', 'Offline', 'thrift', msg=str(e)))
finally:
logStatus(statusList[-1])
@@ -171,14 +168,11 @@ def writeLog():
# Returns the most recent log object to a given status. None if there is none.
def getLogEntry(status):
- # for entry in reversed(logEntries):
- # if status.host == entry.host and status.service == entry.service: return entry
return next((x for x in reversed(logEntries) if (x.host == status.host) and (x.service == status.service)), None)
# Checks weather the status has to be logged or not. (Does the status has changes from the last time?)
def logStatus(status):
obj = getLogEntry(status)
- # print(status.host + " " + status.service + " " + status.state)
if (obj is None) or (status.state != obj.state):
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))
@@ -200,6 +194,9 @@ 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')
# Write the new logfile.
writeLog()