Skip to content

Commit

Permalink
Release 0.17.4
Browse files Browse the repository at this point in the history
  • Loading branch information
wh1te909 committed Feb 5, 2024
2 parents df3e68f + 84c2632 commit e099a5a
Show file tree
Hide file tree
Showing 32 changed files with 317 additions and 125 deletions.
80 changes: 60 additions & 20 deletions api/tacticalrmm/agents/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,22 @@ class Meta:
def __str__(self) -> str:
return self.hostname

def save(self, *args, **kwargs):
# prevent recursion since calling set_alert_template() also calls save()
if not hasattr(self, "_processing_set_alert_template"):
self._processing_set_alert_template = False

if self.pk and not self._processing_set_alert_template:
orig = Agent.objects.get(pk=self.pk)
mon_type_changed = self.monitoring_type != orig.monitoring_type
site_changed = self.site_id != orig.site_id
if mon_type_changed or site_changed:
self._processing_set_alert_template = True
self.set_alert_template()
self._processing_set_alert_template = False

super().save(*args, **kwargs)

@property
def client(self) -> "Client":
return self.site.client
Expand Down Expand Up @@ -282,7 +298,20 @@ def cpu_model(self) -> List[str]:
try:
cpus = self.wmi_detail["cpu"]
for cpu in cpus:
ret.append([x["Name"] for x in cpu if "Name" in x][0])
name = [x["Name"] for x in cpu if "Name" in x][0]
lp, nc = "", ""
with suppress(Exception):
lp = [
x["NumberOfLogicalProcessors"]
for x in cpu
if "NumberOfCores" in x
][0]
nc = [x["NumberOfCores"] for x in cpu if "NumberOfCores" in x][0]
if lp and nc:
cpu_string = f"{name}, {nc}C/{lp}T"
else:
cpu_string = name
ret.append(cpu_string)
return ret
except:
return ["unknown cpu model"]
Expand Down Expand Up @@ -413,7 +442,10 @@ def physical_disks(self) -> Sequence[Disk]:
@property
def serial_number(self) -> str:
if self.is_posix:
return ""
try:
return self.wmi_detail["serialnumber"]
except:
return ""

try:
return self.wmi_detail["bios"][0][0]["SerialNumber"]
Expand Down Expand Up @@ -507,24 +539,32 @@ def get_agent_policies(self) -> "Dict[str, Optional[Policy]]":
)

return {
"agent_policy": self.policy
if self.policy and not self.policy.is_agent_excluded(self)
else None,
"site_policy": site_policy
if (site_policy and not site_policy.is_agent_excluded(self))
and not self.block_policy_inheritance
else None,
"client_policy": client_policy
if (client_policy and not client_policy.is_agent_excluded(self))
and not self.block_policy_inheritance
and not self.site.block_policy_inheritance
else None,
"default_policy": default_policy
if (default_policy and not default_policy.is_agent_excluded(self))
and not self.block_policy_inheritance
and not self.site.block_policy_inheritance
and not self.client.block_policy_inheritance
else None,
"agent_policy": (
self.policy
if self.policy and not self.policy.is_agent_excluded(self)
else None
),
"site_policy": (
site_policy
if (site_policy and not site_policy.is_agent_excluded(self))
and not self.block_policy_inheritance
else None
),
"client_policy": (
client_policy
if (client_policy and not client_policy.is_agent_excluded(self))
and not self.block_policy_inheritance
and not self.site.block_policy_inheritance
else None
),
"default_policy": (
default_policy
if (default_policy and not default_policy.is_agent_excluded(self))
and not self.block_policy_inheritance
and not self.site.block_policy_inheritance
and not self.client.block_policy_inheritance
else None
),
}

