Gvm-tool create_task hosts_ordering

Hello,

We are using gvm-tools to successfully create targets and tasks.

The code below works as expected without ‘hosts_ordering=scan_order’, when it is present, we get the following error: “In create_task the argument hosts_ordering must be of type HostsOrdering.”

Looking in the docs, hosts_ordering appears as though it should be str text format and enumerate to ‘random’, ‘reverse’ or ‘sequential’, but there are no examples with that parameter being passed specifically.

Where would be a good place to look for additional troubleshooting items? Does anyone have an example of successfully passing this parameter?

def create_task(gmp, target_name, target_id, scan_config_id, scanner_id, alerts):
name = “Scan Suspect Target {}”.format(target_name)
scan_order = ‘random’
response = gmp.create_task(
name=name,
config_id=scan_config_id,
target_id=target_id,
scanner_id=scanner_id,
alert_ids=alerts,
hosts_ordering=scan_order
)
return response.get(‘id’)

A quick followup.

We included the following module and updated the variable definition as follows:

from gvm.protocols.gmpv208.entities.hosts import HostsOrdering

scan_order = HostsOrdering.RANDOM

Results are as expected with tasks having host ordering set to ‘random’

2 Likes