Exemplo n.º 1
0
    def post(self, request):
        agent = get_object_or_404(Agent, agent_id=request.data["agent_id"])
        reboot_policy = agent.get_patch_policy().reboot_after_install
        reboot = False

        if reboot_policy == "always":
            reboot = True

        if request.data["reboot"]:
            if reboot_policy == "required":
                reboot = True
            elif reboot_policy == "never":
                agent.needs_reboot = True
                agent.save(update_fields=["needs_reboot"])

        if reboot:
            if agent.has_nats:
                asyncio.run(agent.nats_cmd({"func": "rebootnow"}, wait=False))
            else:
                agent.salt_api_async(
                    func="system.reboot",
                    arg=7,
                    kwargs={"in_seconds": True},
                )

            logger.info(
                f"{agent.hostname} is rebooting after updates were installed.")
        else:
            check_for_updates_task.apply_async(queue="wupdate",
                                               kwargs={
                                                   "pk": agent.pk,
                                                   "wait": False
                                               })

        return Response("ok")
Exemplo n.º 2
0
def update(request):
    agent = get_object_or_404(Agent, agent_id=request.data["agent_id"])

    if agent.update_pending and request.data["version"] != agent.version:
        agent.update_pending = False
        agent.save(update_fields=["update_pending"])

    serializer = WinAgentSerializer(instance=agent,
                                    data=request.data,
                                    partial=True)
    serializer.is_valid(raise_exception=True)
    serializer.save(last_seen=djangotime.now())

    sync_salt_modules_task.delay(agent.pk)
    get_installed_software.delay(agent.pk)
    get_wmi_detail_task.delay(agent.pk)
    check_for_updates_task.apply_async(queue="wupdate",
                                       kwargs={
                                           "pk": agent.pk,
                                           "wait": True
                                       })

    if not agent.choco_installed:
        install_chocolatey.delay(agent.pk, wait=True)

    return Response("ok")
Exemplo n.º 3
0
    def post(self, request):
        agent = get_object_or_404(Agent, agent_id=request.data["agent_id"])
        reboot_policy = agent.get_patch_policy().reboot_after_install
        reboot = False

        if reboot_policy == "always":
            reboot = True

        if request.data["reboot"]:
            if reboot_policy == "required":
                reboot = True
            elif reboot_policy == "never":
                agent.needs_reboot = True
                agent.save(update_fields=["needs_reboot"])

        if reboot:
            r = agent.salt_api_cmd(
                timeout=15,
                func="system.reboot",
                arg=7,
                kwargs={"in_seconds": True},
            )

            if r == "timeout" or r == "error" or (isinstance(r, bool)
                                                  and not r):
                check_for_updates_task.apply_async(queue="wupdate",
                                                   kwargs={
                                                       "pk": agent.pk,
                                                       "wait": False
                                                   })
            else:
                logger.info(
                    f"{agent.hostname} is rebooting after updates were installed."
                )
        else:
            check_for_updates_task.apply_async(queue="wupdate",
                                               kwargs={
                                                   "pk": agent.pk,
                                                   "wait": False
                                               })

        return Response("ok")
Exemplo n.º 4
0
    def post(self, request):
        agent = get_object_or_404(Agent, agent_id=request.data["agent_id"])

        serializer = WinAgentSerializer(instance=agent,
                                        data=request.data,
                                        partial=True)
        serializer.is_valid(raise_exception=True)
        serializer.save(last_seen=djangotime.now())

        sync_salt_modules_task.delay(agent.pk)
        check_for_updates_task.apply_async(queue="wupdate",
                                           kwargs={
                                               "pk": agent.pk,
                                               "wait": True
                                           })

        if not agent.choco_installed:
            install_chocolatey.delay(agent.pk, wait=True)

        return Response("ok")