Commit 33623baa authored by Jason Frisvold's avatar Jason Frisvold
Browse files

- Handle remote output directory missing

- Add results to the database
parent c7fcd221
......@@ -287,7 +287,12 @@ def push_configs(server_conn, configlist, config_path):
def get_results(dbhandle, server_conn, output_dir, server_id):
logger.info('Retrieving results from server')
file_list = server_conn.listdir(output_dir)
try:
file_list = server_conn.listdir(output_dir)
except IOError, e:
logger.info('IO Error retrieving file list - [{0}] - {1}'
.format(e.args[0], e.args[1]))
file_list = []
logger.info('Retrieved list of files - {0}'.format(file_list))
......@@ -331,6 +336,28 @@ def process_results(dbhandle):
output = decrypter.stdout.read()
nmapxml = ET.fromstring(output)
timer_id = nmapfile.split('.')[len(nmapfile.split('.')) - 4]
sql = 'SELECT cloud_id, spawn_id, target_id FROM timers WHERE id = %s'
try:
cur = dbhandle.cursor()
cur.execute(sql, [timer_id])
dbhandle.commit()
except MySQLdb.Error, e:
logger.exception("MySQL Error [{0}]: {1}"
.format(e.args[0], e.args[1]))
row = cur.fetchone()
if (len(row) > 0):
logger.debug('Database Retrieval : {0}'.format(str(row)))
cloud_id = row[0]
spawn_id = row[1]
target_id = row[2]
else:
cloud_id = 0
spawn_id = 0
target_id = 0
# Pull stats from results
# NMAP version (scaninfo.version)
......@@ -359,7 +386,19 @@ def process_results(dbhandle):
# Update the database with the results
# diff between previous and current stats? (ndiff?)
sql = '''INSERT INTO results (id, cloud_id, spawn_id, target_id,
xml_version, start_time, end_time, elapsed_time, exit_status,
port_count, filename) VALUES (NULL, %s, %s, %s, %s, %s, %s, %s,
%s, %s, %s)'''
try:
cur = dbhandle.cursor()
cur.execute(sql, [cloud_id, spawn_id, target_id, version, starttime,
endtime, runtime, status, portcount, nmapfile])
dbhandle.commit()
except MySQLdb.Error, e:
logger.exception("MySQL Error [{0}]: {1}"
.format(e.args[0], e.args[1]))
# Move the processed file into the central repo
scantime = datetime.fromtimestamp(int(starttime))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment