run agent framework

This commit is contained in:
Kun Huang 2015-10-23 02:02:43 +08:00
parent 45751f854b
commit 52438cfe6f

View File

@ -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)