From 52438cfe6ffb065944899e869b36120eecc2fba3 Mon Sep 17 00:00:00 2001 From: Kun Huang Date: Fri, 23 Oct 2015 02:02:43 +0800 Subject: [PATCH] run agent framework --- scalpels/cli/actions/start.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/scalpels/cli/actions/start.py b/scalpels/cli/actions/start.py index a987e11..5e10aaa 100644 --- a/scalpels/cli/actions/start.py +++ b/scalpels/cli/actions/start.py @@ -5,6 +5,8 @@ import os import json from scalpels.db import api as db_api +import subprocess +import time def _parse_agents_from_args(config): parsed_agents = set() @@ -29,11 +31,30 @@ def _parse_agents_from_file(config): parsed_agents.add(ag["name"]) return parsed_agents +# TODO this map should be saved in a config file +agents_map = { + "mysql": "", + "rabbit": "", + "traffic": "", + "rpctraffic": "", +} + def run(config): print "command start: %s" % config agents = _parse_agents_from_args(config) agents |= _parse_agents_from_file(config) - data = {"agents": list(agents)} + running_agents = [] + for ag in agents: + ag_exec = agents_map.get(ag) + if ag_exec: + ag_p = subprocess.Popen(ag_exec, stdout=subprocess.PIPE) + running_agents.append(ag_p) + time.sleep(15) + data = [] + for ag_p in running_agents: + stdout = ag_p.communicate()[0] + ag_p.terminate() + data.append(stdout) rets = [] ret = db_api.result_create(data) rets.append(ret.uuid)