From 0e4dbfb078567e6594441ff57fd7d1fb797d00df Mon Sep 17 00:00:00 2001 From: Shay Nehmad Date: Tue, 7 May 2019 15:57:11 +0300 Subject: [PATCH] Replacing existing code with the new model API Only for is_dead calls --- monkey/monkey_island/cc/resources/local_run.py | 3 ++- monkey/monkey_island/cc/services/node.py | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/monkey/monkey_island/cc/resources/local_run.py b/monkey/monkey_island/cc/resources/local_run.py index d402a440c..54a16f518 100644 --- a/monkey/monkey_island/cc/resources/local_run.py +++ b/monkey/monkey_island/cc/resources/local_run.py @@ -7,6 +7,7 @@ from flask import request, jsonify, make_response import flask_restful from monkey_island.cc.environment.environment import env +from monkey_island.cc.models import Monkey from monkey_island.cc.resources.monkey_download import get_monkey_executable from monkey_island.cc.services.node import NodeService from monkey_island.cc.utils import local_ip_addresses @@ -57,7 +58,7 @@ class LocalRun(flask_restful.Resource): NodeService.update_dead_monkeys() island_monkey = NodeService.get_monkey_island_monkey() if island_monkey is not None: - is_monkey_running = not island_monkey["dead"] + is_monkey_running = not Monkey.get_single_monkey_by_id(island_monkey["_id"]).is_dead() else: is_monkey_running = False diff --git a/monkey/monkey_island/cc/services/node.py b/monkey/monkey_island/cc/services/node.py index 83474a2c3..a9dde51e2 100644 --- a/monkey/monkey_island/cc/services/node.py +++ b/monkey/monkey_island/cc/services/node.py @@ -4,6 +4,7 @@ from bson import ObjectId import monkey_island.cc.services.log from monkey_island.cc.database import mongo +from monkey_island.cc.models import Monkey from monkey_island.cc.services.edge import EdgeService from monkey_island.cc.utils import local_ip_addresses import socket @@ -124,7 +125,7 @@ class NodeService: monkey_type = "manual" if NodeService.get_monkey_manual_run(monkey) else "monkey" monkey_os = NodeService.get_monkey_os(monkey) - monkey_running = "" if monkey["dead"] else "_running" + monkey_running = "" if Monkey.get_single_monkey_by_id(monkey["_id"]).is_dead() else "_running" return "%s_%s%s" % (monkey_type, monkey_os, monkey_running) @staticmethod @@ -136,13 +137,14 @@ class NodeService: @staticmethod def monkey_to_net_node(monkey, for_report=False): label = monkey['hostname'] if for_report else NodeService.get_monkey_label(monkey) + is_monkey_dead = Monkey.get_single_monkey_by_id(monkey["_id"]).is_dead() return \ { "id": monkey["_id"], "label": label, "group": NodeService.get_monkey_group(monkey), "os": NodeService.get_monkey_os(monkey), - "dead": models.Monkey.objects(id=monkey["_id"])[0].is_dead(), + "dead": is_monkey_dead, "domain_name": "", "pba_results": monkey["pba_results"] if "pba_results" in monkey else [] }