check updates task rework to run all agents in parallel
This commit is contained in:
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"python.pythonPath": "api/env/bin/python",
|
||||
"python.pythonPath": "api/tacticalrmm/env/bin/python",
|
||||
"python.formatting.provider": "black",
|
||||
"editor.formatOnSave": true,
|
||||
"vetur.format.defaultFormatter.js": "prettier",
|
||||
|
@@ -212,6 +212,43 @@ class Agent(models.Model):
|
||||
except:
|
||||
return ["unknown disk"]
|
||||
|
||||
|
||||
# auto approves updates
|
||||
def approve_updates(self):
|
||||
patch_policy = self.get_patch_policy()
|
||||
|
||||
updates = list()
|
||||
if patch_policy.critical == "approve":
|
||||
updates += self.winupdates.filter(
|
||||
severity="Critical", installed=False
|
||||
).exclude(action="approve")
|
||||
|
||||
if patch_policy.important == "approve":
|
||||
updates += self.winupdates.filter(
|
||||
severity="Important", installed=False
|
||||
).exclude(action="approve")
|
||||
|
||||
if patch_policy.moderate == "approve":
|
||||
updates += self.winupdates.filter(
|
||||
severity="Moderate", installed=False
|
||||
).exclude(action="approve")
|
||||
|
||||
if patch_policy.low == "approve":
|
||||
updates += self.winupdates.filter(severity="Low", installed=False).exclude(
|
||||
action="approve"
|
||||
)
|
||||
|
||||
if patch_policy.other == "approve":
|
||||
updates += self.winupdates.filter(severity="", installed=False).exclude(
|
||||
action="approve"
|
||||
)
|
||||
|
||||
for update in updates:
|
||||
update.action = "approve"
|
||||
update.save(update_fields=["action"])
|
||||
|
||||
|
||||
# returns agent policy merged with a client or site specific policy
|
||||
def get_patch_policy(self):
|
||||
|
||||
# check if site has a patch policy and if so use it
|
||||
|
@@ -13,49 +13,19 @@ logger.configure(**settings.LOG_CONFIG)
|
||||
|
||||
@app.task
|
||||
def auto_approve_updates_task():
|
||||
# scheduled task that checks and approves updates daily
|
||||
|
||||
agents = Agent.objects.all()
|
||||
|
||||
for agent in agents:
|
||||
|
||||
# check for updates on agent
|
||||
check_for_updates_task(agent.pk, wait=False)
|
||||
|
||||
patch_policy = agent.get_patch_policy()
|
||||
|
||||
updates = list()
|
||||
if patch_policy.critical == "approve":
|
||||
updates += agent.winupdates.filter(
|
||||
severity="Critical", installed=False
|
||||
).exclude(action="approve")
|
||||
|
||||
if patch_policy.important == "approve":
|
||||
updates += agent.winupdates.filter(
|
||||
severity="Important", installed=False
|
||||
).exclude(action="approve")
|
||||
|
||||
if patch_policy.moderate == "approve":
|
||||
updates += agent.winupdates.filter(
|
||||
severity="Moderate", installed=False
|
||||
).exclude(action="approve")
|
||||
|
||||
if patch_policy.low == "approve":
|
||||
updates += agent.winupdates.filter(severity="Low", installed=False).exclude(
|
||||
action="approve"
|
||||
)
|
||||
|
||||
if patch_policy.other == "approve":
|
||||
updates += agent.winupdates.filter(severity="", installed=False).exclude(
|
||||
action="approve"
|
||||
)
|
||||
|
||||
for update in updates:
|
||||
update.action = "approve"
|
||||
update.save(update_fields=["action"])
|
||||
check_for_updates_task.delay(agent.pk, wait=False, auto_approve=True)
|
||||
|
||||
|
||||
@app.task
|
||||
def check_agent_update_schedule_task():
|
||||
# scheduled task that installs updates on agents if enabled
|
||||
agents = Agent.objects.all()
|
||||
|
||||
for agent in agents:
|
||||
@@ -100,11 +70,11 @@ def check_agent_update_schedule_task():
|
||||
],
|
||||
)
|
||||
agent.patches_last_installed = now
|
||||
agent.save()
|
||||
agent.save(update_fields=["patches_last_installed"])
|
||||
|
||||
|
||||
@app.task
|
||||
def check_for_updates_task(pk, wait=False):
|
||||
def check_for_updates_task(pk, wait=False, auto_approve=False):
|
||||
|
||||
if wait:
|
||||
sleep(70)
|
||||
@@ -194,4 +164,8 @@ def check_for_updates_task(pk, wait=False):
|
||||
agent.needs_reboot = False
|
||||
agent.save(update_fields=["needs_reboot"])
|
||||
|
||||
# approve updates if specified
|
||||
if auto_approve:
|
||||
agent.approve_updates()
|
||||
|
||||
return "ok"
|
||||
|
Reference in New Issue
Block a user