fix superseded windows defender updates

This commit is contained in:
wh1te909
2021-01-29 02:37:51 +00:00
parent 1731b05ad0
commit 25059de8e1
4 changed files with 11 additions and 0 deletions

View File

@@ -332,6 +332,7 @@ class WinUpdater(APIView):
update.installed = True
update.save(update_fields=["result", "downloaded", "installed"])
agent.delete_superseded_updates()
return Response("ok")
# agent calls this after it's finished installing all patches
@@ -357,6 +358,7 @@ class WinUpdater(APIView):
f"{agent.hostname} is rebooting after updates were installed."
)
agent.delete_superseded_updates()
return Response("ok")

View File

@@ -176,6 +176,7 @@ class NatsWinUpdates(APIView):
asyncio.run(agent.nats_cmd({"func": "rebootnow"}, wait=False))
logger.info(f"{agent.hostname} is rebooting after updates were installed.")
agent.delete_superseded_updates()
return Response("ok")
def patch(self, request):
@@ -199,6 +200,7 @@ class NatsWinUpdates(APIView):
u.result = "failed"
u.save(update_fields=["result"])
agent.delete_superseded_updates()
return Response("ok")
def post(self, request):
@@ -233,4 +235,5 @@ class NatsWinUpdates(APIView):
revision_number=update["revision_number"],
).save()
agent.delete_superseded_updates()
return Response("ok")

View File

@@ -21,6 +21,7 @@ def auto_approve_updates_task():
agents = Agent.objects.only("pk", "version", "last_seen", "overdue_time")
for agent in agents:
agent.delete_superseded_updates()
try:
agent.approve_updates()
except:
@@ -53,6 +54,7 @@ def check_agent_update_schedule_task():
]
for agent in online:
agent.delete_superseded_updates()
install = False
patch_policy = agent.get_patch_policy()
@@ -126,6 +128,7 @@ def bulk_install_updates_task(pks: List[int]) -> None:
chunks = (agents[i : i + 40] for i in range(0, len(agents), 40))
for chunk in chunks:
for agent in chunk:
agent.delete_superseded_updates()
nats_data = {
"func": "installwinupdates",
"guids": agent.get_approved_update_guids(),
@@ -142,6 +145,7 @@ def bulk_check_for_updates_task(pks: List[int]) -> None:
chunks = (agents[i : i + 40] for i in range(0, len(agents), 40))
for chunk in chunks:
for agent in chunk:
agent.delete_superseded_updates()
asyncio.run(agent.nats_cmd({"func": "getwinupdates"}, wait=False))
time.sleep(0.05)
time.sleep(15)

View File

@@ -22,6 +22,7 @@ def get_win_updates(request, pk):
@api_view()
def run_update_scan(request, pk):
agent = get_object_or_404(Agent, pk=pk)
agent.delete_superseded_updates()
if pyver.parse(agent.version) < pyver.parse("1.3.0"):
return notify_error("Requires agent version 1.3.0 or greater")
@@ -32,6 +33,7 @@ def run_update_scan(request, pk):
@api_view()
def install_updates(request, pk):
agent = get_object_or_404(Agent, pk=pk)
agent.delete_superseded_updates()
if pyver.parse(agent.version) < pyver.parse("1.3.0"):
return notify_error("Requires agent version 1.3.0 or greater")