@@ -164,14 +164,21 @@ def start_monitor(self, ivalue):
164164
165165 def stop_monitor (self , ivalue ):
166166 ''' stop monitoring an address'''
167+
168+ for my_hash , my_dict in ivalue .iteritems ():
169+ if my_hash in self .monitoring :
170+ self .monitoring .pop (my_hash )
171+
172+ self .logger .debug ('stop_monitor:{0},{1}' .format (ivalue , type (ivalue )))
167173 r_exchange = 'topic-poseidon-internal'
168- r_key = 'poseidon.action.start_monitor '
174+ r_key = 'poseidon.action.stop_monitor '
169175 r_msg = json .dumps (ivalue )
170176 self .rabbit_channel_local .basic_publish (exchange = r_exchange ,
171177 routing_key = r_key ,
172178 body = r_msg )
173179
174180 def endpoint_shutdown (self , ivalue ):
181+ self .logger .debug ('endpoint_shutdown:{0}' .format (ivalue ))
175182 ''' shutdown an endpoint '''
176183 r_exchange = 'topic-poseidon-internal'
177184 r_key = 'poseidon.action.endpoint_shutdown'
@@ -197,13 +204,15 @@ def check_db(self, dev_hash, field):
197204 '''
198205 try :
199206 query = {'dev_id' : dev_hash }
207+ query_string = str (query ).replace ("\' " , "\" " )
200208 ip = self .mod_configuration ['storage_interface_ip' ]
201209 port = self .mod_configuration ['storage_interface_port' ]
202210 uri = 'http://' + ip + ':' + port + \
203211 '/v1/storage/query/{database}/{collection}/{query_str}' .format (
204212 database = self .mod_configuration ['database' ],
205213 collection = self .mod_configuration ['collection' ],
206- query_str = query )
214+ query_str = query_string )
215+ self .logger .error ('check_db:{0}:{1}' .format (uri , type (uri )))
207216 resp = requests .get (uri )
208217 self .logger .debug ('response from db:' + resp .text )
209218
@@ -241,46 +250,49 @@ def start_vent_collector(self, dev_hash, num_captures=1):
241250 except Exception , e :
242251 self .logger .debug ('failed to start vent collector' + str (e ))
243252
253+ @staticmethod
254+ def just_the_hash (ivalue ):
255+ return ivalue .keys ()[0 ]
256+
244257 def handle_item (self , itype , ivalue ):
245258 self .logger .debug ('handle_item:{0}:{1}' .format (itype , ivalue ))
246- ivalue = json .loads (ivalue )
259+
260+ # just get a string back from the ml stuff
261+ if 'poseidon.algos.eval_dev_class' not in itype :
262+ ivalue = json .loads (ivalue )
263+
247264 if itype == 'poseidon.action.shutdown' :
248265 self .logger .debug ('***** shutting down' )
249266 self .shutdown = True
250267 if itype == 'poseidon.action.new_machine' :
251268 self .logger .debug ('***** new machine {0}' .format (ivalue ))
252269 # tell monitor to monitor
253- self .start_vent_collector (ivalue )
270+ self .start_vent_collector (self . just_the_hash ( ivalue ) )
254271 self .start_monitor (ivalue )
255- if itype == 'poseidon.analytics.results.traditional' :
256- # TODO make a db call
257- # need to compare results to db
258- if False :
259- # if bad
260- self .logger .debug (
261- '***** shutting down endpoint:{0}:{1}' .format (itype , ivalue ))
262- self .endpoint_shutdown (ivalue )
263- else :
264- # if good
265- self .logger .debug (
266- '***** allowing endpoint {0}:{1}' .format (itype , ivalue ))
267- self .stop_monitor (ivalue )
268272 if 'poseidon.algos.eval_dev_class' in itype :
273+ # ivalue = classificationtype:<string>
269274 # result form eval device classifier with
270275 # dev hash attached to end of routing key
271- dev_hash = ivalue .split ('.' )[- 1 ]
276+ dev_hash = itype .split ('.' )[- 1 ]
272277 prev_class = self .check_db (dev_hash , 'dev_classification' )
278+
273279 monitoring_id = self .monitoring [dev_hash ]
274- self .stop_monitor (monitoring_id )
280+ temp_d = {dev_hash : monitoring_id }
281+
282+ # self.stop_monitor(monitoring_id)
283+ self .stop_monitor (temp_d )
284+
275285 self .logger .debug ('stopping monitoring on:' + itype )
286+ self .logger .debug ('classified as:{0}' .format (ivalue ))
287+ self .logger .debug ('classified previously {0}' .format (prev_class ))
276288 if ivalue == prev_class :
277289 self .logger .debug (
278- '***** allowing endpoint {0}:{1}' .format (itype , ivalue ))
279- self .endpoint_allow (monitoring_id )
290+ '***** allowing endpoint {0}:{1}' .format (itype , temp_d ))
291+ self .endpoint_allow (temp_d )
280292 else :
281293 self .logger .debug (
282- '***** shutting down endpoint:{0}:{1}' .format (itype , ivalue ))
283- self .endpoint_shutdown (monitoring_id )
294+ '***** shutting down endpoint:{0}:{1}' .format (itype , temp_d ))
295+ self .endpoint_shutdown (temp_d )
284296
285297 def make_rabbit_connection (self , host , exchange , queue_name , keys ): # pragma: no cover
286298 '''
0 commit comments