summaryrefslogtreecommitdiffstats
path: root/Code
diff options
context:
space:
mode:
authorTriatmoko2011-11-18 13:23:49 +0100
committerTriatmoko2011-11-18 13:23:49 +0100
commitb99193ba68f947802245a288940e54904ecbee61 (patch)
treedd28de19b823a1b18722c98bebec81c3a8d8e6a1 /Code
parentnagios function fully working (diff)
downloadgsm-selftest-b99193ba68f947802245a288940e54904ecbee61.tar.gz
gsm-selftest-b99193ba68f947802245a288940e54904ecbee61.tar.xz
gsm-selftest-b99193ba68f947802245a288940e54904ecbee61.zip
final version
Diffstat (limited to 'Code')
-rw-r--r--[-rwxr-xr-x]Code/Server-Code/ClientClass.py0
-rw-r--r--[-rwxr-xr-x]Code/Server-Code/ControllerClass.py59
-rw-r--r--[-rwxr-xr-x]Code/Server-Code/DbClass.py15
-rw-r--r--Code/Server-Code/GSMHandler.py103
-rw-r--r--[-rwxr-xr-x]Code/Server-Code/LogFileClass.py0
-rw-r--r--[-rwxr-xr-x]Code/Server-Code/PingClass.py0
-rw-r--r--[-rwxr-xr-x]Code/Server-Code/SIPHandler.py138
-rw-r--r--[-rwxr-xr-x]Code/Server-Code/SSHTunnelBoxClass.py0
-rw-r--r--[-rwxr-xr-x]Code/Server-Code/ServerClass.py0
-rw-r--r--[-rwxr-xr-x]Code/Server-Code/gsmselftest.py81
-rw-r--r--Code/Server-Code/handler.txt1
-rw-r--r--[-rwxr-xr-x]Code/Server-Code/help.txt1
-rw-r--r--[-rwxr-xr-x]Code/Server-Code/initTestClass.py3
-rw-r--r--[-rwxr-xr-x]Code/Server-Code/startSoftware.py10
-rw-r--r--[-rwxr-xr-x]Code/Server-Code/truthtableClass.py80
-rw-r--r--[-rwxr-xr-x]Code/Server-Code/usbDetectClass.py0
16 files changed, 337 insertions, 154 deletions
diff --git a/Code/Server-Code/ClientClass.py b/Code/Server-Code/ClientClass.py
index 46c3b00..46c3b00 100755..100644
--- a/Code/Server-Code/ClientClass.py
+++ b/Code/Server-Code/ClientClass.py
diff --git a/Code/Server-Code/ControllerClass.py b/Code/Server-Code/ControllerClass.py
index 4f4cef5..4ed0d9d 100755..100644
--- a/Code/Server-Code/ControllerClass.py
+++ b/Code/Server-Code/ControllerClass.py
@@ -4,6 +4,7 @@ import subprocess
import SSHTunnelBoxClass
import ClientClass
import random
+import csv
import LogFileClass
logger = LogFileClass.Logging('TestProcessLog.log')
@@ -46,6 +47,7 @@ class controller:
sleep(2)
self.callerGreeting()
+ logger.logEvent('Status Handler Connection :'+self.connected)
if self.connected == 'OK':
self.caller.sendData('CALLER|'+self.destNo)
@@ -65,8 +67,9 @@ class controller:
else:
#waiting 2 seconds if doesnt use ssh connection until handler ready
sleep(2)
- self.receiverGreeting()
-
+ self.receiverGreeting()
+
+ logger.logEvent('Status Handler Connection :'+self.connected)
if self.connected == 'OK':
self.receiver.sendData('RECEIVER')
@@ -105,7 +108,6 @@ class controller:
self.caller.sendData('TERMINATE CONNECTION')
self.caller.closeConnection()
- self.initCancelTest()
#can connect to handler but device caller not ready to do the test.
elif self.connected == 'DEVICE NOT READY':
@@ -118,6 +120,14 @@ class controller:
self.testResult = 999
logger.logEvent('999 General Handler Error: Could not connect to Caller handler')
+ def writeToFile(self, AccountInfo):
+ try:
+ with open('handler.txt', 'w') as F:
+ writer = csv.writer(F)
+ writer.writerow([AccountInfo])
+ F.close()
+ except ValueError:
+ print "can't write to file"
def initCancelTest(self):
#close SSH connection when using gsmBox and destination doesnt respond. to make sure SSH connection are terminate
@@ -134,16 +144,19 @@ class controller:
self.resultCaller = self.caller.receiveData(20)
#print 'result '+self.resultCaller+'--'+self.resultDest
if self.resultCaller == 'DEVICE NOT READY':
+ logger.logEvent('Task :'+self.callFrom+' - '+self.dest)
logger.logEvent('Caller DEVICE NOT READY')
self.testResult = 801
self.initTerminate()
elif self.dest == 'DEVICE NOT READY':
+ logger.logEvent('Task :'+self.callFrom+' - '+self.dest)
logger.logEvent('Caller DEVICE NOT READY')
self.testResult = 802
self.initTerminate()
elif self.resultCaller == 'CALL OK' and self.resultDest =='CALL OK':
+ logger.logEvent('Task :'+self.callFrom+' - '+self.dest)
logger.logEvent('Test Succeed')
self.testResult = 200
self.initTerminate()
@@ -151,17 +164,20 @@ class controller:
#build specially only for Eplus card. since they use prepaid card.
if self.dest == 'GSMExt.Eplus':
if self.resultCaller == 'CALL OK' and self.resultDest <> 'TIME OUT':
+ logger.logEvent('Task :'+self.callFrom+' - '+self.dest)
logger.logEvent('Test Failed - Eplus No credit on Eplus')
self.testResult = 402
self.initTerminate()
else:
logger.logEvent('Test Failed')
+ logger.logEvent('Task :'+self.callFrom+' - '+self.dest)
self.testResult = 486
self.initTerminate()
else:
#one or both of the handler send un success test. assign failed to this test
if self.resultCaller <> 'CALL OK' or self.resultDest <> 'CALL OK':
+ logger.logEvent('Task :'+self.callFrom+' - '+self.dest)
logger.logEvent('Test Failed')
self.testResult = 486
self.initTerminate()
@@ -172,7 +188,7 @@ class controller:
self.receiver.sendData('RECEIVE START')
self.caller.sendData('CALL START')
- def initAccount(self, account):
+ def initAccount(self, account, handler, PortName, portCom):
accConf = account
self.username = accConf[0:accConf.find(':')]
@@ -183,6 +199,9 @@ class controller:
newLine = line[line.find(':')+1:]
self.server = newLine[0:newLine.find(':')]
+ textFile = 'Account:'+str(self.username)+':'+str(self.password)+':'+str(self.server)+':'+str(handler)+':'+str(PortName)+':'+str(portCom)
+ self.writeToFile(textFile)
+
# define the caller configuration such as port name and port caller.
def initCaller(self):
logger.logEvent('init Caller')
@@ -191,12 +210,15 @@ class controller:
if self.callFrom[0:4] == 'GSMR':
if self.callFrom =="GSMRZ1":
+ self.initAccount(self.accCaller,self.callFrom, self.callPortName,self.portCaller)
self.initGSM(self.portCaller, self.callPortName, self.callFrom)
else:
- self.initAccount(self.accCaller)
+ self.initAccount(self.accCaller, self.callFrom, self.callPortName,self.portCaller)
#open SSH tunneling
+
self.boxCaller = SSHTunnelBoxClass.SSHTunneling(self.portCaller, 50008, self.server, self.username, self.password)
status = self.boxCaller.startTunneling()
+ logger.logEvent('SSH Status :'+str(status))
#check whether the SSH tunneling succes or not, 0 is failed!
if status!= 0:
@@ -204,11 +226,14 @@ class controller:
else:
self.continues = 0
elif self.callFrom[0:4] == 'GSME':
+ self.initAccount(self.accCaller,self.callFrom, self.callPortName,self.portCaller)
self.initGSM(self.portCaller, self.callPortName, self.callFrom)
else:
#open the SIP handler
- subprocess.Popen(args=["gnome-terminal", '--command=python SIPHandler.py '+self.accCaller+ ' ' +str(self.portCaller)])
+ self.initAccount(self.accCaller,self.callFrom, self.callPortName,self.portCaller)
+ script = 'SIPHandler.py'
+ subprocess.Popen(['python',script], shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# define the destination configuration such as port name and port caller.
def initReceiver(self):
@@ -218,25 +243,31 @@ class controller:
if self.dest[0:4] == 'GSMR':
if self.dest =="GSMRZ1":
+ self.initAccount(self.accDest, self.dest, self.destPortName,self.portDest)
self.initGSM(self.portDest, self.destPortName, self.dest)
else:
- self.initAccount(self.accDest)
+ self.initAccount(self.accDest, self.dest, self.destPortName,self.portDest)
#open SSH tunneling
+
self.boxDest = SSHTunnelBoxClass.SSHTunneling(self.portDest, 50008, self.server, self.username, self.password)
status = self.boxDest.startTunneling()
#check whether the SSH tunneling succes or not, 0 is failed!
+ logger.logEvent('SSH Status :'+str(status))
if status!= 0:
self.continues = 1
else:
self.continues = 0
elif self.dest[0:4] == 'GSME':
- self.initGSM(self.portDest, self.destPortName, self.dest)
+ self.initAccount(self.accDest, self.dest, self.destPortName,self.portDest)
+ self.initGSM(self.portDest, self.destPortName, self.dest)
else:
- self.portDest = 50100
- subprocess.Popen(args=['gnome-terminal', '--command=python SIPHandler.py '+self.accDest+ ' ' +str(self.portDest)])
+ #self.portDest = 50100
+ self.initAccount(self.accDest, self.dest, self.destPortName,self.portDest)
+ script = 'SIPHandler.py'
+ subprocess.Popen(['python',script], shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# send terminate message to Handlers
def initTerminate(self):
@@ -263,7 +294,7 @@ class controller:
#open connection to the Handler
self.caller = ClientClass.Connection('localhost',self.portCaller)
self.caller.connect()
-
+
if self.caller.connected == 1:
#connection establish and send hallo message to handler
logger.logEvent('Connected to Caller Handler')
@@ -290,10 +321,11 @@ class controller:
def receiverGreeting(self): # send greeting message to the destination handler
logger.logEvent('Receiver Greeting')
self.connected = None
+
#open connection to the Handler
self.receiver = ClientClass.Connection('localhost', self.portDest)
self.receiver.connect()
-
+
if self.receiver.connected == 1:
#connection establish and send hallo message to handler
logger.logEvent('Connected to Receiver Handler')
@@ -321,7 +353,8 @@ class controller:
def initGSM(self, portCommunication, portDevice, handler):
#open GSM Handler
logger.logEvent('Init GSM')
- subprocess.Popen(args=["gnome-terminal", '--command=python GSMHandler.py '+str(portCommunication)+ ' ' +str(portDevice)+' '+str(handler)])
+ script = 'GSMHandler.py'
+ subprocess.Popen(['python',script], shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
diff --git a/Code/Server-Code/DbClass.py b/Code/Server-Code/DbClass.py
index a53987f..d937eb1 100755..100644
--- a/Code/Server-Code/DbClass.py
+++ b/Code/Server-Code/DbClass.py
@@ -4,8 +4,8 @@ import string
class DBMySQLConnection:
def __init__(self):
#initialize at the start all the user parameters
- self.usern = "selftest"
- self.passw = "selftest"
+ self.usern = "root"
+ self.passw = ""
self.host = "localhost"
self.db = "gsmselftesting"
self.connectionCreated = 0
@@ -19,7 +19,7 @@ class DBMySQLConnection:
def connectDB(self):
try:
- #try the connection
+ #try to connect
self.datBaseConn=MySQLdb.connect(self.host,self.usern, self.passw,self.db)
self.datBaseConn.paramstyle = 'format'
self.cur = self.datBaseConn.cursor() #make the cursor, used for sending queries
@@ -115,7 +115,7 @@ class DBMySQLConnection:
return 2 #the table doesn't exist
if debugMode == 1:
print str(e)
- return 3 #some error happened 07667929147--Fitri
+ return 3 #some error happened
else:
return 0 #I am not connected
def deviceList(self): # taking all device list and put it in the list
@@ -171,6 +171,13 @@ class DBMySQLConnection:
def updateGSMDevice(self, deviceName, newPortName, newNumber):
if self.connectionCreated == 1:
try:
+ try:
+ #delete old device portName which assign to this port, to prevent double port address in the table.
+ stmt = "UPDATE DeviceAddressTable SET portName = 'missing' WHERE portName = '"+newPortName+"'"
+ self.cur.execute(stmt)
+ except ValueError:
+ print "Error execute query"
+
stmt = "UPDATE DeviceAddressTable SET portName = '"+ newPortName + "', number = '"+ newNumber+ "' WHERE deviceName = '" + deviceName+ "'"
self.cur.execute(stmt)
return 1
diff --git a/Code/Server-Code/GSMHandler.py b/Code/Server-Code/GSMHandler.py
index cf9a2b4..1379fe9 100644
--- a/Code/Server-Code/GSMHandler.py
+++ b/Code/Server-Code/GSMHandler.py
@@ -4,34 +4,55 @@ import LogFileClass
from time import sleep
import sys
import setproctitle
-
+import csv
+global sipServer, username, password, handler
global portListen
global portAddress
-
-
-if len(sys.argv) <> 4:
- print "Error given command"
- sys.exit(2)
-
-
-handler = sys.argv[3]
-portAddress = sys.argv[2]
-portListen = int(sys.argv[1])
+global nameOfLogFile
def initLogfile():
global nameOfLogFile
nameOfLogFile = str(handler)+' handler.log'
+def writeToFile():
+ try:
+ string = '--'
+ with open('handler.txt', 'w') as F:
+ writer = csv.writer(F)
+ writer.writerow([string])
+ F.close()
+ except ValueError:
+ print "can't write to file"
+
+def openFile():
+ global sipServer, username, password, handler
+ global portListen
+ global portAddress
+
+ #String format: 'Account:username:password:server:handler:PortName:portCaller
+ File = open('handler.txt')
+ reader = csv.reader(File, delimiter=':')
+ for row in reader:
+ if str(row[0]) == 'Account':
+ handler = str(row[4])
+ portAddress = str(row[5])
+ portListen = int(row[6])
+ File.close()
+ writeToFile()
+
baudRate = 19200
+#Taking account information
+openFile()
+
+#start Logging
initLogfile()
logger = LogFileClass.Logging(nameOfLogFile)
+logger.logEvent('')
errorCount = 0
-logger.logEvent('')
-
whileCounter =0
#define global varibales
@@ -42,8 +63,10 @@ lastState = 0
resetState = 0
deviceError = 0
+
+
def initSystem():
- print 'init system'
+
global handlerSocket
global gsmDevice
@@ -58,20 +81,23 @@ def initSystem():
lastState = 0 #variable used to know
numberToCall = '000' #number to call
resetState = 0
-
+
handlerSocket = ServerClass.ServerHandler(portListen)
logger.logEvent('LISTEN ON PORT: '+str(portListen))
anyConnection = handlerSocket.openSocket()
- #add this if you need it
- gsmDevice = GSMClass.serialPort(portAddress, baudRate, 15)
- initDevice = gsmDevice.portInit(5)
+
+ try :
+ logger.logEvent('Trying connect to the device')
+ gsmDevice = GSMClass.serialPort(portAddress, baudRate, 15)
+ initDevice = gsmDevice.portInit(5)
+ logger.logEvent('init device ' + str(initDevice))
+
+ except ValueError:
+ logger.logEvent('Failure when trying connect to device')
+
########################################################
- #add nice formating to the log file :)
- print 'any connection ' + str(anyConnection)
- print 'initDevice ' + str(initDevice)
-
if initDevice!= 1:
deviceError = 1
else:
@@ -82,7 +108,7 @@ def initSystem():
logger.logEvent('CONNECTION ESTABLISHED AND DEVICE WORKING: ' + str(handlerSocket.connectedTo()))
return 1
- elif anyConnection == 1 and initDevice != 0:
+ elif anyConnection == 1 and initDevice != 1:
logger.logEvent('$connection established but device not working: ' + str(handlerSocket.connectedTo()))
resetState = 1
return 2
@@ -90,7 +116,10 @@ def initSystem():
logger.logEvent('$no connection')
logger.logEvent('$else case in init system' + str(anyConnection) + ' ' + str(initDevice) + ' ')
resetState = 1
- return 0
+
+ return 0
+
+
def receiveMessage(timeout):
@@ -221,12 +250,10 @@ def receiveStart():
callSuccess = 'CALL OK'
else:
callSuccess = 'CALL NOT OK'
-
-
-
- sendMessage = handlerSocket.sendData(callSuccess)
if deviceError==0:
- tryHangUp = gsmDevice.hangUp()
+ tryHangUp = gsmDevice.hangUp()
+ sendMessage = handlerSocket.sendData(callSuccess)
+
return sendMessage
############################
@@ -280,10 +307,12 @@ def callStart(numberToCall):
else:
callSuccess = 'CALL NOT OK'
- handResponse = handlerSocket.sendData(callSuccess)
-
if deviceError==0:
- tryHangUp = gsmDevice.hangUp()
+ try:
+ tryHangUp = gsmDevice.hangUp()
+ except ValueError:
+ print 'Error when try hangup the call'
+ handResponse = handlerSocket.sendData(callSuccess)
return handResponse
#########################
@@ -313,7 +342,7 @@ def other():
setproctitle.setproctitle('GSM Handler')
-while 1:
+try:
test = initSystem()
if test == 1:
@@ -328,10 +357,16 @@ while 1:
print 'initialized system but device not working'
logger.logEvent('initialized system but device not working')
handlerSocket.sendData('DEVICE NOT READY')
+
elif test ==0:
print 'nobody can connect, reboot board, restart cellphone'
logger.logEvent('nobody can connect, reboot board, restart cellphone')
-
+
+ logger.closeLogging()
del handlerSocket
del gsmDevice
+except ValueError:
+ logger.logEvent('Could not start the handler')
+ logger.closeLogging()
+
diff --git a/Code/Server-Code/LogFileClass.py b/Code/Server-Code/LogFileClass.py
index cb152f4..cb152f4 100755..100644
--- a/Code/Server-Code/LogFileClass.py
+++ b/Code/Server-Code/LogFileClass.py
diff --git a/Code/Server-Code/PingClass.py b/Code/Server-Code/PingClass.py
index e13b32b..e13b32b 100755..100644
--- a/Code/Server-Code/PingClass.py
+++ b/Code/Server-Code/PingClass.py
diff --git a/Code/Server-Code/SIPHandler.py b/Code/Server-Code/SIPHandler.py
index e446e1a..eb5302c 100755..100644
--- a/Code/Server-Code/SIPHandler.py
+++ b/Code/Server-Code/SIPHandler.py
@@ -5,6 +5,7 @@ import ServerClass
import LogFileClass
import setproctitle
from time import sleep
+import csv
def log_cb(level, str, len):
@@ -13,23 +14,22 @@ def log_cb(level, str, len):
# Receive events from incoming Call
class Account(pj.AccountCallback):
+ def __init__(self, account=None):
+ pj.AccountCallback.__init__(self, account)
+
def on_incoming_call(self, call):
global current_call
- print 'Incoming Call'
+ #print 'Incoming Call'
current_call = call
call_cb = Calling(current_call)
current_call.set_callback(call_cb)
- logger.logEvent(current_call)
+ logger.logEvent('Incoming Call')
call.answer(200)
- logger.logEvent("Answer call")
- print 'Answer Call'
- if current_call <> None:
- logger.logEvent("Hangup call")
- print 'Hangup Call'
- call.hangup()
+
+ sleep(2)
logger.logEvent('CALL OK')
@@ -44,20 +44,23 @@ class Calling(pj.CallCallback):
if self.call.info().state <> pj.CallState.DISCONNECTED:
if self.call.info().state_text == "CONNECTING":
- print 'Call Connecting'
logger.logEvent("Call Connecting")
- logger.logEvent('200')
+ try:
+ logger.logEvent('Try to hangup the call')
+ self.call.hangup()
+ logger.logEvent('Hangup OK')
+ except ValueError:
+ logger.logEvent('hangup failed, waiting destination hangup the call')
+
server.sendData('CALL OK')
if self.call.info().last_reason == "Busy Here":
- print 'Number busy or offline'
logger.logEvent('Number busy or Offline')
server.sendData('CALL NOT OK')
logger.logEvent('CALL NOT OK')
if self.call.info().state == pj.CallState.DISCONNECTED:
logger.logEvent('Call Disconnected')
- print 'Call Discont'
current_call = None
#function to make a call
@@ -68,19 +71,41 @@ def make_call(uri):
return acc.make_call(uri, cb)
except pj.Error, e:
- print "408 " + str(e)
- logger.logEvent('408')
+ logger.logEvent('Error when trying to call, 408')
+ server.sendData('CALL NOT OK')
return None
+def writeToFile():
+ try:
+ string = '--'
+ with open('handler.txt', 'w') as F:
+ writer = csv.writer(F)
+ writer.writerow([string])
+ F.close()
+ except ValueError:
+ print "can't write to file"
+
+def openFile():
+ global sipServer, username, password, ip, portadd
+ global port
+
+ #file format: 'Account:username:password:server:handler:PortName:portCommunication
+ File = open('handler.txt')
+ reader = csv.reader(File, delimiter=':')
+ for row in reader:
+ if str(row[0]) == 'Account':
+ username = str(row[1])
+ password = str(row[2])
+ sipServer = str(row[3])
+ port = int(row[6])
+ File.close()
+ writeToFile()
+
#send greeting message to the controller
def greeting():
- global server
- global status
- global port
- port = sys.argv[2]
+ global server
server = None
- status = None
# create socket communication object
server = ServerClass.ServerHandler(port)
@@ -88,15 +113,15 @@ def greeting():
conn = server.openSocket()
if server.connected == 1:
- #connection to the controller esatablish
+ #connection to the controller establish
+ logger.logEvent('Connection Establish')
if server.receiveData(25) == 'HELLO HANDLER':
- print 'GREETING'
server.sendData('HELLO CONTROLLER')
- status = 'OK'
+ return 1
else:
- status = 'NOT OK'
logger.logEvent('Cant connect to Controller')
- sys.exit(1)
+ del server
+ return 0
def initLogFile(sipServer):
@@ -104,15 +129,15 @@ def initLogFile(sipServer):
if sipServer == '132.230.4.8':
nameOfLogFile = 'SIP handler.log'
- print '--SIP Asterisk--'
+ #print '--SIP Asterisk--'
elif sipServer == 'sipgate.de':
nameOfLogFile = 'Landline handler.log'
- print '--Landline--'
+ #print '--Landline--'
elif sipServer == '132.230.252.228':
nameOfLogFile = 'University SIP handler.log'
- print '--university tephone network--'
+ #print '--university tephone network--'
logger = LogFileClass.Logging(nameOfLogFile)
@@ -127,7 +152,6 @@ def initState():
if message == 'RECEIVER':
state = 'RECEIVER'
-
elif message[0:6] == 'CALLER':
state = 'CALLER'
no = message[7:]
@@ -137,30 +161,13 @@ def initState():
num = no[7:]
else:
num = no
- print 'INIT STATE', state
-
-def initHandler():
- global sipServer
- global username
- global password
-
-
- accConf = sys.argv[1]
- username = accConf[0:accConf.find(':')]
-
- line = accConf[accConf.find(':')+1:]
- password = line[0:line.find(':')]
-
- newLine = line[line.find(':')+1:]
- sipServer = newLine[0:newLine.find(':')]
-
lib = pj.Lib()
stop = False
print 'INIT SYSTEM'
-initHandler()
+openFile()
setproctitle.setproctitle('SIP Handler')
initLogFile(sipServer)
@@ -176,9 +183,9 @@ while stop <> True:
lib.start()
lib.set_null_snd_dev()
- greeting()
-
-
+ if greeting() != 1:
+ lib.destroy()
+ break
try:
initState()
acc_cfg = pj.AccountConfig(str(sipServer),str(username),str(password))
@@ -201,7 +208,7 @@ while stop <> True:
print data
logger.logEvent(data)
- #shutting down message
+ #get shutting down message
if data == 'TERMINATE CONNECTION':
print data
logger.logEvent('Terminate')
@@ -218,13 +225,12 @@ while stop <> True:
#start the call
if data == 'CALL START':
- print data
+ #print data
if num <> '':
sleep(3)
logger.logEvent(data)
logger.logEvent('Make a call to: ' + num)
number = "sip:"+num+"@"+sipServer
- print number
make_call(number)
else:
logger.logEvent('No number to call')
@@ -232,7 +238,7 @@ while stop <> True:
#shutting down message
if data == 'TERMINATE CONNECTION':
- print data
+ #print data
stop = True
logger.logEvent('Terminate')
break
@@ -240,21 +246,27 @@ while stop <> True:
else:
logger.logEvent('Unknow Message')
server.sendData('Unknow Message')
- server.closeConnection()
- sys.exit(0.5)
+ break
else:
logger.logEvent("488 Not Acceptable Here")
- lib.destroy()
+ server.sendData('DEVICE NOT READY')
+ break
- except ValueError:
- print "401 Unauthorized " + str(e)
+ except ValueError:
logger.logEvent("401 Unauthorized ")
+ break
logger.logEvent("Goodbye")
-acc.delete()
-lib.destroy()
-server.closeConnection()
-lib = None
-acc = None
+logger.closeLogging()
+# trying to clean everything before shutting down
+try:
+ acc.delete()
+ lib.destroy()
+ lib = None
+ acc = None
+ server.closeConnection()
+ del server
+except ValueError:
+ message = 'trying failure'
diff --git a/Code/Server-Code/SSHTunnelBoxClass.py b/Code/Server-Code/SSHTunnelBoxClass.py
index 1b76d0b..1b76d0b 100755..100644
--- a/Code/Server-Code/SSHTunnelBoxClass.py
+++ b/Code/Server-Code/SSHTunnelBoxClass.py
diff --git a/Code/Server-Code/ServerClass.py b/Code/Server-Code/ServerClass.py
index 93c2f8e..93c2f8e 100755..100644
--- a/Code/Server-Code/ServerClass.py
+++ b/Code/Server-Code/ServerClass.py
diff --git a/Code/Server-Code/gsmselftest.py b/Code/Server-Code/gsmselftest.py
index 61d4246..082b19f 100755..100644
--- 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()
diff --git a/Code/Server-Code/handler.txt b/Code/Server-Code/handler.txt
new file mode 100644
index 0000000..45b50ac
--- /dev/null
+++ b/Code/Server-Code/handler.txt
@@ -0,0 +1 @@
+--
diff --git a/Code/Server-Code/help.txt b/Code/Server-Code/help.txt
index 5491f26..1a3b843 100755..100644
--- a/Code/Server-Code/help.txt
+++ b/Code/Server-Code/help.txt
@@ -11,6 +11,7 @@ Options and arguments (and corresponding environment variables):
--incoming : To check incoming calls from Landline
--smart : To test only important points in the network and to identify the problems
--devconf : To configure the USB device on the server
+--nagios : Execute smart test but only for Nagios plugin
example : ./gsmselftest.py --devconf
./gsmselftest.py --smart
diff --git a/Code/Server-Code/initTestClass.py b/Code/Server-Code/initTestClass.py
index b3414e2..568f840 100755..100644
--- a/Code/Server-Code/initTestClass.py
+++ b/Code/Server-Code/initTestClass.py
@@ -79,6 +79,8 @@ class initTesting:
self.initaccount(dest,callTo)
if self.status == 1:
+ #string = 'Account:username:password:server:ipaddress:portaddress:portnumber'
+
callPortName = caller[0]
accCaller = caller[2]+':'+caller[3]+':'+caller[4]+':'
@@ -91,6 +93,7 @@ class initTesting:
makeTest.FuncTest()
self.result = str(makeTest.testResult)
+
else:
self.result = 100
else:
diff --git a/Code/Server-Code/startSoftware.py b/Code/Server-Code/startSoftware.py
index 18863be..b2beb58 100755..100644
--- a/Code/Server-Code/startSoftware.py
+++ b/Code/Server-Code/startSoftware.py
@@ -1,7 +1,9 @@
#! /usr/bin/env python
import ServerClass
-import subprocess
+import subprocess
+import setproctitle
+setproctitle.setproctitle('Start Software')
while 1:
# try connect to website
server = ServerClass.ServerHandler(34600)
@@ -9,7 +11,11 @@ while 1:
test = server.receiveData(2)
if test == 'START APP':
print 'start'
- subprocess.Popen(args=['gnome-terminal','--command= python gsmselftest.py'])
+ try:
+ script = 'gsmselftest.py'
+ subprocess.Popen(['python',script], shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+ except ValueError:
+ print " - can't start controller software -"
server.closeConnection()
del server
diff --git a/Code/Server-Code/truthtableClass.py b/Code/Server-Code/truthtableClass.py
index 0d7a633..c45ab4d 100755..100644
--- a/Code/Server-Code/truthtableClass.py
+++ b/Code/Server-Code/truthtableClass.py
@@ -9,6 +9,11 @@ class trueTable:
self.incomingRZ = None
self.openBSC = None
self.nanoBTS = None
+ self.deviceStatus = list()
+ self.testMount = len(resultsList)
+ self.OK = 0
+ self.FAILED = 0
+ self.handlerError = 0
def initDB(self):
# function for connect to database
@@ -27,6 +32,64 @@ class trueTable:
self.found = True
return self.found
+ def findStatusInList(self,key):
+
+ if len(self.deviceStatus) == 0:
+ update = False
+ else:
+ update = False
+ for item in self.deviceStatus:
+ if key == item[0] and str(item[1]) != 'OK':
+ update = True
+ return update
+
+ def initNagiosResult(self):
+ self.initDB()
+ deviceLists = self.db.deviceList()
+ self.db.closeDBConn()
+
+ for items in deviceLists:
+ device = items[0]
+ for result in self.resultsList:
+ if device == result[0] or device == result[1]:
+ if int(result[2]) == 200:
+ if self.findStatusInList(device) == True:
+ try:
+ self.deviceStatus.remove([device,'NOT OK'])
+ except:
+ try:
+ self.deviceStatus.remove([device,'UNKNOWN'])
+ except:
+ continue
+ self.deviceStatus.append([device,'OK'])
+ else:
+ self.deviceStatus.append([device,'OK'])
+
+ elif int(result[2]) == 486:
+ found = False
+ for item in self.deviceStatus:
+ if device == item[0]:
+ if str(item[1]) != 'OK' or str(item[1]) == 'OK':
+ found = True
+ if found == False:
+ self.deviceStatus.append([device,'NOT OK'])
+ else:
+ found = False
+ for item in self.deviceStatus:
+ if device == item[0]:
+ if str(item[1]) != 'OK' or str(item[1]) == 'OK':
+ found = True
+ if found == False:
+ self.deviceStatus.append([device,'UNKNOWN'])
+ for status in self.deviceStatus:
+
+ if status[1] == 'OK':
+ self.OK = self.OK+1
+ elif status[1] == 'NOT OK':
+ self.FAILED = self.FAILED+1
+ else:
+ self.handlerError = self.handlerError+1
+
def initTrueTable(self):
global btsName
self.initDB()
@@ -39,7 +102,7 @@ class trueTable:
if device[0:5] == 'GSMEx' or device == 'landline':
externalRZList.append(device) # fetch into the list
self.db.closeDBConn()
- lists = self.resultsList
+ lists = self.resultsList
self.nanoBts = list()
gsmResultList = list()
@@ -113,25 +176,16 @@ class trueTable:
if found != True:
self.nanoBts.append([btsName,False])
- elif str(result) == '801' and key == call:
+ elif (str(result) == '801' or str(result) == '999') and key == call:
self.lookingBTSname(key)
if self.found != True:
self.nanoBts.append([key,result])
- elif str(result) == '802'and key == dest:
- self.lookingBTSname(key)
- if self.found != True:
- self.nanoBts.append([key,result])
-
- if str(result) == '998' and key == dest:
+ elif (str(result) == '802' or str(result) == '998') and key == dest:
self.lookingBTSname(key)
if self.found != True:
self.nanoBts.append([key,result])
-
- if str(result) == '999' and key == call:
- self.lookingBTSname(key)
- if self.found != True:
- self.nanoBts.append([key,result])
+
j = j+1
elif j == i:
stop = True
diff --git a/Code/Server-Code/usbDetectClass.py b/Code/Server-Code/usbDetectClass.py
index d64e328..d64e328 100755..100644
--- a/Code/Server-Code/usbDetectClass.py
+++ b/Code/Server-Code/usbDetectClass.py