From c6a5741c964a9c14a93d558bb3cff3c7bff374e8 Mon Sep 17 00:00:00 2001 From: Itay Mizeretz Date: Tue, 17 Oct 2017 12:13:46 +0300 Subject: [PATCH] Force kill only affects live monkeys, and is reset once a monkey is dead --- monkey_island/cc/resources/root.py | 2 +- monkey_island/cc/services/node.py | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/monkey_island/cc/resources/root.py b/monkey_island/cc/resources/root.py index 781926818..3f5ee9dd4 100644 --- a/monkey_island/cc/resources/root.py +++ b/monkey_island/cc/resources/root.py @@ -29,7 +29,7 @@ class Root(flask_restful.Resource): ConfigService.init_config() return jsonify(status='OK') elif action == "killall": - mongo.db.monkey.update({}, {'$set': {'config.alive': False, 'modifytime': datetime.now()}}, upsert=False, + mongo.db.monkey.update({'dead': False}, {'$set': {'config.alive': False, 'modifytime': datetime.now()}}, upsert=False, multi=True) return jsonify(status='OK') else: diff --git a/monkey_island/cc/services/node.py b/monkey_island/cc/services/node.py index 24ab18cc2..3acd66b75 100644 --- a/monkey_island/cc/services/node.py +++ b/monkey_island/cc/services/node.py @@ -209,8 +209,14 @@ class NodeService: @staticmethod def set_monkey_dead(monkey, is_dead): + props_to_set = {'dead': is_dead} + + # Cancel the force kill once monkey died + if is_dead: + props_to_set['config.alive'] = True + mongo.db.monkey.update({"guid": monkey['guid']}, - {'$set': {'dead': is_dead}}, + {'$set': props_to_set}, upsert=False) @staticmethod @@ -255,9 +261,10 @@ class NodeService: {'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, 'modifytime': datetime.now()}}, upsert=False, multi=True) + {'$set': {'dead': True, 'config.alive': True, 'modifytime': datetime.now()}}, upsert=False, multi=True) @staticmethod def is_any_monkey_alive():