in export.py [0:0]
def start_exporting(count):
logging.debug(str.format("start_exporting - count={}, len(exporting_agents)={} (MAX_EXPORTS={}), len(agents_queue)={}", count, len(exporting_agents), MAX_EXPORTS, len(agents_queue)))
while len(exporting_agents) < MAX_EXPORTS and len(agents_queue) > 0:
agent = agents_queue.pop(0)
count += 1
logging.info(str.format("Starting export for agent {} ({}/{})", agent['agentId'], str(count), str(total_exports)))
reg_time = get_time(agent['registeredTime'])
last_health_time = get_time(agent['lastHealthPingTime'])
if start_input != None:
start_time = max(reg_time, start_input)
else:
start_time = reg_time
if end_input != None:
final_end_time = min(last_health_time, end_input)
else:
final_end_time = last_health_time
if start_time >= final_end_time:
logging.info(str.format("Nothing to export for agent {} since registeredTime={} and lastHealthPingTime={}", agent['agentId'], reg_time, last_health_time))
continue
logging.info(str.format("Export for agent {} will start at {} (registeredTime={}) and end at {} (lastHealthPingTime={})", agent['agentId'], start_time, reg_time, final_end_time, last_health_time))
try:
response = client.start_export_task(filters=[{'name': 'agentIds', 'values': [agent['agentId']], 'condition': 'EQUALS'}],
startTime = start_time, endTime = min(start_time + datetime.timedelta(days=3), final_end_time))
exporting_agents[agent['agentId']] = [start_time, final_end_time, response['exportId']]
except Exception as e:
if (type(e).__name__ == "OperationNotPermittedException"):
last_word = e.message.split()[-1]
if last_word == "another.":
# Full message: You have reached limit of maximum allowed concurrent exports. Please wait for current export tasks to finish before starting another.
agents_queue.insert(0, agent)
count -= 1
logging.info(str.format("start_exporting - Maximum number of concurrent exports exceeded. Requeuing agent {} and waiting...", agent['agentId']))
time.sleep(8)
else:
# Full message: An error occurred (OperationNotPermittedException) when calling the StartExportTask operation: A successful export is already present Export ID: <export id>
logging.info(str.format("start_exporting - OperationNotPermittedException for agent {}: {}", agent['agentId'], e.message))
exporting_agents[agent['agentId']] = [start_time, final_end_time, last_word]
else:
raise(e)
return count