some more fixes an formatting changes

This commit is contained in:
sadnub
2020-11-11 13:01:11 -05:00
parent 3fabae5b5f
commit 65b6aabe69
3 changed files with 20 additions and 3 deletions

View File

@@ -6,6 +6,7 @@ from django.conf import settings
from django.shortcuts import get_object_or_404
from django.utils import timezone as djangotime
from django.http import HttpResponse
from rest_framework import serializers
from rest_framework.response import Response
from rest_framework.views import APIView
@@ -189,13 +190,14 @@ class TaskRunner(APIView):
serializer.is_valid(raise_exception=True)
serializer.save(last_run=djangotime.now())
new_task = AutomatedTask.objects.get(pk=task.pk)
AuditLog.objects.create(
username=agent.hostname,
agent=agent.hostname,
object_type="agent",
action="task_run",
message=f"Scheduled Task {task.name} was run on {agent.hostname}",
after_value=AutomatedTask.serialize(serializer),
after_value=AutomatedTask.serialize(new_task),
)
return Response("ok")

View File

@@ -1,4 +1,5 @@
import datetime as dt
import json
from abc import abstractmethod
from django.db import models
from tacticalrmm.middleware import get_username, get_debug_info
@@ -178,8 +179,12 @@ class AuditLog(models.Model):
@staticmethod
def audit_bulk_action(username, action, affected, debug_info={}):
from clients.models import Client, Site
from agents.models import Agent
from scripts.models import Script
target = ""
agents = None
if affected["target"] == "all":
target = "on all agents"
elif affected["target"] == "client":
@@ -188,9 +193,19 @@ class AuditLog(models.Model):
elif affected["target"] == "site":
site = Site.objects.get(pk=affected["site"])
target = f"on all agents within site: {site.client.name}\\{site.name}"
elif affected["target"] == "agent":
elif affected["target"] == "agents":
agents = Agent.objects.filter(pk__in=affected["agentPKs"]).values_list(
"hostname", flat=True
)
target = "on multiple agents"
if action == "script":
script = Script.objects.get(pk=affected["scriptPK"])
action = f"script: {script.name}"
if agents:
affected["agent_hostnames"] = list(agents)
AuditLog.objects.create(
username=username,
object_type="bulk",

View File

@@ -248,7 +248,7 @@ export default {
objectOptions: [
{ value: "agent", label: "Agent" },
{ value: "automatedtask", label: "Automated Task" },
{ value: "bulk", label: "Bullk Actions" },
{ value: "bulk", label: "Bulk Actions" },
{ value: "coresettings", label: "Core Settings" },
{ value: "check", label: "Check" },
{ value: "client", label: "Client" },