def check_run_interval(self) -> int:
Expand Down
20 changes: 11 additions & 9 deletions api/tacticalrmm/alerts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,15 +169,17 @@ def create_or_return_check_alert(
assigned_check=check,
agent=agent,
alert_type=AlertType.CHECK,
severity=check.alert_severity
if check.check_type
not in {
CheckType.MEMORY,
CheckType.CPU_LOAD,
CheckType.DISK_SPACE,
CheckType.SCRIPT,
}
else alert_severity,
severity=(
check.alert_severity
if check.check_type
not in {
CheckType.MEMORY,
CheckType.CPU_LOAD,
CheckType.DISK_SPACE,
CheckType.SCRIPT,
}
else alert_severity
),
message=f"{agent.hostname} has a {check.check_type} check: {check.readable_desc} that failed.",
hidden=True,
),
Expand Down
22 changes: 13 additions & 9 deletions api/tacticalrmm/autotasks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,16 +248,20 @@ def generate_nats_task_payload(self) -> Dict[str, Any]:
"name": self.win_task_name,
"overwrite_task": True,
"enabled": self.enabled,
"trigger": self.task_type
if self.task_type != TaskType.CHECK_FAILURE
else TaskType.MANUAL,
"trigger": (
self.task_type
if self.task_type != TaskType.CHECK_FAILURE
else TaskType.MANUAL
),
"multiple_instances": self.task_instance_policy or 0,
"delete_expired_task_after": self.remove_if_not_scheduled
if self.expire_date
else False,
"start_when_available": self.run_asap_after_missed
if self.task_type != TaskType.RUN_ONCE
else True,
"delete_expired_task_after": (
self.remove_if_not_scheduled if self.expire_date else False
),
"start_when_available": (
self.run_asap_after_missed
if self.task_type != TaskType.RUN_ONCE
else True
),
}

