Get_reports returns empty list

I am testing the gvm-script commands to process results.

all_tasks = gmp.get_tasks().xpath("task")
for task in all_tasks:
  task_id = task.xpath("@id")[0]
  task_name = task.xpath("name/text()")[0]
  print(f'Processing task "{task_name}" ({task_id})...')
  reports = gmp.get_reports(
                    "sort-reverse=date", details=True, ignore_pagination=True
  print(f"  Found {str(len(reports))} report(s).")

This snippet does not list all tasks and always zero reports to a task, why?
The code is similar to this script example.

For example, I can retrieve all tasks with gvm-cli socket --xml "<get_tasks ignore_pagination=\"1\"/> but gmp.get_tasks does not provide a ignore_pagination option?

I can confirm that while this code fetches all the tasks for me, as you mentioned it does not fetch any reports attached to those tasks. Even using the default filter from the code you linked to:

reports = gmp.get_reports(
            filter_string="task_id={task_id} and status=Done "

However, the default filter works when used from the web-interface.

This is a Python programming issue. You need to use an f-string here.


Ohh, nice catch! So I guess the gvm-tools script needs to be updated.

1 Like

gmp.get_tasks().xpath("task") fetches only the first 10 tasks on my side.
Can you fetch more than 10 tasks?

:thinking: Not sure why, I am able to fetch all my tasks (27 for this installation).

It fetches only the first ten, which are shown on the web interface before you have to scroll to the next page.
The same behavior as the xml version without ignore_pagination.

If it matters, I am using the unix socket from the docker container.

I don’t have any custom filters set on Kali native installation but my tasks page is not limited to 10 items - seems the GB Docker containers are different. The solution is to create a custom filter_string and submit it with the get_tasks() function. Maybe the ignore_pagination field can be submitted with the filter_string, or else use the filter string rows=-1.

A quick tour through the community forum could produce some potential solutions.

For example: Max row per page

1 Like

I think send delta emails is more outdated.

I could fix the empty list problem, but at this line format_id does not exist. It should be report_format_id.

If I replace this parameter, the error appears:
Unable to send the email. Error: <class 'TypeError'>
An email is sent with a report and no results.

How can I fix this?

I see what you mean. Without having actually tried this script myself, I would start by enabling better error reporting using Python’s traceback module and print a full traceback since it seems custom error in the try catch seems limited and doesn’t provide full traceback.

If you look at the docs for the get_report() function You could also try using an ENUM which is shows as a potential input type here

Seems you have uncovered a bug in the gvm-tools script and also maybe GMP get_report function.