Commit 8a356bfe6a752ce7c60405b56dbde8adc1414255

Authored by Alexis Koralewski
1 parent ed0f85e2
Exists in dev

Fix get_all_cmds when it's the first time we're sending it

CHANGELOG
  1 +18-01-2023 (AKo): v0.6.16.1
  2 + - Fix get_all_cmds when it's the first time we're sending it
  3 +
1 4 16-01-2023 (AKo): v0.6.16.0
2 5 - Change redis container name to pyros-redis
3 6 - Renaming HOST_NAME env variable to WEBSERVER_HOST_NAME to avoid confusion
... ...
VERSION
1   -0.6.16.0
2 1 \ No newline at end of file
  2 +0.6.16.1
3 3 \ No newline at end of file
... ...
src/core/pyros_django/dashboard/views.py
... ... @@ -219,21 +219,27 @@ def get_last_all_cmds(agent_name):
219 219 # AgentSST doesn't have do_stop cmd... (for the moment)
220 220 datetime_now = datetime.datetime.now(tz=timezone.utc)
221 221 time_delta = datetime_now - datetime.timedelta(minutes=30)
222   - last_agent_all_cmds = AgentCmd.objects.filter(full_name="get_all_cmds",recipient=agent_name,state__contains="CMD_EXECUTED").latest("s_deposit_time")
223   - if time_delta <= last_agent_all_cmds.s_deposit_time:
  222 + last_agent_all_cmds = AgentCmd.objects.filter(full_name="get_all_cmds",recipient=agent_name,state__contains="CMD_EXECUTED")
  223 + if last_agent_all_cmds.exits() :
  224 + last_agent_all_cmds.latest("s_deposit_time")
  225 + if time_delta <= last_agent_all_cmds.s_deposit_time:
224 226  
  227 + last_agent_all_cmds = AgentCmd.send_cmd_from_to("System",agent_name,"get_all_cmds")
  228 + max_wait_time = 3
  229 + current_wait_time = 0
  230 + while not AgentCmd.objects.get(id=last_agent_all_cmds.id).is_executed() and not AgentCmd.objects.get(id=last_agent_all_cmds.id).is_exec_error():
  231 + time.sleep(0.5)
  232 + current_wait_time+=0.5
  233 + if max_wait_time <= current_wait_time:
  234 + break
  235 + return AgentCmd.objects.get(id=last_agent_all_cmds.id)
  236 + else:
  237 + return AgentCmd.objects.get(id=last_agent_all_cmds.id)
  238 + else:
  239 + # There is no get_all_cmds for this agent in database, it's the first time we send this command, we have to wait until the command is executed.
225 240 last_agent_all_cmds = AgentCmd.send_cmd_from_to("System",agent_name,"get_all_cmds")
226   - max_wait_time = 3
227   - current_wait_time = 0
228 241 while not AgentCmd.objects.get(id=last_agent_all_cmds.id).is_executed() and not AgentCmd.objects.get(id=last_agent_all_cmds.id).is_exec_error():
229   - time.sleep(0.5)
230   - current_wait_time+=0.5
231   - if max_wait_time <= current_wait_time:
232   - break
233   - return AgentCmd.objects.get(id=last_agent_all_cmds.id)
234   - else:
235   - return AgentCmd.objects.get(id=last_agent_all_cmds.id)
236   -
  242 + time.sleep(0.5)
237 243 @login_required
238 244 def agent_detail(request, agent_name):
239 245 agent_log_path = os.path.join(os.environ.get("PROJECT_ROOT_PATH"),f"logs/{agent_name}/",f"{agent_name}.log")
... ...