@@ -25,6 +25,9 @@ def check_clients_ok():
25
25
else :
26
26
client ['check_ok' ] = True
27
27
28
+ def get_id (host , port ):
29
+ return 'client_{}_{}' .format (host , port )
30
+
28
31
29
32
@app .route ('/' )
30
33
def index ():
@@ -57,7 +60,7 @@ def fake_data():
57
60
client = random .choice (client_types )
58
61
status = random .choice (statuses )
59
62
check_ok = random .choice ([True , False ])
60
- _id = 'client_ {}' .format (port )
63
+ _id = 'client_127.0.0.1_ {}' .format (port )
61
64
data = {
62
65
'client_type' : client ,
63
66
'_id' : _id ,
@@ -82,14 +85,16 @@ def index_fe():
82
85
def keep_alive ():
83
86
global global_state
84
87
data = json .loads (request .data )
85
- _id = data ['_id' ]
88
+ host = request .remote_addr
89
+ port = data ['port' ]
90
+ _id = get_id (host , port )
86
91
if _id not in global_state ['clients' ]:
87
92
global_state ['clients' ][_id ] = {
88
93
'joined_at' : datetime .now ().strftime ('%Y-%m-%d %H:%m' ),
89
94
'client_type' : data ['client_type' ],
90
- 'port' : data [ ' port' ] ,
95
+ 'port' : port ,
91
96
'check_ok' : True ,
92
- 'host' : data [ ' host' ] ,
97
+ 'host' : host ,
93
98
'last_ping' : datetime .now ()
94
99
}
95
100
global_state ['clients' ][_id ].update ({'state' : data ['state' ]})
@@ -112,13 +117,13 @@ def get_state():
112
117
global global_state
113
118
host = request .remote_addr
114
119
data = json .loads (request .data )
115
- # TODO: Conform _id from real host
116
- _id = data [ '_id' ]
120
+ port = data [ 'port' ]
121
+ _id = get_id ( host , port )
117
122
if _id not in global_state ['clients' ]:
118
123
global_state ['clients' ][_id ] = {
119
124
'joined_at' : datetime .now ().strftime ('%Y-%m-%d %H:%m' ),
120
125
'client_type' : data ['client_type' ],
121
- 'port' : data [ ' port' ] ,
126
+ 'port' : port ,
122
127
'check_ok' : True ,
123
128
'host' : host ,
124
129
'last_ping' : datetime .now ()
0 commit comments