diff --git a/api/tacticalrmm/automation/serializers.py b/api/tacticalrmm/automation/serializers.py index 0812b114..81151e4f 100644 --- a/api/tacticalrmm/automation/serializers.py +++ b/api/tacticalrmm/automation/serializers.py @@ -3,6 +3,7 @@ from rest_framework import serializers from .models import Policy from autotasks.models import AutomatedTask from autotasks.serializers import TaskSerializer +from checks.serializers import CheckSerializer class PolicySerializer(serializers.ModelSerializer): @@ -29,3 +30,4 @@ class AutoTaskPolicySerializer(serializers.ModelSerializer): "name", "autotasks", ) + \ No newline at end of file diff --git a/api/tacticalrmm/automation/urls.py b/api/tacticalrmm/automation/urls.py index b4c15fe6..c0b3e65d 100644 --- a/api/tacticalrmm/automation/urls.py +++ b/api/tacticalrmm/automation/urls.py @@ -6,6 +6,7 @@ urlpatterns = [ path("policies//related/", views.GetRelated.as_view()), path("policies/overview/", views.OverviewPolicy.as_view()), path("policies//", views.GetUpdateDeletePolicy.as_view()), + path("/policychecks/", views.PolicyCheck.as_view()), path("/policyautomatedtasks/", views.PolicyAutoTask.as_view()), path("runwintask//", views.RunPolicyTask.as_view()), ] diff --git a/api/tacticalrmm/automation/views.py b/api/tacticalrmm/automation/views.py index cca922ef..d5ef9fb8 100644 --- a/api/tacticalrmm/automation/views.py +++ b/api/tacticalrmm/automation/views.py @@ -13,6 +13,7 @@ from .models import Policy from agents.models import Agent from scripts.models import Script from clients.models import Client, Site +from checks.models import Check from clients.serializers import ( ClientSerializer, @@ -27,6 +28,8 @@ from .serializers import ( AutoTaskPolicySerializer, ) +from checks.serializers import CheckSerializer + class GetAddPolicies(APIView): def get(self, request): @@ -112,6 +115,11 @@ class RunPolicyTask(APIView): # TODO: Run tasks for all Agents under policy return Response("ok") +class PolicyCheck(APIView): + def get(self, request, pk): + checks = Check.objects.filter(policy__pk=pk) + return Response(CheckSerializer(checks, many=True).data) + class OverviewPolicy(APIView): def get(self, request): diff --git a/api/tacticalrmm/checks/serializers.py b/api/tacticalrmm/checks/serializers.py index a529b4cc..95052bf5 100644 --- a/api/tacticalrmm/checks/serializers.py +++ b/api/tacticalrmm/checks/serializers.py @@ -57,29 +57,3 @@ class CheckSerializer(serializers.ModelSerializer): ) return val - - -""" class PolicyChecksSerializer(serializers.ModelSerializer): - diskchecks = DiskCheckSerializer(many=True, read_only=True) - cpuloadchecks = CpuLoadCheckSerializer(many=True, read_only=True) - memchecks = MemCheckSerializer(many=True, read_only=True) - pingchecks = PingCheckSerializer(many=True, read_only=True) - winservicechecks = WinServiceCheckSerializer(many=True, read_only=True) - scriptchecks = ScriptCheckSerializer(many=True, read_only=True) - eventlogchecks = EventLogCheckSerializer(many=True, read_only=True) - - class Meta: - model = Policy - fields = ( - "id", - "name", - "active", - "diskchecks", - "cpuloadchecks", - "memchecks", - "pingchecks", - "winservicechecks", - "scriptchecks", - "eventlogchecks", - ) - """ diff --git a/api/tacticalrmm/checks/urls.py b/api/tacticalrmm/checks/urls.py index 66cd9614..8121eb49 100644 --- a/api/tacticalrmm/checks/urls.py +++ b/api/tacticalrmm/checks/urls.py @@ -5,7 +5,6 @@ urlpatterns = [ path("checks/", views.GetAddCheck.as_view()), path("/check/", views.GetUpdateDeleteCheck.as_view()), path("/loadchecks/", views.load_checks), - path("/loadpolicychecks/", views.load_policy_checks), path("checkrunner/", views.check_runner), path("getalldisks/", views.get_disks_for_policies), path("runchecks//", views.run_checks), diff --git a/api/tacticalrmm/checks/views.py b/api/tacticalrmm/checks/views.py index fcb7920e..2242cfc6 100644 --- a/api/tacticalrmm/checks/views.py +++ b/api/tacticalrmm/checks/views.py @@ -157,12 +157,6 @@ def load_checks(request, pk): return Response(CheckSerializer(checks, many=True).data) -@api_view() -def load_policy_checks(request, pk): - policy = get_object_or_404(Policy, pk=pk) - return Response(PolicyChecksSerializer(policy).data) - - @api_view() def get_disks_for_policies(request): - return Response(DiskCheck.all_disks()) + return Response(Check.all_disks()) diff --git a/web/src/components/automation/AutomationManager.vue b/web/src/components/automation/AutomationManager.vue index 0391efa3..b51f36ac 100644 --- a/web/src/components/automation/AutomationManager.vue +++ b/web/src/components/automation/AutomationManager.vue @@ -247,7 +247,7 @@ export default { }, clearRow() { this.$store.commit("automation/setSelectedPolicy", null); - this.$store.commit("automation/setPolicyChecks", {}); + this.$store.commit("automation/setPolicyChecks", []); this.$store.commit("automation/setPolicyAutomatedTasks", {}); }, refresh() { diff --git a/web/src/components/automation/PolicyChecksTab.vue b/web/src/components/automation/PolicyChecksTab.vue index 7a048809..59c76a76 100644 --- a/web/src/components/automation/PolicyChecksTab.vue +++ b/web/src/components/automation/PolicyChecksTab.vue @@ -1,5 +1,5 @@