Skip to content

Commit

Permalink
Release 0.2.23
Browse files Browse the repository at this point in the history
  • Loading branch information
wh1te909 committed Jan 14, 2021
2 parents d082874 + e26fbf0 commit 9ab915a
Show file tree
Hide file tree
Showing 65 changed files with 1,833 additions and 57 deletions.
4 changes: 2 additions & 2 deletions .devcontainer/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ KEY_FILE = '/opt/tactical/certs/privkey.pem'
SCRIPTS_DIR = '${WORKSPACE_DIR}/scripts'
ALLOWED_HOSTS = ['${API_HOST}']
ALLOWED_HOSTS = ['${API_HOST}', 'localhost', '127.0.0.1']
ADMIN_URL = 'admin/'
Expand Down Expand Up @@ -137,7 +137,7 @@ if [ "$1" = 'tactical-init-dev' ]; then
test -f "${TACTICAL_READY_FILE}" && rm "${TACTICAL_READY_FILE}"

# setup Python virtual env and install dependencies
python -m venv --copies ${VIRTUAL_ENV}
test -f ${VIRTUAL_ENV} && python -m venv --copies ${VIRTUAL_ENV}
pip install --no-cache-dir -r /requirements.txt

django_setup
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 3.1.4 on 2021-01-14 01:23

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("accounts", "0009_user_show_community_scripts"),
]

operations = [
migrations.AddField(
model_name="user",
name="agent_dblclick_action",
field=models.CharField(
choices=[
("editagent", "Edit Agent"),
("takecontrol", "Take Control"),
("remotebg", "Remote Background"),
],
default="editagent",
max_length=50,
),
),
]
9 changes: 9 additions & 0 deletions api/tacticalrmm/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,21 @@

from logs.models import BaseAuditModel

AGENT_DBLCLICK_CHOICES = [
("editagent", "Edit Agent"),
("takecontrol", "Take Control"),
("remotebg", "Remote Background"),
]


class User(AbstractUser, BaseAuditModel):
is_active = models.BooleanField(default=True)
totp_key = models.CharField(max_length=50, null=True, blank=True)
dark_mode = models.BooleanField(default=True)
show_community_scripts = models.BooleanField(default=True)
agent_dblclick_action = models.CharField(
max_length=50, choices=AGENT_DBLCLICK_CHOICES, default="editagent"
)

agent = models.OneToOneField(
"agents.Agent",
Expand Down
12 changes: 12 additions & 0 deletions api/tacticalrmm/accounts/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,18 @@ def test_user_ui(self):
r = self.client.patch(url, data, format="json")
self.assertEqual(r.status_code, 200)

data = {"agent_dblclick_action": "editagent"}
r = self.client.patch(url, data, format="json")
self.assertEqual(r.status_code, 200)

data = {"agent_dblclick_action": "remotebg"}
r = self.client.patch(url, data, format="json")
self.assertEqual(r.status_code, 200)

data = {"agent_dblclick_action": "takecontrol"}
r = self.client.patch(url, data, format="json")
self.assertEqual(r.status_code, 200)

self.check_not_authenticated("patch", url)


Expand Down
4 changes: 4 additions & 0 deletions api/tacticalrmm/accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,8 @@ def patch(self, request):
user.show_community_scripts = request.data["show_community_scripts"]
user.save(update_fields=["show_community_scripts"])

if "agent_dblclick_action" in request.data:
user.agent_dblclick_action = request.data["agent_dblclick_action"]
user.save(update_fields=["agent_dblclick_action"])

return Response("ok")
24 changes: 19 additions & 5 deletions api/tacticalrmm/agents/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,13 @@ def check_in_task() -> None:
agents: List[int] = [
i.pk for i in q if pyver.parse(i.version) >= pyver.parse("1.1.12")
]
for agent in agents:
_check_in_full(agent)
chunks = (agents[i : i + 50] for i in range(0, len(agents), 50))
for chunk in chunks:
for pk in chunk:
_check_in_full(pk)
sleep(0.1)
rand = random.randint(3, 7)
sleep(rand)


@app.task
Expand Down Expand Up @@ -115,7 +120,6 @@ def send_agent_update_task(pks: List[int], version: str) -> None:
def auto_self_agent_update_task() -> None:
core = CoreSettings.objects.first()
if not core.agent_auto_update:
logger.info("Agent auto update is disabled. Skipping.")
return

q = Agent.objects.only("pk", "version")
Expand All @@ -137,8 +141,14 @@ def sync_sysinfo_task():
for i in agents
if pyver.parse(i.version) >= pyver.parse("1.1.3") and i.status == "online"
]
for agent in online:
asyncio.run(agent.nats_cmd({"func": "sync"}, wait=False))

chunks = (online[i : i + 50] for i in range(0, len(online), 50))
for chunk in chunks:
for agent in chunk:
asyncio.run(agent.nats_cmd({"func": "sync"}, wait=False))
sleep(0.1)
rand = random.randint(3, 7)
sleep(rand)


@app.task
Expand Down Expand Up @@ -281,6 +291,10 @@ def agent_outages_task():
outage = AgentOutage(agent=agent)
outage.save()

# add a null check history to allow gaps in graph
for check in agent.agentchecks.all():
check.add_check_history(None)

if agent.overdue_email_alert and not agent.maintenance_mode:
agent_outage_email_task.delay(pk=outage.pk)

Expand Down
10 changes: 0 additions & 10 deletions api/tacticalrmm/apiv3/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,16 +266,6 @@ def patch(self, request):
check.save(update_fields=["last_run"])
status = check.handle_checkv2(request.data)

