From 59dcdd5393cd16efe347ba5af5a9524fefb57bd8 Mon Sep 17 00:00:00 2001 From: Supermanu <manueltondeur@gmail.com> Date: Thu, 30 Mar 2023 12:21:48 +0200 Subject: [PATCH] Enable hostname filtering for bulk delete agents --- .../management/commands/bulk_delete_agents.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/api/tacticalrmm/agents/management/commands/bulk_delete_agents.py b/api/tacticalrmm/agents/management/commands/bulk_delete_agents.py index 895e2352..2390aafc 100644 --- a/api/tacticalrmm/agents/management/commands/bulk_delete_agents.py +++ b/api/tacticalrmm/agents/management/commands/bulk_delete_agents.py @@ -33,6 +33,11 @@ class Command(BaseCommand): type=str, help="Delete agents that belong to the specified client", ) + parser.add_argument( + "--hostname", + type=str, + help="Delete agents with hostname starting with argument", + ) parser.add_argument( "--delete", action="store_true", @@ -44,12 +49,13 @@ class Command(BaseCommand): agentver = kwargs["agentver"] site = kwargs["site"] client = kwargs["client"] + hostname = kwargs["hostname"] delete = kwargs["delete"] - if not days and not agentver and not site and not client: + if not days and not agentver and not site and not client and not hostname: self.stdout.write( self.style.ERROR( - "Must have at least one parameter: days, agentver, site, or client" + "Must have at least one parameter: days, agentver, site, client or hostname" ) ) return @@ -70,6 +76,9 @@ class Command(BaseCommand): if client: agents = [i for i in q if i.client.name == client] + if hostname: + agents = [i for i in q if i.hostname.startswith(hostname)] + if not agents: self.stdout.write(self.style.ERROR("No agents matched")) return