Commit fe97c24c27e93216971b1e89df75658dfd5271cf

Authored by Alexis Koralewski
1 parent ee31d41e
Exists in dev

Add timer to get last get_all_cmds for AgentSST

Showing 2 changed files with 18 additions and 10 deletions   Show diff stats
CHANGELOG
... ... @@ -4,7 +4,8 @@
4 4 - fix typo obs config album name
5 5 - Template & css fix
6 6 - Remove gsc from Dockerfile
7   -
  7 + - Add timer to get last get_all_cmds for AgentSST
  8 +
8 9 03-01-2023 (AKo): v0.6.15.4
9 10 - new usage of delimiter in cmd parsing in agent_detail view
10 11  
... ...
src/core/pyros_django/dashboard/views.py
... ... @@ -217,15 +217,22 @@ def get_last_all_cmds(agent_name):
217 217 return AgentCmd.objects.get(id=last_agent_all_cmds.id)
218 218 else:
219 219 # AgentSST doesn't have do_stop cmd... (for the moment)
220   - last_agent_all_cmds = AgentCmd.send_cmd_from_to("System",agent_name,"get_all_cmds")
221   - max_wait_time = 3
222   - current_wait_time = 0
223   - 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():
224   - time.sleep(0.5)
225   - current_wait_time+=0.5
226   - if max_wait_time <= current_wait_time:
227   - break
228   - return AgentCmd.objects.get(id=last_agent_all_cmds.id)
  220 + datetime_now = datetime.datetime.now(tz=timezone.utc)
  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:
  224 +
  225 + 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 + 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)
229 236  
230 237 @login_required
231 238 def agent_detail(request, agent_name):
... ...