Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added --hours cli option to all for finer control in deleting old or … #2012

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions api/tacticalrmm/agents/management/commands/bulk_delete_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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)

Expand Down
Loading