append results to tracer
so a tracer could have: [(timestamp, data), ...] # result from yesterday [(timestamp, data), ...] # result from today Change-Id: Ief409c1401e9972da576657db74a3388c9422356
This commit is contained in:
parent
c960bba7a0
commit
03ce2e4901
@ -30,7 +30,8 @@ class TracerEndpoint(object):
|
||||
ret.append({"name":tr.name,
|
||||
"tpl":tr.template,
|
||||
"running":tr.is_running,
|
||||
"pid":tr.pid})
|
||||
"pid":tr.pid,
|
||||
"results":tr.results})
|
||||
return ret
|
||||
|
||||
def start_tracers(self, ctx, tracers):
|
||||
|
@ -5,9 +5,21 @@
|
||||
from scalpels.client.api import api as agent_api
|
||||
from scalpels.client.utils import generate_multiple_result_html
|
||||
from scalpels.client.utils import pprint_result
|
||||
from scalpels.client.actions.start import _parse_agents_from_args
|
||||
|
||||
|
||||
def run(config):
|
||||
if config["uuid"] and config["agent"]:
|
||||
raise ValueError("Can't stop both a task and a tracer")
|
||||
elif config["agent"]:
|
||||
req_tr = _parse_agents_from_args(config)
|
||||
all_tr = {t["name"]:t for t in agent_api.get_tracer_list()}
|
||||
for tr in req_tr:
|
||||
for ret_uuid in all_tr[tr]["results"]:
|
||||
ret = agent_api.get_result(ret_uuid)
|
||||
pprint_result(ret)
|
||||
else:
|
||||
|
||||
task = agent_api.try_get_task_from_config(config)
|
||||
|
||||
print "reporting task: <%s>" % task["uuid"]
|
||||
|
@ -9,10 +9,11 @@ from scalpels.client.actions.start import _parse_agents_from_args
|
||||
def run(config):
|
||||
print "command stop: %s" % config
|
||||
if config["uuid"] and config["agent"]:
|
||||
raise ValueError("")
|
||||
elif config["uuid"]:
|
||||
task = agent_api.try_get_task_from_config(config)
|
||||
agent_api.stop_task(task["uuid"])
|
||||
raise ValueError("Can't stop both a task and a tracer")
|
||||
elif config["agent"]:
|
||||
agents = _parse_agents_from_args(config)
|
||||
agent_api.stop_tracers(agents)
|
||||
else:
|
||||
# no tracers are specified so trying to find a task
|
||||
task = agent_api.try_get_task_from_config(config)
|
||||
agent_api.stop_task(task["uuid"])
|
||||
|
@ -37,6 +37,7 @@ def main():
|
||||
report.add_argument("--last", action="store_true", dest="last", help="report the last task")
|
||||
report.add_argument("--html", action="store_true", dest="html", help="report html to stdout instead of pretty print")
|
||||
report.add_argument("uuid", type=str, default="", nargs="?", help="report the last task")
|
||||
report.add_argument("-a", "--agent", action="append", dest="agent", help="agent(s) to stop", required=False)
|
||||
|
||||
# setup sca result --list
|
||||
result = subparsers.add_parser("result")
|
||||
|
@ -60,14 +60,12 @@ def save_result_to_task():
|
||||
co.start()
|
||||
lock = co.get_lock("task_update_lock")
|
||||
with lock:
|
||||
task = db_api.task_get(task_uuid)
|
||||
results = copy(task.results)
|
||||
for ret in parse_func(out):
|
||||
ret = db_api.result_create(**ret)
|
||||
print "[LOG] appending result with id %s" % ret.uuid
|
||||
results.append(ret.uuid)
|
||||
db_api.task_append_result(task_uuid, ret.uuid)
|
||||
db_api.tracer_append_result(ag, ret.uuid)
|
||||
print "[LOG] update tas with result %s" % task_uuid
|
||||
db_api.task_update(task_uuid, results=results)
|
||||
time.sleep(2)
|
||||
co.stop()
|
||||
|
||||
|
@ -39,6 +39,9 @@ def task_get(task_uuid, fuzzy=False):
|
||||
def task_update(task_uuid, results=None, pids=None):
|
||||
return IMPL.task_update(task_uuid, results, pids)
|
||||
|
||||
def task_append_result(task_uuid, result_uuid):
|
||||
return IMPL.task_append_result(task_uuid, result_uuid)
|
||||
|
||||
def task_get_last():
|
||||
return IMPL.task_get_last()
|
||||
|
||||
@ -77,3 +80,6 @@ def tracer_get(tracer):
|
||||
|
||||
def tracer_update(tracer, running=None, pid=None):
|
||||
return IMPL.tracer_update(tracer, running, pid)
|
||||
|
||||
def tracer_append_result(tracer, result_uuid):
|
||||
return IMPL.tracer_append_result(tracer, result_uuid)
|
||||
|
@ -77,7 +77,14 @@ def task_update(task_uuid, results=None, pids=None):
|
||||
task.save(session=session)
|
||||
return task
|
||||
|
||||
|
||||
def task_append_result(task_uuid, result_uuid):
|
||||
session = get_session()
|
||||
task = model_query(models.Task, session=session).filter_by(uuid=task_uuid).first()
|
||||
new = copy(task.results)
|
||||
new.append(result_uuid)
|
||||
task.update({"results":new})
|
||||
task.save(session=session)
|
||||
return task
|
||||
|
||||
def task_get(task_uuid, fuzzy=False):
|
||||
if not fuzzy:
|
||||
@ -119,7 +126,7 @@ def get_all_results():
|
||||
|
||||
def register_tracer(name, template):
|
||||
tracer = models.Tracer()
|
||||
tracer.update({"name":name, "template": template})
|
||||
tracer.update({"name":name, "template": template, "results":[]})
|
||||
tracer.save()
|
||||
return tracer
|
||||
|
||||
@ -155,3 +162,12 @@ def tracer_update(tracer_name, running=None, pid=None):
|
||||
tracer.update(_update)
|
||||
tracer.save(session=session)
|
||||
return tracer
|
||||
|
||||
def tracer_append_result(tracer_name, result_uuid):
|
||||
session = get_session()
|
||||
tracer = model_query(models.Tracer, session=session).filter_by(name=tracer_name).first()
|
||||
new = copy(tracer.results)
|
||||
new.append(result_uuid)
|
||||
tracer.update({"results":new})
|
||||
tracer.save(session=session)
|
||||
return tracer
|
||||
|
@ -57,4 +57,5 @@ class Tracer(BASE, ScalpelsBase):
|
||||
name = Column(String(20), nullable=False, unique=True)
|
||||
template = Column(String(20), nullable=False)
|
||||
is_running = Column(Boolean(), default=False)
|
||||
results = Column(JSONEncodedData, nullable=False)
|
||||
pid = Column(Integer(), default=-1)
|
||||
|
Loading…
Reference in New Issue
Block a user