diff --git a/api/tacticalrmm/agents/management/commands/bulk_delete_agents.py b/api/tacticalrmm/agents/management/commands/bulk_delete_agents.py index 85b1ba8827..2e4e6f0afa 100644 --- a/api/tacticalrmm/agents/management/commands/bulk_delete_agents.py +++ b/api/tacticalrmm/agents/management/commands/bulk_delete_agents.py @@ -18,6 +18,11 @@ def add_arguments(self, parser): type=int, help="Delete agents that have not checked in for this many days", ) + parser.add_argument( + "--hours", + type=int, + help="Delete agents that have not checked in for this many hours", + ) parser.add_argument( "--agentver", type=str, @@ -46,16 +51,17 @@ def add_arguments(self, parser): def handle(self, *args, **kwargs): days = kwargs["days"] + hours = kwargs["hours"] 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 and not hostname: + if not days and not hours 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, client or hostname" + "Must have at least one parameter: days, hours, agentver, site, client or hostname" ) ) return @@ -66,6 +72,10 @@ def handle(self, *args, **kwargs): overdue = djangotime.now() - djangotime.timedelta(days=days) agents = agents.filter(last_seen__lt=overdue) + if hours: + overdue = djangotime.now() - djangotime.timedelta(hours=hours) + agents = agents.filter(last_seen__lt=overdue) + if site: agents = agents.filter(site__name=site)