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.
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 …
I’m already doing that
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()')
medium = host.xpath('result_count/warning/page/text()')
low = host.xpath('result_count/info/page/text()')
print("Count: ", high, medium, low)
Thats just an example and an additional Problem from 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)
<Element get_reports_response at 0x109422f00>
>>> werte = res.xpath('report/report/host')
[<Element host at 0x109422580>, <Element host at 0x109422240>]
>>> for host in werte:
... high = host.xpath('result_count/hole/page/text()')
... medium = host.xpath('result_count/warning/page/text()')
... low = host.xpath('result_count/info/page/text()')
... print("Count: ", high, medium, low)
Count: 13 29 5
Count: 21 29 3