コード例 #1
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")
コード例 #2
0
def update(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)
    get_installed_software.delay(agent.pk)
    get_wmi_detail_task.delay(agent.pk)

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

    return Response("ok")
コード例 #3
0
ファイル: views.py プロジェクト: doytsujin/tacticalrmm
def update(request):
    data = request.data
    agent_id = data["agentid"]
    hostname = data["hostname"]
    os = data["operating_system"]
    total_ram = data["total_ram"]
    cpu_info = data["cpu_info"]
    plat = data["platform"]
    plat_release = data["platform_release"]
    version = data["version"]
    av = data["av"]

    agent = get_object_or_404(Agent, agent_id=agent_id)

    agent.hostname = hostname
    agent.operating_system = os
    agent.total_ram = total_ram
    agent.cpu_info = cpu_info
    agent.plat = plat
    agent.plat_release = plat_release
    agent.version = version
    agent.antivirus = av

    agent.save(update_fields=[
        "last_seen",
        "hostname",
        "operating_system",
        "total_ram",
        "cpu_info",
        "plat",
        "plat_release",
        "version",
        "antivirus",
    ])

    sync_salt_modules_task.delay(agent.pk)
    get_installed_software.delay(agent.pk)
    get_wmi_detail_task.delay(agent.pk)

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

    # check for updates if this is fresh agent install
    if not WinUpdate.objects.filter(agent=agent).exists():
        check_for_updates_task.delay(agent.pk, wait=True)

    return Response("ok")
コード例 #4
0
def on_agent_first_install(request):
    pk = request.data["pk"]
    agent = get_object_or_404(Agent, pk=pk)

    resp = agent.salt_api_cmd(hostname=agent.salt_id,
                              timeout=60,
                              func="saltutil.sync_modules")
    try:
        data = resp.json()
    except Exception:
        return Response("err", status=status.HTTP_400_BAD_REQUEST)

    try:
        ret = data["return"][0][agent.salt_id]
    except KeyError:
        return Response("err", status=status.HTTP_400_BAD_REQUEST)

    if not data["return"][0][agent.salt_id]:
        return Response("err", status=status.HTTP_400_BAD_REQUEST)

    get_wmi_detail_task.delay(agent.pk)
    get_installed_software.delay(agent.pk)
    check_for_updates_task.delay(agent.pk, wait=True)
    return Response("ok")