summaryrefslogtreecommitdiffstats
path: root/Code/Server-Code/truthtableClass.py
blob: df6738b266c27861506b450d3702e08cbeacf7e2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
import DbClass

class trueTable:
     def __init__(self, resultsList):

		self.resultsList	= resultsList
		self.outGoingRZ		= None
		self.asteriskServer 	= None
        	self.incomingRZ     	= None
            	self.openBSC    	= None
		self.nanoBTS		= ''
		self.deviceStatus	= list()
		self.testMount		= len(resultsList)
		self.OK 		= 0
		self.FAILED 		= 0
		self.handlerError 	= 0

     def initDB(self):
    	# function for connect to database
	self.db = DbClass.DBMySQLConnection()
        self.db.connectDB()
        self.dbStatus = self.db.connectDB()

     def lookingBTSname(self, btsname):
	if self.nanoBts == '':
		self.found = False
	else:
		found = False
		for y in self.nanoBts: #find the existing nanoBts result
			name = y[0]
			if name == btsName:
				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]:
				if str(item[1]) != 'OK':
					update = True
				else:
					update = None
	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'])

					elif self.findStatusInList(device) == False:
						self.deviceStatus.append([device,'OK'])
					else:
						continue

				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()
	deviceLists = self.db.deviceList() #fetch device list from database
	externalRZList = list()

        for devLists in deviceLists: #define category of the external devices
		device = devLists[0]

            	if device[0:5] == 'GSMEx' or device == 'landline':
                	externalRZList.append(device) # fetch into the list
	self.db.closeDBConn()
	lists = self.resultsList
        self.nanoBts = list()
        gsmResultList = list()

        i= 1
        for w in lists:
		call=w[0]
		dest=w[1]

		
        	if call[0:5]=='GSMRZ':
               		if i <= int(call[5:]):
              			i = int(call[5:])
        	if dest[0:5]=='GSMRZ':

               		if i <= int(dest[5:]):
               			i = int(dest[5:])
	i = i+1

        for x in lists: # to find nanoBts, asterik server and open BSC status regarding result test for GSM RZ 
            call=x[0]
            dest=x[1]
            result=x[2]
            stop = False
            j=1

	    if call[0:5]=='GSMRZ' or dest[0:5]=='GSMRZ':
            	while stop != True:
                	if j != i:
                    		key = 'GSMRZ'+str(j)
                    		if key == call or key == dest:

					btsName = 'nanoBts '+str(j)
                        		if result == '200':

						btsName = 'nanoBts '+str(j)
                            			self.asteriskServer = True #set status of asterik server as working
						self.lookingBTSname(btsName)
						if self.found != True:
							#if doesnt found the nanoBts, add the result to the list, otherwise just ignoring 
							try:
								self.nanoBts.remove(btsName)
							except ValueError:
								message = 'Error'

							self.nanoBts.append([btsName,True])

                            			if key == call:
                                			for z in externalRZList:# find the result for outgoing call from GSM RZ to external RZ network
                                    				if dest == z:
                                        				self.outGoingRZ = True #set status as working for outgoing RZ
                            			if key == dest:
                                			for z in externalRZList:
                                    				if call == z:
                                        				self.incomingRZ = True # find the result for imcoming call to GSM RZ from external RZ network
					elif result == '486':
						found = False
                            			if key == call:
                                			for z in externalRZList:
                                    				if dest == z and self.outGoingRZ != True:
                                        				self.outGoingRZ = False
                            			if key == dest:
                                			for z in externalRZList:
                                    				if call == z and self.incomingRZ != True:
                                        				self.incomingRZ = False
						if self.nanoBts == '':
							self.nanoBts.append([btsName,False])
						for y in self.nanoBts: #find the existing nanoBts result
                                    			name = y[0]
                                    			if name == btsName and y[1] == True:
								found = True
						if found != True:
                            				self.nanoBts.append([btsName,False])

					elif (str(result) == '801' or str(result) == '999') and key == call:
						#self.lookingBTSname(key)
						if self.lookingBTSname(key) != True:
							self.nanoBts.append([key,result])

					elif (str(result) == '802' or str(result) == '998') and key == dest:
						#self.lookingBTSname(key)
						if self.lookingBTSname(key) != True:
							self.nanoBts.append([key,result])
         
                    		j = j+1
               		elif j == i:
                    		stop = True

            if call[0:5]=='GSMEx': # looking for calling from GSMexternal
            		found = False
            		if len(self.nanoBts) == 0:
                		self.nanoBts.append([call,result])
                		found = False
            		else:
                		for y in self.nanoBts: #find the existing result for GSM external in the list
                    			name = y[0]
					if name == call:
						if int(result) == 200:
							if int(y[1]) == 486 or int(y[1]) == 999 or int(y[1]) == 998 or int(y[1]) == 801 or int(y[1]) == 802 or int(y[1]) == 402:
								self.nanoBts.remove(y)
						else:
	                        			found = True                    			
                		if found != True:
                    			self.nanoBts.append([call,result])
    
            if dest[0:5]=='GSMEx': # looking for destination call to GSMexternal
            		found = False
            		if len(self.nanoBts) == 0:
                		self.nanoBts.append([dest,result])
                		found = False
            		else:
				
                		for y in self.nanoBts:
                    			name = y[0]
                    			if name == dest:
						if int(result) == 200:
							if int(y[1]) == 486 or int(y[1]) == 999 or int(y[1]) == 998 or int(y[1]) == 402 or int(y[1]) == 802 or int(y[1]) == 801:
								self.nanoBts.remove(y)
						else:
	                        			found = True
                		if found != True:
                    			self.nanoBts.append([dest,result])


	    for device in externalRZList:
		if device == dest and int(result) == 200:
			self.outGoingRZ = True