-
Notifications
You must be signed in to change notification settings - Fork 0
/
statusMonitor.py
65 lines (40 loc) · 1.83 KB
/
statusMonitor.py
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
__author__ = 'erlend'
from time import sleep as zzz
import udpServer
import databaseHandeling as dbh
import mailOnFail
import datetime
def setTimeOfDeath(): #different formatting from method in udpServerm, finds exact time of death
time_now = datetime.datetime.now()
time_now = (time_now.strftime('%d%m%Y%H%M%S'))
return time_now
def confirmStatus(id): # this is used to monitor the status of the computer via the database hosted on digitalocean
control_variable = 300
isSent = False
mailOnFail.mailOnFail(id,' is UP!')
while True:
current_system_time = udpServer.getCurrentTime()
last_ping_time = dbh.checkTime(id)
result = int(current_system_time) - int(last_ping_time)
control_variable = last_ping_time
programstatus = dbh.checkProgramStatus(id)
if(programstatus == False and isSent == False):
mailOnFail.mailOnFail(id,' is not recording! Timecode - ' + dbh.getTimeOfDeath(id))
isSent = True
if(programstatus == True and isSent == True):
mailOnFail.mailOnFail(id,' is now recording again!')
isSent = False
print('Time scince last ping from ' + id + ' is ' + str(result) + ' second(s)')
if(result >= 10): ## Denne skal oppdateres til 15 min i ferdig versjon etter testing hos kunde
break
if(result<0 and (last_ping_time == control_variable)): #handles the situation where result is stuck at >0
zzz(4)
if((dbh.checkTime(id)) == control_variable):
break
zzz(5)
print('CLIENT WITH ID: ' + id + ' IS DOWN!')
dbh.updateComputerStatus(id,'0')
dbh.updateProgramStatus(id,'0')
dbh.setTimeOfDeath(id,setTimeOfDeath())
mailOnFail.mailOnFail(id, ' is DOWN! Timecode - ' + dbh.getTimeOfDeath(id))
return