forked from p15670423/monkey
Replacing existing code with the new model API
Only for is_dead calls
This commit is contained in:
parent
3c6cda03af
commit
0e4dbfb078
|
@ -7,6 +7,7 @@ from flask import request, jsonify, make_response
|
||||||
import flask_restful
|
import flask_restful
|
||||||
|
|
||||||
from monkey_island.cc.environment.environment import env
|
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.resources.monkey_download import get_monkey_executable
|
||||||
from monkey_island.cc.services.node import NodeService
|
from monkey_island.cc.services.node import NodeService
|
||||||
from monkey_island.cc.utils import local_ip_addresses
|
from monkey_island.cc.utils import local_ip_addresses
|
||||||
|
@ -57,7 +58,7 @@ class LocalRun(flask_restful.Resource):
|
||||||
NodeService.update_dead_monkeys()
|
NodeService.update_dead_monkeys()
|
||||||
island_monkey = NodeService.get_monkey_island_monkey()
|
island_monkey = NodeService.get_monkey_island_monkey()
|
||||||
if island_monkey is not None:
|
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:
|
else:
|
||||||
is_monkey_running = False
|
is_monkey_running = False
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ from bson import ObjectId
|
||||||
|
|
||||||
import monkey_island.cc.services.log
|
import monkey_island.cc.services.log
|
||||||
from monkey_island.cc.database import mongo
|
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.services.edge import EdgeService
|
||||||
from monkey_island.cc.utils import local_ip_addresses
|
from monkey_island.cc.utils import local_ip_addresses
|
||||||
import socket
|
import socket
|
||||||
|
@ -124,7 +125,7 @@ class NodeService:
|
||||||
monkey_type = "manual" if NodeService.get_monkey_manual_run(monkey) else "monkey"
|
monkey_type = "manual" if NodeService.get_monkey_manual_run(monkey) else "monkey"
|
||||||
|
|
||||||
monkey_os = NodeService.get_monkey_os(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)
|
return "%s_%s%s" % (monkey_type, monkey_os, monkey_running)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -136,13 +137,14 @@ class NodeService:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def monkey_to_net_node(monkey, for_report=False):
|
def monkey_to_net_node(monkey, for_report=False):
|
||||||
label = monkey['hostname'] if for_report else NodeService.get_monkey_label(monkey)
|
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 \
|
return \
|
||||||
{
|
{
|
||||||
"id": monkey["_id"],
|
"id": monkey["_id"],
|
||||||
"label": label,
|
"label": label,
|
||||||
"group": NodeService.get_monkey_group(monkey),
|
"group": NodeService.get_monkey_group(monkey),
|
||||||
"os": NodeService.get_monkey_os(monkey),
|
"os": NodeService.get_monkey_os(monkey),
|
||||||
"dead": models.Monkey.objects(id=monkey["_id"])[0].is_dead(),
|
"dead": is_monkey_dead,
|
||||||
"domain_name": "",
|
"domain_name": "",
|
||||||
"pba_results": monkey["pba_results"] if "pba_results" in monkey else []
|
"pba_results": monkey["pba_results"] if "pba_results" in monkey else []
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue