How to get Report Values?

Hi everyone,

I need help for my GMP-Script…
I want to get some values from the last report of a specific task and output them in the console.
I know how to get the last_report_id of a specific task but i have problems to extract the data from the report_xml.
Do you have any ideas about a for loop or a filter?

The Values i need, are:
The Host IP, Host Severity, Host High/Medium/Low Amount and the date of the last scan.

Best regards
Marc

You can build your filter interactively and save it. Or just export it as XML to use it as reference.

The loop needs to be scripted with your script-language of your preference.

1 Like

First of all. Welcome!

I suggest you to use the gvm-tools.
You can use gvm-pyshell to run an interactive python shell with an active GMP connection.

Here you can lookup the task with gmp.get_task(...) and extract the report_id you want.
Afterwards you can run gmp.get_report(report_id, details=True) and with pretty_print() you can look into the XML structure.
Afterwards you can try to iterate through that XML …

Thanks for your Answer!
How can i use this gvm-pyshell?

There are also different scripts that are already doing what you want …
Looking up the latest report of a task, is done by this one e.g.: https://github.com/greenbone/gvm-tools/blob/master/scripts/create-consolidated-report.gmp.py
Report different amounts of found Vulnerabilities is done by this one: https://github.com/greenbone/gvm-tools/blob/master/scripts/monthly-report.gmp.py

Maybe you can extract the relevant things you need for your own script.

You need to install gvm-tools … https://gvm-tools.readthedocs.io
With pip or by source from git …
You will need basic Python skills. :wink:

I’m already doing that :slight_smile:
Here I have the error, that I always get 0 for the “result_count” value…

   res = gmp.get_report(report_id=last_report_id, details=True)
            werte = res.xpath('report/report/host')
            for host in werte:
                high = host.xpath('result_count/hole/page/text()')[0]
                medium = host.xpath('result_count/warning/page/text()')[0]
                low = host.xpath('result_count/info/page/text()')[0]
                print("Count: ", high, medium, low)

Thats just an example and an additional Problem from me :smiley:

result_count is not in ‘report/report/host’, but in ‘report/report’

But i need the result_count of each host. This value is in my xml in ```
report/report/host

Are there results for the hosts? Can you confirm that by the overall result count?

1 Like

There are results for the hosts, but the output is always 0…

<host>
   <ip>###</ip>
   <asset asset_id="###"/>
   <start>2021-01-12T11:26:04Z</start>
   <end>2021-01-12T12:02:22Z</end>
   <port_count>
   </port_count>
   <result_count>
     <page>33</page>
     <hole>
       <page>6</page>
     </hole>
     <warning>
       <page>23</page>
     </warning>
     <info>
       <page>4</page>
     </info>

I will try your code later!

2 Likes

Works for me …:

GVM Interactive Console 21.1.1.dev1 API 21.1.3. Type "help" to get information about functionality.
>>> res = gmp.get_report(report_id='f7d7ba9b-bec8-436b-ae33-94c340153a17', details=True)
>>> res
<Element get_reports_response at 0x109422f00>
>>> werte = res.xpath('report/report/host')
>>> werte
[<Element host at 0x109422580>, <Element host at 0x109422240>]
>>> for host in werte:
...     high = host.xpath('result_count/hole/page/text()')[0]
...     medium = host.xpath('result_count/warning/page/text()')[0]
...     low = host.xpath('result_count/info/page/text()')[0]
...     print("Count: ", high, medium, low)
...
Count:  13 29 5
Count:  21 29 3
>>>
1 Like