From 8cd2544f78ad3abec65dc6be1cb5ee4986bde7bc Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Fri, 26 Feb 2021 22:05:42 +0000 Subject: [PATCH] add new management command --- .../commands/bulk_change_checkin.py | 93 +++++++++++++++++++ docs/docs/install_server.md | 6 +- docs/docs/management_cmds.md | 30 +++++- 3 files changed, 125 insertions(+), 4 deletions(-) create mode 100644 api/tacticalrmm/agents/management/commands/bulk_change_checkin.py diff --git a/api/tacticalrmm/agents/management/commands/bulk_change_checkin.py b/api/tacticalrmm/agents/management/commands/bulk_change_checkin.py new file mode 100644 index 00000000..804e86a1 --- /dev/null +++ b/api/tacticalrmm/agents/management/commands/bulk_change_checkin.py @@ -0,0 +1,93 @@ +from django.core.management.base import BaseCommand + +from agents.models import Agent +from clients.models import Client, Site + + +class Command(BaseCommand): + help = "Bulk update agent offline/overdue time" + + def add_arguments(self, parser): + parser.add_argument("time", type=int, help="Time in minutes") + parser.add_argument( + "--client", + type=str, + help="Client Name", + ) + parser.add_argument( + "--site", + type=str, + help="Site Name", + ) + parser.add_argument( + "--offline", + action="store_true", + help="Offline", + ) + parser.add_argument( + "--overdue", + action="store_true", + help="Overdue", + ) + parser.add_argument( + "--all", + action="store_true", + help="All agents", + ) + + def handle(self, *args, **kwargs): + time = kwargs["time"] + client_name = kwargs["client"] + site_name = kwargs["site"] + all_agents = kwargs["all"] + offline = kwargs["offline"] + overdue = kwargs["overdue"] + agents = None + + if offline and time < 2: + self.stdout.write(self.style.ERROR("Minimum offline time is 2 minutes")) + return + + if overdue and time < 3: + self.stdout.write(self.style.ERROR("Minimum overdue time is 3 minutes")) + return + + if client_name: + try: + client = Client.objects.get(name=client_name) + except Client.DoesNotExist: + self.stdout.write( + self.style.ERROR(f"Client {client_name} doesn't exist") + ) + return + + agents = Agent.objects.filter(site__client=client) + + elif site_name: + try: + site = Site.objects.get(name=site_name) + except Site.DoesNotExist: + self.stdout.write(self.style.ERROR(f"Site {site_name} doesn't exist")) + return + + agents = Agent.objects.filter(site=site) + + elif all_agents: + agents = Agent.objects.all() + + if agents: + if offline: + agents.update(offline_time=time) + self.stdout.write( + self.style.SUCCESS( + f"Changed offline time on {len(agents)} agents to {time} minutes" + ) + ) + + if overdue: + agents.update(overdue_time=time) + self.stdout.write( + self.style.SUCCESS( + f"Changed overdue time on {len(agents)} agents to {time} minutes" + ) + ) diff --git a/docs/docs/install_server.md b/docs/docs/install_server.md index 93637732..8f6205d9 100644 --- a/docs/docs/install_server.md +++ b/docs/docs/install_server.md @@ -52,8 +52,8 @@ ufw allow ssh Allow ssh from only allowed IP's (__highly__ recommended) ```bash -ufw allow from X.X.X.X to any port 22 -ufw allow from X.X.X.X to any port 22 +ufw allow proto tcp from X.X.X.X to any port 22 +ufw allow proto tcp from X.X.X.X to any port 22 ``` Enable and activate the firewall @@ -69,7 +69,7 @@ We'll be using `example.com` as our domain for this example. The RMM uses 3 different sites. The Vue frontend e.g. `rmm.example.com` which is where you'll be accesing your RMM from the browser, the REST backend e.g. `api.example.com` and Meshcentral e.g. `mesh.example.com` -Get the public IP of your server with `curl icanhazip.com`
+Get the public IP of your server with `curl https://icanhazip.tacticalrmm.io`
Open the DNS manager of wherever the domain you purchased is hosted.
Create 3 A records: `rmm`, `api` and `mesh` and point them to the public IP of your server: diff --git a/docs/docs/management_cmds.md b/docs/docs/management_cmds.md index cf643d78..dafdd6ca 100644 --- a/docs/docs/management_cmds.md +++ b/docs/docs/management_cmds.md @@ -39,4 +39,32 @@ python manage.py remove_orphaned_tasks #### Create a MeshCentral agent invite link ```bash python manage.py get_mesh_exe_url -``` \ No newline at end of file +``` + +#### Bulk update agent offline/overdue time + +```bash +wget -q https://raw.githubusercontent.com/wh1te909/tacticalrmm/develop/api/tacticalrmm/agents/management/commands/bulk_change_checkin.py -O /rmm/api/tacticalrmm/agents/management/commands/bulk_change_checkin.py +``` +Examples: + +Change offline time on all agents to 5 minutes +```bash +python manage.py bulk_change_checkin --offline --all 5 +``` + +Change overdue time on all agents to 10 minutes +```bash +python manage.py bulk_change_checkin --overdue --all 10 +``` + +Change overdue time on all agents in client named *Example Client* to 12 minutes +```bash +python manage.py bulk_change_checkin --overdue --client "Example Client" 12 +``` + +Change offline time on all agents in site named *Example Site* to 2 minutes +```bash +python manage.py bulk_change_checkin --offline --site "Example Site" 2 +``` +