Exemplo n.º 1
0
    def save(self, *args, **kwargs):
        from alerts.tasks import cache_agents_alert_template
        from automation.tasks import generate_all_agent_checks_task

        if not self.pk and CoreSettings.objects.exists():
            raise ValidationError(
                "There can only be one CoreSettings instance")

        # for install script
        if not self.pk:
            try:
                self.mesh_site = settings.MESH_SITE
                self.mesh_username = settings.MESH_USERNAME
                self.mesh_token = settings.MESH_TOKEN_KEY
            except:
                pass

        old_settings = type(self).objects.get(pk=self.pk) if self.pk else None
        super(BaseAuditModel, self).save(*args, **kwargs)

        # check if server polcies have changed and initiate task to reapply policies if so
        if old_settings and old_settings.server_policy != self.server_policy:
            generate_all_agent_checks_task.delay(mon_type="server",
                                                 create_tasks=True)

        # check if workstation polcies have changed and initiate task to reapply policies if so
        if old_settings and old_settings.workstation_policy != self.workstation_policy:
            generate_all_agent_checks_task.delay(mon_type="workstation",
                                                 create_tasks=True)

        if old_settings and old_settings.alert_template != self.alert_template:
            cache_agents_alert_template.delay()
Exemplo n.º 2
0
def edit_settings(request):
    settings = CoreSettings.objects.first()
    serializer = CoreSettingsSerializer(instance=settings, data=request.data)
    serializer.is_valid(raise_exception=True)
    new_settings = serializer.save()

    # check if default policies changed
    if settings.server_policy != new_settings.server_policy:
        generate_all_agent_checks_task.delay(
            mon_type="server", clear=True, create_tasks=True
        )

    if settings.workstation_policy != new_settings.workstation_policy:
        generate_all_agent_checks_task.delay(
            mon_type="workstation", clear=True, create_tasks=True
        )

    return Response("ok")
Exemplo n.º 3
0
    def delete(self, request, pk, sitepk):
        from automation.tasks import generate_all_agent_checks_task

        client = get_object_or_404(Client, pk=pk)
        agents = Agent.objects.filter(site__client=client)

        if not sitepk:
            return notify_error(
                "There needs to be a site specified to move existing agents to"
            )

        site = get_object_or_404(Site, pk=sitepk)
        agents.update(site=site)

        generate_all_agent_checks_task.delay("workstation", create_tasks=True)
        generate_all_agent_checks_task.delay("server", create_tasks=True)

        client.delete()
        return Response(f"{client.name} was deleted!")
Exemplo n.º 4
0
    def delete(self, request, pk, sitepk):
        from automation.tasks import generate_all_agent_checks_task

        site = get_object_or_404(Site, pk=pk)
        if site.client.sites.count() == 1:
            return notify_error("A client must have at least 1 site.")

        agents = Agent.objects.filter(site=site)

        if not sitepk:
            return notify_error(
                "There needs to be a site specified to move the agents to")

        agent_site = get_object_or_404(Site, pk=sitepk)

        agents.update(site=agent_site)

        generate_all_agent_checks_task.delay("workstation", create_tasks=True)
        generate_all_agent_checks_task.delay("server", create_tasks=True)

        site.delete()
        return Response(f"{site.name} was deleted!")