Use dedicated api to determine server is running

This commit is contained in:
Itay Mizeretz 2018-02-28 18:26:31 +02:00
parent 15b9ef1565
commit 260607b685
2 changed files with 7 additions and 4 deletions

View File

@ -67,11 +67,9 @@ class ControlClient(object):
if ControlClient.proxies: if ControlClient.proxies:
debug_message += " through proxies: %s" % ControlClient.proxies debug_message += " through proxies: %s" % ControlClient.proxies
LOG.debug(debug_message) LOG.debug(debug_message)
# TODO: use different api call to check connectivity. requests.get("https://%s/api?action=is-up" % (server,),
requests.get("https://%s/api/monkey" % (server,),
verify=False, verify=False,
proxies=ControlClient.proxies) proxies=ControlClient.proxies)
break break
except Exception as exc: except Exception as exc:

View File

@ -15,7 +15,6 @@ __author__ = 'Barak'
class Root(flask_restful.Resource): class Root(flask_restful.Resource):
@jwt_required()
def get(self, action=None): def get(self, action=None):
if not action: if not action:
action = request.args.get('action') action = request.args.get('action')
@ -26,21 +25,26 @@ class Root(flask_restful.Resource):
return Root.reset_db() return Root.reset_db()
elif action == "killall": elif action == "killall":
return Root.kill_all() return Root.kill_all()
elif action == "is-up":
return {'is-up': True}
else: else:
return make_response(400, {'error': 'unknown action'}) return make_response(400, {'error': 'unknown action'})
@staticmethod @staticmethod
@jwt_required()
def get_server_info(): def get_server_info():
return jsonify(ip_addresses=local_ip_addresses(), mongo=str(mongo.db), return jsonify(ip_addresses=local_ip_addresses(), mongo=str(mongo.db),
completed_steps=Root.get_completed_steps()) completed_steps=Root.get_completed_steps())
@staticmethod @staticmethod
@jwt_required()
def reset_db(): def reset_db():
[mongo.db[x].drop() for x in ['config', 'monkey', 'telemetry', 'node', 'edge', 'report']] [mongo.db[x].drop() for x in ['config', 'monkey', 'telemetry', 'node', 'edge', 'report']]
ConfigService.init_config() ConfigService.init_config()
return jsonify(status='OK') return jsonify(status='OK')
@staticmethod @staticmethod
@jwt_required()
def kill_all(): def kill_all():
mongo.db.monkey.update({'dead': False}, {'$set': {'config.alive': False, 'modifytime': datetime.now()}}, mongo.db.monkey.update({'dead': False}, {'$set': {'config.alive': False, 'modifytime': datetime.now()}},
upsert=False, upsert=False,
@ -48,6 +52,7 @@ class Root(flask_restful.Resource):
return jsonify(status='OK') return jsonify(status='OK')
@staticmethod @staticmethod
@jwt_required()
def get_completed_steps(): def get_completed_steps():
is_any_exists = NodeService.is_any_monkey_exists() is_any_exists = NodeService.is_any_monkey_exists()
infection_done = NodeService.is_monkey_finished_running() infection_done = NodeService.is_monkey_finished_running()