add new management command
This commit is contained in:
parent
c03b768364
commit
8cd2544f78
|
@ -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"
|
||||
)
|
||||
)
|
|
@ -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`<br/>
|
||||
Get the public IP of your server with `curl https://icanhazip.tacticalrmm.io`<br/>
|
||||
Open the DNS manager of wherever the domain you purchased is hosted.<br/>
|
||||
Create 3 A records: `rmm`, `api` and `mesh` and point them to the public IP of your server:
|
||||
|
||||
|
|
|
@ -39,4 +39,32 @@ python manage.py remove_orphaned_tasks
|
|||
#### Create a MeshCentral agent invite link
|
||||
```bash
|
||||
python manage.py get_mesh_exe_url
|
||||
```
|
||||
```
|
||||
|
||||
#### 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
|
||||
```
|
||||
|
||||
|
|
Loading…
Reference in New Issue