if self.task_type in (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.conf import settings
from django.core.management.base import BaseCommand

from tacticalrmm.helpers import get_nats_internal_protocol, get_nats_ports
from tacticalrmm.helpers import get_nats_url


class Command(BaseCommand):
Expand All @@ -20,11 +20,9 @@ def handle(self, *args, **kwargs):
else:
ssl = "disable"

nats_std_port, _ = get_nats_ports()
proto = get_nats_internal_protocol()
config = {
"key": settings.SECRET_KEY,
"natsurl": f"{proto}://{settings.ALLOWED_HOSTS[0]}:{nats_std_port}",
"natsurl": get_nats_url(),
"user": db["USER"],
"pass": db["PASSWORD"],
"host": db["HOST"],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 4.2.9 on 2024-01-26 00:31

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("core", "0038_alter_coresettings_default_time_zone"),
]

operations = [
migrations.AddField(
model_name="coresettings",
name="smtp_from_name",
field=models.CharField(blank=True, max_length=255, null=True),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.9 on 2024-01-28 02:50

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("core", "0039_coresettings_smtp_from_name"),
]

operations = [
migrations.AddField(
model_name="customfield",
name="hide_in_summary",
field=models.BooleanField(default=False),
),
]
18 changes: 18 additions & 0 deletions api/tacticalrmm/core/migrations/0041_auto_20240128_0301.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.9 on 2024-01-28 03:01

from django.db import migrations


def update_hide_in_summary(apps, schema_editor):
CustomField = apps.get_model("core", "CustomField")
for field in CustomField.objects.filter(hide_in_ui=True):
field.hide_in_summary = True
field.save(update_fields=["hide_in_summary"])


class Migration(migrations.Migration):
dependencies = [
("core", "0040_customfield_hide_in_summary"),
]

operations = [migrations.RunPython(update_hide_in_summary)]
25 changes: 21 additions & 4 deletions api/tacticalrmm/core/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import smtplib
from contextlib import suppress
from email.message import EmailMessage
from email.headerregistry import Address
from typing import TYPE_CHECKING, List, Optional, cast

import requests
Expand Down Expand Up @@ -44,6 +45,7 @@ class CoreSettings(BaseAuditModel):
smtp_from_email = models.CharField(
max_length=255, blank=True, default="[email protected]"
)
smtp_from_name = models.CharField(max_length=255, null=True, blank=True)
smtp_host = models.CharField(max_length=255, blank=True, default="smtp.gmail.com")
smtp_host_user = models.CharField(
max_length=255, blank=True, default="[email protected]"
Expand Down Expand Up @@ -207,7 +209,14 @@ def send_mail(
try:
msg = EmailMessage()
msg["Subject"] = subject
msg["From"] = from_address

if self.smtp_from_name:
msg["From"] = Address(
display_name=self.smtp_from_name, addr_spec=from_address
)
else:
msg["From"] = from_address

msg["To"] = email_recipients
msg.set_content(body)

Expand All @@ -222,9 +231,16 @@ def send_mail(
server.send_message(msg)
server.quit()
else:
# smtp relay. no auth required
server.send_message(msg)
server.quit()
# gmail smtp relay specific handling.
if self.smtp_host == "smtp-relay.gmail.com":
server.ehlo()
server.starttls()
server.send_message(msg)
server.quit()
else:
# smtp relay. no auth required
server.send_message(msg)
server.quit()

except Exception as e:
DebugLog.error(message=f"Sending email failed with error: {e}")
Expand Down Expand Up @@ -298,6 +314,7 @@ class CustomField(BaseAuditModel):
default=list,
)
hide_in_ui = models.BooleanField(default=False)
hide_in_summary = models.BooleanField(default=False)

class Meta:
unique_together = (("model", "name"),)
Expand Down
37 changes: 34 additions & 3 deletions api/tacticalrmm/core/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
from core.utils import get_core_settings, get_meshagent_url

# from logs.models import PendingAction
from tacticalrmm.constants import (
from tacticalrmm.constants import ( # PAAction,; PAStatus,
CONFIG_MGMT_CMDS,
CustomFieldModel,
MeshAgentIdent,
# PAAction,
# PAStatus,
)
from tacticalrmm.helpers import get_nats_hosts, get_nats_url
from tacticalrmm.test import TacticalTestCase

from .consumers import DashInfo
Expand Down Expand Up @@ -445,6 +444,38 @@ def test_get_config(self):
call_command("get_config", cmd)


class TestNatsUrls(TacticalTestCase):
def setUp(self):
self.setup_coresettings()

def test_standard_install(self):
self.assertEqual(get_nats_url(), "nats://localhost:4222")

@override_settings(
NATS_STANDARD_PORT=5000,
USE_NATS_STANDARD=True,
ALLOWED_HOSTS=["api.example.com"],
)
def test_custom_port_nats_standard(self):
self.assertEqual(get_nats_url(), "tls://api.example.com:5000")

@override_settings(DOCKER_BUILD=True, ALLOWED_HOSTS=["api.example.com"])
def test_docker_nats(self):
self.assertEqual(get_nats_url(), "nats://api.example.com:4222")

@patch.dict("os.environ", {"NATS_CONNECT_HOST": "172.20.4.3"})
@override_settings(ALLOWED_HOSTS=["api.example.com"])
def test_custom_connect_host_env(self):
self.assertEqual(get_nats_url(), "nats://172.20.4.3:4222")

def test_standard_nats_hosts(self):
self.assertEqual(get_nats_hosts(), ("localhost", "localhost", "localhost"))

@override_settings(DOCKER_BUILD=True, ALLOWED_HOSTS=["api.example.com"])
def test_docker_nats_hosts(self):
self.assertEqual(get_nats_hosts(), ("0.0.0.0", "0.0.0.0", "api.example.com"))


class TestCorePermissions(TacticalTestCase):
def setUp(self):
self.setup_client()
Expand Down
6 changes: 3 additions & 3 deletions api/tacticalrmm/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ def dashboard_info(request):
"show_community_scripts": request.user.show_community_scripts,
"dbl_click_action": request.user.agent_dblclick_action,
"default_agent_tbl_tab": request.user.default_agent_tbl_tab,
"url_action": request.user.url_action.id
if request.user.url_action
else None,
"url_action": (
request.user.url_action.id if request.user.url_action else None
),
"client_tree_sort": request.user.client_tree_sort,
"client_tree_splitter": request.user.client_tree_splitter,
"loading_bar_color": request.user.loading_bar_color,
Expand Down
2 changes: 1 addition & 1 deletion api/tacticalrmm/ee/reporting/custom_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import validators


def as_tz(date_obj, tz, format="%b %d, %I:%M %p"):
def as_tz(date_obj, tz, format="%b %d %Y, %I:%M %p"):
return date_obj.astimezone(ZoneInfo(tz)).strftime(format)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This file is subject to the EE License Agreement.
For details, see: https://license.tacticalrmm.com/ee
"""

import json
from typing import TYPE_CHECKING, Any, Dict, List, Tuple

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
This file is subject to the EE License Agreement.
For details, see: https://license.tacticalrmm.com/ee
"""

import urllib.parse
from time import sleep
from typing import Any, Optional
Expand Down
Loading

0 comments on commit e099a5a

Please sign in to comment.