run agent framework
This commit is contained in:
parent
45751f854b
commit
52438cfe6f
@ -5,6 +5,8 @@
|
|||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
from scalpels.db import api as db_api
|
from scalpels.db import api as db_api
|
||||||
|
import subprocess
|
||||||
|
import time
|
||||||
|
|
||||||
def _parse_agents_from_args(config):
|
def _parse_agents_from_args(config):
|
||||||
parsed_agents = set()
|
parsed_agents = set()
|
||||||
@ -29,11 +31,30 @@ def _parse_agents_from_file(config):
|
|||||||
parsed_agents.add(ag["name"])
|
parsed_agents.add(ag["name"])
|
||||||
return parsed_agents
|
return parsed_agents
|
||||||
|
|
||||||
|
# TODO this map should be saved in a config file
|
||||||
|
agents_map = {
|
||||||
|
"mysql": "",
|
||||||
|
"rabbit": "",
|
||||||
|
"traffic": "",
|
||||||
|
"rpctraffic": "",
|
||||||
|
}
|
||||||
|
|
||||||
def run(config):
|
def run(config):
|
||||||
print "command start: %s" % config
|
print "command start: %s" % config
|
||||||
agents = _parse_agents_from_args(config)
|
agents = _parse_agents_from_args(config)
|
||||||
agents |= _parse_agents_from_file(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 = []
|
rets = []
|
||||||
ret = db_api.result_create(data)
|
ret = db_api.result_create(data)
|
||||||
rets.append(ret.uuid)
|
rets.append(ret.uuid)
|
||||||
|
Loading…
Reference in New Issue
Block a user