# create audit entry
AuditLog.objects.create(
username=check.agent.hostname,
agent=check.agent.hostname,
object_type="agent",
action="check_run",
message=f"{check.readable_desc} was run on {check.agent.hostname}. Status: {status}",
after_value=Check.serialize(check),
)

return Response(status)


Expand Down
6 changes: 6 additions & 0 deletions api/tacticalrmm/autotasks/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ def delete_win_task_schedule(pk, pending_action=False):
pendingaction.status = "completed"
pendingaction.save(update_fields=["status"])

# complete any other pending actions on agent with same task_id
for action in task.agent.pendingactions.all():
if action.details["task_id"] == task.id:
action.status = "completed"
action.save()

task.delete()
return "ok"

Expand Down
3 changes: 2 additions & 1 deletion api/tacticalrmm/checks/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.contrib import admin

from .models import Check
from .models import Check, CheckHistory

admin.site.register(Check)
admin.site.register(CheckHistory)
30 changes: 30 additions & 0 deletions api/tacticalrmm/checks/migrations/0011_check_run_history.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Generated by Django 3.1.4 on 2021-01-09 02:56

import django.contrib.postgres.fields
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("checks", "0010_auto_20200922_1344"),
]

operations = [
migrations.AddField(
model_name="check",
name="run_history",
field=django.contrib.postgres.fields.ArrayField(
base_field=django.contrib.postgres.fields.ArrayField(
base_field=models.PositiveIntegerField(),
blank=True,
null=True,
size=None,
),
blank=True,
default=list,
null=True,
size=None,
),
),
]
39 changes: 39 additions & 0 deletions api/tacticalrmm/checks/migrations/0011_checkhistory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Generated by Django 3.1.4 on 2021-01-09 21:36

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
("checks", "0010_auto_20200922_1344"),
]

operations = [
migrations.CreateModel(
name="CheckHistory",
fields=[
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("x", models.DateTimeField()),
("y", models.PositiveIntegerField()),
("results", models.JSONField(blank=True, null=True)),
(
"check_history",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="check_history",
to="checks.check",
),
),
],
),
]
18 changes: 18 additions & 0 deletions api/tacticalrmm/checks/migrations/0012_auto_20210110_0503.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.1.4 on 2021-01-10 05:03

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("checks", "0011_checkhistory"),
]

operations = [
migrations.AlterField(
model_name="checkhistory",
name="y",
field=models.PositiveIntegerField(blank=True, null=True),
),
]
18 changes: 18 additions & 0 deletions api/tacticalrmm/checks/migrations/0013_auto_20210110_0505.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.1.4 on 2021-01-10 05:05

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("checks", "0012_auto_20210110_0503"),
]

operations = [
migrations.AlterField(
model_name="checkhistory",
name="y",
field=models.PositiveIntegerField(null=True),
),
]
13 changes: 13 additions & 0 deletions api/tacticalrmm/checks/migrations/0014_merge_20210110_1808.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Generated by Django 3.1.4 on 2021-01-10 18:08

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("checks", "0013_auto_20210110_0505"),
("checks", "0011_check_run_history"),
]

operations = []
27 changes: 27 additions & 0 deletions api/tacticalrmm/checks/migrations/0015_auto_20210110_1808.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 3.1.4 on 2021-01-10 18:08

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("checks", "0014_merge_20210110_1808"),
]

operations = [
migrations.RemoveField(
model_name="check",
name="run_history",
),
migrations.AlterField(
model_name="checkhistory",
name="x",
field=models.DateTimeField(auto_now_add=True),
),
migrations.AlterField(
model_name="checkhistory",
name="y",
field=models.PositiveIntegerField(blank=True, default=None, null=True),
),
]
27 changes: 26 additions & 1 deletion api/tacticalrmm/checks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import os
import json
import pytz
from statistics import mean
from statistics import mean, mode

from django.db import models
from django.conf import settings
from django.contrib.postgres.fields import ArrayField
from django.core.validators import MinValueValidator, MaxValueValidator
from rest_framework.fields import JSONField

from core.models import CoreSettings
from logs.models import BaseAuditModel
Expand Down Expand Up @@ -214,6 +215,10 @@ def non_editable_fields(self):
"modified_time",
]

def add_check_history(self, value):
if self.check_type in ["memory", "cpuload", "diskspace"]:
CheckHistory.objects.create(check_history=self, y=value)

def handle_checkv2(self, data):
# cpuload or mem checks
if self.check_type == "cpuload" or self.check_type == "memory":
Expand All @@ -232,6 +237,9 @@ def handle_checkv2(self, data):
else:
self.status = "passing"

# add check history
self.add_check_history(data["percent"])

# diskspace checks
elif self.check_type == "diskspace":
if data["exists"]:
Expand All @@ -245,6 +253,9 @@ def handle_checkv2(self, data):
self.status = "passing"

self.more_info = f"Total: {total}B, Free: {free}B"

# add check history
self.add_check_history(percent_used)
else:
self.status = "failing"
self.more_info = f"Disk {self.disk} does not exist"
Expand Down Expand Up @@ -645,3 +656,17 @@ def send_sms(self):
body = subject

CORE.send_sms(body)


class CheckHistory(models.Model):
check_history = models.ForeignKey(
Check,
related_name="check_history",
on_delete=models.CASCADE,
)
x = models.DateTimeField(auto_now_add=True)
y = models.PositiveIntegerField(null=True, blank=True, default=None)
results = models.JSONField(null=True, blank=True)

def __str__(self):
return self.check_history.readable_desc
Loading

0 comments on commit 9ab915a

Please sign in to comment.