From b99193ba68f947802245a288940e54904ecbee61 Mon Sep 17 00:00:00 2001 From: Triatmoko Date: Fri, 18 Nov 2011 13:23:49 +0100 Subject: final version --- Code/Server-Code/gsmselftest.py | 81 ++++++++++++++++++++++++++++------------- 1 file changed, 56 insertions(+), 25 deletions(-) mode change 100755 => 100644 Code/Server-Code/gsmselftest.py (limited to 'Code/Server-Code/gsmselftest.py') diff --git a/Code/Server-Code/gsmselftest.py b/Code/Server-Code/gsmselftest.py old mode 100755 new mode 100644 index 61d4246..082b19f --- a/Code/Server-Code/gsmselftest.py +++ b/Code/Server-Code/gsmselftest.py @@ -11,6 +11,9 @@ import WebsiteCommClass import signal import random from time import sleep +import setproctitle + +setproctitle.setproctitle('Controller Software') class bcolors: HEADER = '\033[95m' @@ -76,7 +79,22 @@ def initDB(): # function for connection database db.connectDB() dbStatus = db.connectDB() if dbStatus == 1: - print 'Lock the mutex: ' + str(db.lockMutex(600)) + db.lockMutex(600) + +def initNagiosString(x): + + initResult = truthtableClass.trueTable(x) + initResult.initNagiosResult() + + if int(initResult.FAILED) != 0: + print "GSM CRITICAL - Number of test "+str(initResult.testMount)+'; Failure '+str(initResult.FAILED)+'; Unknown '+str(initResult.handlerError) + elif int(initResult.handlerError) != 0: + print "GSM WARNING - Number of test "+str(initResult.testMount)+'; Failure '+str(initResult.FAILED)+'; Unknown '+str(initResult.handlerError) + elif int(initResult.FAILED) == 0 and int(initResult.handlerError) == 0: + print "GSM OK - Number of test "+str(initResult.testMount)+'; Failure '+str(initResult.FAILED)+'; Unknown '+str(initResult.handlerError) + else: + + print "unknown error" def initTrueTable(x): @@ -86,7 +104,6 @@ def initTrueTable(x): print '\n' openBSC = None asterikServer = None - finalResult = list() for x in initResult.nanoBts: name = x[0] @@ -136,7 +153,7 @@ def initTrueTable(x): def errorCodes(callFrom, callTo, result): message = '|' + str(callFrom) + '|' + str(callTo) + '|' + str(result) + '|' + str(db.errorCode(result)) - print message + sendResultWebsite(message) # function to search in the list @@ -151,7 +168,7 @@ def isThere(keyword,lists): def testDest(callFrom, callTo, tried): - makeTest.initTest(callFrom,callTo)#xxxx + makeTest.initTest(callFrom,callTo) db.insertTask(taskNum,callFrom,callTo) smartResultList.append([callFrom,callTo, makeTest.result,tried]) taskID = db.maxTaskID() @@ -192,8 +209,7 @@ def smartTest(): testDest(callFrom, callTo, 1) gsmRZList.remove(callTo) destList.remove(callTo) - - + for callFrom in gsmRZList: i = random.randint(0, len(destList)-1) #Check whether the caller and dest are same @@ -228,10 +244,11 @@ def smartTest(): #checking unsuccess call, to make sure that destination are really unreachable for dest in smartResultList: #check unsuccess call and did the test have already tried, 2 means has been check - if int(dest[2]) == 486 or int(dest[2]) == 999 or int(dest[2]) == 998 or int(dest[2]) == 801 or int(dest[2]) == 802: + if int(dest[2]) == 486 or int(dest[2]) == 999 or int(dest[2]) == 998 or int(dest[2]) == 801 or int(dest[2]) == 802: + if int(dest[3]) != 2 and dest[1] != 'sip': testDestination = True - founds = False + testFromRZ = False testCaller = True # make sure that destination have not tested by another part and give success result. for test in smartResultList: @@ -242,28 +259,24 @@ def smartTest(): if int(test[2]) == 200: testCaller = False #if destination have not tested by other part. try to test from RZ GSM - if int(test[2]) == 200: + if int(test[2]) == 200 and testFromRZ != True: for caller in cpgsmRZList: if caller == test[0] or caller == test[1]: callFrom = caller - founds = True + testFromRZ = True - if dest[0] != 'sip': - founds = False - if testDestination == True: - if founds != True: + if testFromRZ != True: callFrom = 'sip' callTo = dest[1] - if dest[0] != 'sip': - testDest(callFrom, callTo, 2) - rem.append(dest) + testDest(callFrom, callTo, 2) + rem.append(dest) #check unsuccess call because caller handler having problem #destination handler having problem, we should make test also to the caller if int(dest[2]) == 998 or int(dest[2]) == 802 or int(dest[2]) == 486: if testCaller == True: - if founds != True: + if testFromRZ != True: callFrom = 'sip' callTo = dest[0] testDest(callFrom, callTo, 2) @@ -272,10 +285,15 @@ def smartTest(): caller = dest[0] # to test nanobts if the test come from RZ GSM but fehler if caller[0:5] == 'GSMRZ' and int(dest[3]) != 2 and dest[1] != 'sip': + repeatTest = True + for test in smartResultList: + if test[1] == caller or test[0] == caller: + repeatTest = False if int(dest[2]) == 486 or int(dest[2]) == 402: - callFrom = 'sip' - testDest(callFrom, dest[0], 2) - rem.append(dest) + if repeatTest == True: + callFrom = 'sip' + testDest(callFrom, dest[0], 2) + rem.append(dest) # test to make sure nanoBTS working or not. sice probably that nanotbts seems error but actually not. for RZ in cpgsmRZList: @@ -321,18 +339,25 @@ def smartTest(): return smartResultList def doSmartTest(status): - global taskNum + global taskNum, printMessage global WebStatus initDB() taskNum = db.maxTaskNo() global makeTest if status == True: WebStatus = True + else: WebStatus = False + makeTest = initTestClass.initTesting() result = smartTest() - initTrueTable(result) + if status == 'NAGIOS': + initNagiosString(result) + + elif status == False: + initTrueTable(result) + if status == True: sendFinishMessage() @@ -643,8 +668,6 @@ def closeFunction(dbConn,serverSocket): if len(sys.argv) > 1: command = sys.argv[1] - - print ' ' if command == '--all': resultsList = list() @@ -674,6 +697,14 @@ if len(sys.argv) > 1: db.updatePingResult(taskNo, sipServer, sipGate, unisip, gsmBox1, gsmBox2) doSmartTest(False) + elif command == '--nagios': + initDB() + resultsList = list() + allPing() + taskNo = db.maxTaskNo() + db.updatePingResult(taskNo, sipServer, sipGate, unisip, gsmBox1, gsmBox2) + doSmartTest('NAGIOS') + elif command == '--devconf': updateDevice() -- cgit v1.2.3-55-g7522