Skip to content

Commit

Permalink
Release 0.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
wh1te909 committed Jan 27, 2021
2 parents e37f6cf + f3b7634 commit bff0527
Show file tree
Hide file tree
Showing 40 changed files with 268 additions and 10,945 deletions.
2 changes: 1 addition & 1 deletion api/tacticalrmm/agents/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def get_last_seen(self, obj) -> str:
else:
agent_tz = self.context["default_tz"]

return obj.last_seen.astimezone(agent_tz).strftime("%m %d %Y %H:%M:%S")
return obj.last_seen.astimezone(agent_tz).timestamp()

def get_logged_username(self, obj) -> str:
if obj.logged_in_username == "None" and obj.status == "online":
Expand Down
23 changes: 16 additions & 7 deletions api/tacticalrmm/agents/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def check_in_task() -> None:

@app.task
def monitor_agents_task() -> None:
q = Agent.objects.all()
q = Agent.objects.only("pk", "version", "last_seen", "overdue_time")
agents: List[int] = [i.pk for i in q if i.has_nats and i.status != "online"]
for agent in agents:
_check_agent_service(agent)
Expand All @@ -62,9 +62,18 @@ def agent_update(pk: int) -> str:
logger.warning(f"Unable to determine arch on {agent.hostname}. Skipping.")
return "noarch"

version = settings.LATEST_AGENT_VER
url = agent.winagent_dl
inno = agent.win_inno_exe
# removed sqlite in 1.4.0 to get rid of cgo dependency
# 1.3.0 has migration func to move from sqlite to win registry, so force an upgrade to 1.3.0 if old agent
if pyver.parse(agent.version) >= pyver.parse("1.3.0"):
version = settings.LATEST_AGENT_VER
url = agent.winagent_dl
inno = agent.win_inno_exe
else:
version = "1.3.0"
inno = (
"winagent-v1.3.0.exe" if agent.arch == "64" else "winagent-v1.3.0-x86.exe"
)
url = f"https://github.com/wh1te909/rmmagent/releases/download/v1.3.0/{inno}"

if agent.has_nats:
if pyver.parse(agent.version) <= pyver.parse("1.1.11"):
Expand Down Expand Up @@ -141,7 +150,7 @@ def auto_self_agent_update_task() -> None:

@app.task
def get_wmi_task():
agents = Agent.objects.all()
agents = Agent.objects.only("pk", "version", "last_seen", "overdue_time")
online = [
i
for i in agents
Expand All @@ -158,7 +167,7 @@ def get_wmi_task():

@app.task
def sync_sysinfo_task():
agents = Agent.objects.all()
agents = Agent.objects.only("pk", "version", "last_seen", "overdue_time")
online = [
i
for i in agents
Expand Down Expand Up @@ -307,7 +316,7 @@ def remove_salt_task() -> None:
if hasattr(settings, "KEEP_SALT") and settings.KEEP_SALT:
return

q = Agent.objects.all()
q = Agent.objects.only("pk", "version")
agents = [i for i in q if pyver.parse(i.version) >= pyver.parse("1.3.0")]
chunks = (agents[i : i + 50] for i in range(0, len(agents), 50))
for chunk in chunks:
Expand Down
33 changes: 27 additions & 6 deletions api/tacticalrmm/agents/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,19 +780,20 @@ def test_agent_update(self, nats_cmd):
action = PendingAction.objects.get(agent__pk=agent64_111.pk)
self.assertEqual(action.action_type, "agentupdate")
self.assertEqual(action.status, "pending")
self.assertEqual(action.details["url"], settings.DL_64)
self.assertEqual(
action.details["inno"], f"winagent-v{settings.LATEST_AGENT_VER}.exe"
action.details["url"],
"https://github.com/wh1te909/rmmagent/releases/download/v1.3.0/winagent-v1.3.0.exe",
)
self.assertEqual(action.details["version"], settings.LATEST_AGENT_VER)
self.assertEqual(action.details["inno"], "winagent-v1.3.0.exe")
self.assertEqual(action.details["version"], "1.3.0")

agent64 = baker.make_recipe(
agent_64_130 = baker.make_recipe(
"agents.agent",
operating_system="Windows 10 Pro, 64 bit (build 19041.450)",
version="1.1.12",
version="1.3.0",
)
nats_cmd.return_value = "ok"
r = agent_update(agent64.pk)
r = agent_update(agent_64_130.pk)
self.assertEqual(r, "created")
nats_cmd.assert_called_with(
{
Expand All @@ -806,6 +807,26 @@ def test_agent_update(self, nats_cmd):
wait=False,
)

agent64_old = baker.make_recipe(
"agents.agent",
operating_system="Windows 10 Pro, 64 bit (build 19041.450)",
version="1.2.1",
)
nats_cmd.return_value = "ok"
r = agent_update(agent64_old.pk)
self.assertEqual(r, "created")
nats_cmd.assert_called_with(
{
"func": "agentupdate",
"payload": {
"url": "https://github.com/wh1te909/rmmagent/releases/download/v1.3.0/winagent-v1.3.0.exe",
"version": "1.3.0",
"inno": "winagent-v1.3.0.exe",
},
},
wait=False,
)

""" @patch("agents.models.Agent.salt_api_async")
@patch("agents.tasks.sleep", return_value=None)
def test_auto_self_agent_update_task(self, mock_sleep, salt_api_async):
Expand Down
2 changes: 1 addition & 1 deletion api/tacticalrmm/agents/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,7 +825,7 @@ def bulk(request):
elif request.data["target"] == "agents":
q = Agent.objects.filter(pk__in=request.data["agentPKs"])
elif request.data["target"] == "all":
q = Agent.objects.all()
q = Agent.objects.only("pk", "monitoring_type")
else:
return notify_error("Something went wrong")

Expand Down
9 changes: 9 additions & 0 deletions api/tacticalrmm/apiv3/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,12 @@ def test_hello_patch(self):
self.assertEqual(r.status_code, 200)

self.check_not_authenticated("patch", url)

def test_checkrunner_interval(self):
url = f"/api/v3/{self.agent.agent_id}/checkinterval/"
r = self.client.get(url, format="json")
self.assertEqual(r.status_code, 200)
self.assertEqual(
r.json(),
{"agent": self.agent.pk, "check_interval": self.agent.check_interval},
)
1 change: 1 addition & 0 deletions api/tacticalrmm/apiv3/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
path("hello/", views.Hello.as_view()),
path("checkrunner/", views.CheckRunner.as_view()),
path("<str:agentid>/checkrunner/", views.CheckRunner.as_view()),
path("<str:agentid>/checkinterval/", views.CheckRunnerInterval.as_view()),
path("<int:pk>/<str:agentid>/taskrunner/", views.TaskRunner.as_view()),
path("<int:pk>/meshinfo/", views.MeshInfo.as_view()),
path("meshexe/", views.MeshExe.as_view()),
Expand Down
9 changes: 9 additions & 0 deletions api/tacticalrmm/apiv3/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,15 @@ def patch(self, request):
return Response(status)


class CheckRunnerInterval(APIView):
authentication_classes = [TokenAuthentication]
permission_classes = [IsAuthenticated]

def get(self, request, agentid):
agent = get_object_or_404(Agent, agent_id=agentid)
return Response({"agent": agent.pk, "check_interval": agent.check_interval})


class TaskRunner(APIView):
"""
For the windows golang agent
Expand Down
20 changes: 14 additions & 6 deletions api/tacticalrmm/automation/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ def generate_agent_checks_from_policies_task(policypk, create_tasks=False):
policy = Policy.objects.get(pk=policypk)

if policy.is_default_server_policy and policy.is_default_workstation_policy:
agents = Agent.objects.all()
agents = Agent.objects.prefetch_related("policy").only("pk", "monitoring_type")
elif policy.is_default_server_policy:
agents = Agent.objects.filter(monitoring_type="server")
agents = Agent.objects.filter(monitoring_type="server").only(
"pk", "monitoring_type"
)
elif policy.is_default_workstation_policy:
agents = Agent.objects.filter(monitoring_type="workstation")
agents = Agent.objects.filter(monitoring_type="workstation").only(
"pk", "monitoring_type"
)
else:
agents = policy.related_agents()

Expand Down Expand Up @@ -84,11 +88,15 @@ def generate_agent_tasks_from_policies_task(policypk):
policy = Policy.objects.get(pk=policypk)

if policy.is_default_server_policy and policy.is_default_workstation_policy:
agents = Agent.objects.all()
agents = Agent.objects.prefetch_related("policy").only("pk", "monitoring_type")
elif policy.is_default_server_policy:
agents = Agent.objects.filter(monitoring_type="server")
agents = Agent.objects.filter(monitoring_type="server").only(
"pk", "monitoring_type"
)
elif policy.is_default_workstation_policy:
agents = Agent.objects.filter(monitoring_type="workstation")
agents = Agent.objects.filter(monitoring_type="workstation").only(
"pk", "monitoring_type"
)
else:
agents = policy.related_agents()

Expand Down
10 changes: 7 additions & 3 deletions api/tacticalrmm/automation/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,15 @@ def patch(self, request):

agents = None
if "client" in request.data:
agents = Agent.objects.filter(site__client_id=request.data["client"])
agents = Agent.objects.prefetch_related("winupdatepolicy").filter(
site__client_id=request.data["client"]
)
elif "site" in request.data:
agents = Agent.objects.filter(site_id=request.data["site"])
agents = Agent.objects.prefetch_related("winupdatepolicy").filter(
site_id=request.data["site"]
)
else:
agents = Agent.objects.all()
agents = Agent.objects.prefetch_related("winupdatepolicy").only("pk")

for agent in agents:
winupdatepolicy = agent.winupdatepolicy.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Command(BaseCommand):
help = "Checks for orphaned tasks on all agents and removes them"

def handle(self, *args, **kwargs):
agents = Agent.objects.all()
agents = Agent.objects.only("pk", "last_seen", "overdue_time")
online = [i for i in agents if i.status == "online"]
for agent in online:
remove_orphaned_win_tasks.delay(agent.pk)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def handle(self, *args, **kwargs):
# 10-16-2020 changed the type of the agent's 'disks' model field
# from a dict of dicts, to a list of disks in the golang agent
# the following will convert dicts to lists for agent's still on the python agent
agents = Agent.objects.all()
agents = Agent.objects.only("pk", "disks")
for agent in agents:
if agent.disks is not None and isinstance(agent.disks, dict):
new = []
Expand Down
2 changes: 1 addition & 1 deletion api/tacticalrmm/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def server_maintenance(request):
from agents.models import Agent
from autotasks.tasks import remove_orphaned_win_tasks

agents = Agent.objects.all()
agents = Agent.objects.only("pk", "last_seen", "overdue_time")
online = [i for i in agents if i.status == "online"]
for agent in online:
remove_orphaned_win_tasks.delay(agent.pk)
Expand Down
2 changes: 1 addition & 1 deletion api/tacticalrmm/logs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def cancel_pending_action(request):
def debug_log(request, mode, hostname, order):
log_file = settings.LOG_CONFIG["handlers"][0]["sink"]

agents = Agent.objects.all()
agents = Agent.objects.prefetch_related("site").only("pk", "hostname")
agent_hostnames = AgentHostnameSerializer(agents, many=True)

switch_mode = {
Expand Down
3 changes: 3 additions & 0 deletions api/tacticalrmm/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
black
Werkzeug
django-extensions
mkdocs
mkdocs-material
pymdown-extensions
8 changes: 4 additions & 4 deletions api/tacticalrmm/tacticalrmm/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
AUTH_USER_MODEL = "accounts.User"

# latest release
TRMM_VERSION = "0.4.0"
TRMM_VERSION = "0.4.1"

# bump this version everytime vue code is changed
# to alert user they need to manually refresh their browser
APP_VER = "0.0.107"
APP_VER = "0.0.108"

# https://github.com/wh1te909/rmmagent
LATEST_AGENT_VER = "1.3.0"
LATEST_AGENT_VER = "1.4.0"

MESH_VER = "0.7.49"
MESH_VER = "0.7.54"

# for the update script, bump when need to recreate venv or npm install
PIP_VER = "7"
Expand Down
4 changes: 2 additions & 2 deletions api/tacticalrmm/winupdate/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
def auto_approve_updates_task():
# scheduled task that checks and approves updates daily

agents = Agent.objects.all()
agents = Agent.objects.only("pk", "version", "last_seen", "overdue_time")
for agent in agents:
try:
agent.approve_updates()
Expand All @@ -43,7 +43,7 @@ def auto_approve_updates_task():
@app.task
def check_agent_update_schedule_task():
# scheduled task that installs updates on agents if enabled
agents = Agent.objects.all()
agents = Agent.objects.only("pk", "version", "last_seen", "overdue_time")
online = [
i
for i in agents
Expand Down
12 changes: 0 additions & 12 deletions docs/.npmignore

This file was deleted.

41 changes: 0 additions & 41 deletions docs/.vuepress/config.js

This file was deleted.

14 changes: 0 additions & 14 deletions docs/.vuepress/enhanceApp.js

This file was deleted.

8 changes: 0 additions & 8 deletions docs/.vuepress/styles/index.styl

This file was deleted.

10 changes: 0 additions & 10 deletions docs/.vuepress/styles/palette.styl

This file was deleted.

Binary file added docs/docs/images/favicon.ico
Binary file not shown.
Binary file added docs/docs/images/onit.ico
Binary file not shown.
Loading

0 comments on commit bff0527

Please sign in to comment.