Gvm-script | Modify task fails on update-task-target.gmp.py

GVM versions

gsad: (Greenbone Security Assistant 21.4.3)
gvmd: (Greenbone Vulnerability Manager 21.4.4)
openvas-scanner: (OpenVAS 21.4.3)
gvm-libs: (gvm-libs 21.4.3)

Environment

Operating system:
NAME=“Ubuntu”
VERSION=“20.04.4 LTS (Focal Fossa)”
Kernel: ('Linux 5.13.0-1017-aws #19~20.04.1-Ubuntu SMP Mon Mar 7 12:53:12 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux)
Installation method / source:
Docker

I’m trying to update the targets of a task using update-task-target.gmp.py. It creates the target successfully as a copy, but fails to update the task with the new target id. The error message returned is “Response Error 400. Status must be New to edit Target”

It looks like neither of these functions get run:

def create_target_hosts(gmp: Gmp, host_file, task_id, old_target_id):
    new_target_id = copy_send_target(gmp, host_file, old_target_id)

    gmp.modify_task(task_id=task_id, target_id=new_target_id)

    print('  Task successfully modified!\n')


def check_to_delete(gmp: Gmp, target_id: str) -> None:
    target = gmp.get_target(target_id=target_id)[0]
    if '0' in target.xpath("in_use/text()"):
        gmp.delete_target(target_id=target_id)

Is there a way around this? I’m simply trying to have a task named “monthly scan” and update the targets to the task monthly and rescan. This way I can keep previous reports and rerun the same tasks with new updated targets. It looks as though the status of the task needs to be “New”. Is there a way to get around this?

Hi Sw1tch.

As the Error message correctly told you, the status of the Task must be new. You can not change the target of a task in any other status, like queued, interrupted, finished, etc! So there is no way to change the target of your monthly scan. If the target changed, you probably need to create a new task for it. (The same for the target, you can not change the “target in use”.)

1 Like