2019-09-05 20:03:30 +08:00
|
|
|
import json
|
|
|
|
|
2019-08-29 23:18:25 +08:00
|
|
|
|
|
|
|
class CommunicationAnalyzer(object):
|
|
|
|
|
2019-09-05 20:03:30 +08:00
|
|
|
def __init__(self, island_client, machine_ips):
|
2019-08-29 23:18:25 +08:00
|
|
|
self.island_client = island_client
|
2019-09-05 20:03:30 +08:00
|
|
|
self.machine_ips = machine_ips
|
2019-08-29 23:18:25 +08:00
|
|
|
|
|
|
|
def analyze_test_results(self):
|
2019-09-05 20:03:30 +08:00
|
|
|
for machine_ip in self.machine_ips:
|
|
|
|
if not self.did_monkey_communicate_back(machine_ip):
|
|
|
|
return False
|
|
|
|
print("Monkey from {} communicated back".format(machine_ip))
|
|
|
|
return True
|
2019-08-29 23:18:25 +08:00
|
|
|
|
2019-09-05 20:03:30 +08:00
|
|
|
def did_monkey_communicate_back(self, machine_ip):
|
|
|
|
query = json.dumps({'ip_addresses': {'$elemMatch': {'$eq': machine_ip}}})
|
|
|
|
response = self.island_client.send_get_request("api/test/monkey", {'find_query': query})
|
|
|
|
return len(json.loads(response.content)['results']) > 0
|
2019-08-29 23:18:25 +08:00
|
|
|
|
|
|
|
|