diff --git a/monkey/monkey_island/cc/models/monkey.py b/monkey/monkey_island/cc/models/monkey.py index 3d941d512..74967878c 100644 --- a/monkey/monkey_island/cc/models/monkey.py +++ b/monkey/monkey_island/cc/models/monkey.py @@ -44,7 +44,6 @@ class Monkey(Document): ip_addresses = ListField(StringField()) networks = ListField() launch_time = FloatField() - keepalive = DateTimeField() modifytime = DateTimeField() # TODO make "parent" an embedded document, so this can be removed and the schema explained ( # and validated) verbosely. diff --git a/monkey/monkey_island/cc/resources/client_run.py b/monkey/monkey_island/cc/resources/client_run.py index 79a8c214b..4c2d02180 100644 --- a/monkey/monkey_island/cc/resources/client_run.py +++ b/monkey/monkey_island/cc/resources/client_run.py @@ -15,7 +15,6 @@ class ClientRun(flask_restful.Resource): monkey = NodeService.get_monkey_island_monkey() else: monkey = NodeService.get_monkey_by_ip(client_ip) - NodeService.update_dead_monkeys() if monkey is not None: is_monkey_running = not monkey["dead"] else: diff --git a/monkey/monkey_island/cc/resources/local_run.py b/monkey/monkey_island/cc/resources/local_run.py index 49517dbdb..5645557da 100644 --- a/monkey/monkey_island/cc/resources/local_run.py +++ b/monkey/monkey_island/cc/resources/local_run.py @@ -12,7 +12,6 @@ from monkey_island.cc.services.run_local_monkey import LocalMonkeyRunService class LocalRun(flask_restful.Resource): @jwt_required def get(self): - NodeService.update_dead_monkeys() island_monkey = NodeService.get_monkey_island_monkey() if island_monkey is not None: is_monkey_running = not Monkey.get_single_monkey_by_id(island_monkey["_id"]).is_dead() diff --git a/monkey/monkey_island/cc/resources/monkey.py b/monkey/monkey_island/cc/resources/monkey.py index 07e96a4b3..9e4cf47af 100644 --- a/monkey/monkey_island/cc/resources/monkey.py +++ b/monkey/monkey_island/cc/resources/monkey.py @@ -1,7 +1,6 @@ import json from datetime import datetime -import dateutil.parser import flask_restful from flask import request @@ -21,7 +20,6 @@ class Monkey(flask_restful.Resource): # Used by monkey. can't secure. def get(self, guid=None, config_format=None, **kw): - NodeService.update_dead_monkeys() # refresh monkeys status if not guid: guid = request.args.get("guid") @@ -45,10 +43,6 @@ class Monkey(flask_restful.Resource): monkey_json = json.loads(request.data) update = {"$set": {"modifytime": datetime.now()}} monkey = NodeService.get_monkey_by_guid(guid) - if "keepalive" in monkey_json: - update["$set"]["keepalive"] = dateutil.parser.parse(monkey_json["keepalive"]) - else: - update["$set"]["keepalive"] = datetime.now() if "config" in monkey_json: update["$set"]["config"] = monkey_json["config"] if "config_error" in monkey_json: @@ -70,10 +64,6 @@ class Monkey(flask_restful.Resource): with agent_killing_mutex: monkey_json = json.loads(request.data) monkey_json["dead"] = False - if "keepalive" in monkey_json: - monkey_json["keepalive"] = dateutil.parser.parse(monkey_json["keepalive"]) - else: - monkey_json["keepalive"] = datetime.now() monkey_json["modifytime"] = datetime.now() diff --git a/monkey/monkey_island/cc/services/node.py b/monkey/monkey_island/cc/services/node.py index a006d9d7f..688f67f92 100644 --- a/monkey/monkey_island/cc/services/node.py +++ b/monkey/monkey_island/cc/services/node.py @@ -1,5 +1,5 @@ import socket -from datetime import datetime, timedelta +from datetime import datetime from bson import ObjectId @@ -295,22 +295,6 @@ class NodeService: def set_node_propagated(node_id): mongo.db.node.update({"_id": node_id}, {"$set": {"propagated": True}}) - @staticmethod - def update_dead_monkeys(): - # Update dead monkeys only if no living monkey transmitted keepalive in the last 10 minutes - if mongo.db.monkey.find_one( - {"dead": {"$ne": True}, "keepalive": {"$gte": datetime.now() - timedelta(minutes=10)}} - ): - return - - # config.alive is changed to true to cancel the force kill of dead monkeys - mongo.db.monkey.update( - {"keepalive": {"$lte": datetime.now() - timedelta(minutes=10)}, "dead": {"$ne": True}}, - {"$set": {"dead": True, "config.alive": True, "modifytime": datetime.now()}}, - upsert=False, - multi=True, - ) - @staticmethod def is_any_monkey_alive(): all_monkeys = models.Monkey.objects()