def get_label_for_endpoint(endpoint_id): node_service = monkey_island.cc.services.node.NodeService if endpoint_id == ObjectId("000000000000000000000000"): return 'MonkeyIsland' if Monkey.is_monkey(endpoint_id): return Monkey.get_label_by_id(endpoint_id) else: return node_service.get_node_label( node_service.get_node_by_id(endpoint_id))
def test_is_monkey(self): a_monkey = Monkey(guid=str(uuid.uuid4())) a_monkey.save() cache_info_before_query = Monkey.is_monkey.storage.backend.cache_info() assert cache_info_before_query.hits == 0 # not cached assert Monkey.is_monkey(a_monkey.id) fake_id = "123456789012" assert not Monkey.is_monkey(fake_id) # should be cached assert Monkey.is_monkey(a_monkey.id) assert not Monkey.is_monkey(fake_id) cache_info_after_query = Monkey.is_monkey.storage.backend.cache_info() assert cache_info_after_query.hits == 2
def test_is_monkey(self): self.fail_if_not_testing_env() self.clean_monkey_db() a_monkey = Monkey(guid=str(uuid.uuid4())) a_monkey.save() cache_info_before_query = Monkey.is_monkey.storage.backend.cache_info() self.assertEqual(cache_info_before_query.hits, 0) # not cached self.assertTrue(Monkey.is_monkey(a_monkey.id)) fake_id = "123456789012" self.assertFalse(Monkey.is_monkey(fake_id)) # should be cached self.assertTrue(Monkey.is_monkey(a_monkey.id)) self.assertFalse(Monkey.is_monkey(fake_id)) cache_info_after_query = Monkey.is_monkey.storage.backend.cache_info() self.assertEqual(cache_info_after_query.hits, 2)
def get_edge_label(edge): node_service = monkey_island.cc.services.node.NodeService from_id = edge["from"] to_id = edge["to"] try: from_label = Monkey.get_label_by_id(from_id) except MonkeyNotFoundError: from_label = node_service.get_node_by_id(from_id)['domain_name'] if to_id == ObjectId("000000000000000000000000"): to_label = 'MonkeyIsland' else: if Monkey.is_monkey(to_id): to_label = Monkey.get_label_by_id(to_id) else: to_label = node_service.get_node_label( node_service.get_node_by_id(to_id)) return "%s %s %s" % (from_label, RIGHT_ARROW, to_label)