forked from p15670423/monkey
Use dedicated api to determine server is running
This commit is contained in:
parent
15b9ef1565
commit
260607b685
|
@ -67,11 +67,9 @@ class ControlClient(object):
|
|||
if ControlClient.proxies:
|
||||
debug_message += " through proxies: %s" % ControlClient.proxies
|
||||
LOG.debug(debug_message)
|
||||
# TODO: use different api call to check connectivity.
|
||||
requests.get("https://%s/api/monkey" % (server,),
|
||||
requests.get("https://%s/api?action=is-up" % (server,),
|
||||
verify=False,
|
||||
proxies=ControlClient.proxies)
|
||||
|
||||
break
|
||||
|
||||
except Exception as exc:
|
||||
|
|
|
@ -15,7 +15,6 @@ __author__ = 'Barak'
|
|||
|
||||
class Root(flask_restful.Resource):
|
||||
|
||||
@jwt_required()
|
||||
def get(self, action=None):
|
||||
if not action:
|
||||
action = request.args.get('action')
|
||||
|
@ -26,21 +25,26 @@ class Root(flask_restful.Resource):
|
|||
return Root.reset_db()
|
||||
elif action == "killall":
|
||||
return Root.kill_all()
|
||||
elif action == "is-up":
|
||||
return {'is-up': True}
|
||||
else:
|
||||
return make_response(400, {'error': 'unknown action'})
|
||||
|
||||
@staticmethod
|
||||
@jwt_required()
|
||||
def get_server_info():
|
||||
return jsonify(ip_addresses=local_ip_addresses(), mongo=str(mongo.db),
|
||||
completed_steps=Root.get_completed_steps())
|
||||
|
||||
@staticmethod
|
||||
@jwt_required()
|
||||
def reset_db():
|
||||
[mongo.db[x].drop() for x in ['config', 'monkey', 'telemetry', 'node', 'edge', 'report']]
|
||||
ConfigService.init_config()
|
||||
return jsonify(status='OK')
|
||||
|
||||
@staticmethod
|
||||
@jwt_required()
|
||||
def kill_all():
|
||||
mongo.db.monkey.update({'dead': False}, {'$set': {'config.alive': False, 'modifytime': datetime.now()}},
|
||||
upsert=False,
|
||||
|
@ -48,6 +52,7 @@ class Root(flask_restful.Resource):
|
|||
return jsonify(status='OK')
|
||||
|
||||
@staticmethod
|
||||
@jwt_required()
|
||||
def get_completed_steps():
|
||||
is_any_exists = NodeService.is_any_monkey_exists()
|
||||
infection_done = NodeService.is_monkey_finished_running()
|
||||
|
|
Loading…
Reference in New Issue