Unable to delete report with python-gvm

Hi,

I am trying to delete existing reports using the python-gvm library but I keep getting a “404 Failed to find report …” error while am sure the report exists!

Am I doing something wrong ? I can’t seem to wrap my head around this.

This is the code am running:

...
# Fetching reports using gmp.get_reports() -> OK
...

for report in reports:
  if report.get("id"):
    print(report.get("id"))
    print(gmp.get_report(report.get("id")))
    gmp.delete_report(report.get("id"))

...

This is the output:

<Element get_reports_response at 0x7f9521bd6240>
6714a663-184a-4509-8e00-ad4446a63792
2022-08-11 08:15:38 WARNING  Lost the connection to GVM. So, kill the container.
Traceback (most recent call last):
  File "mapper.py", line 289, in fetch_reports
    gmp.delete_report(report.get("id"))
  File "/usr/local/lib/python3.8/dist-packages/gvm/protocols/gmpv208/entities/reports.py", line 45, in delete_report
    return self._send_xml_command(cmd)
  File "/usr/local/lib/python3.8/dist-packages/gvm/protocols/base.py", line 86, in _send_xml_command
    return self.send_command(xmlcmd.to_string())
  File "/usr/local/lib/python3.8/dist-packages/gvm/protocols/base.py", line 142, in send_command
    return self._transform(response)
  File "/usr/local/lib/python3.8/dist-packages/gvm/protocols/base.py", line 78, in _transform
    return transform(data)
  File "/usr/local/lib/python3.8/dist-packages/gvm/transforms.py", line 79, in __call__
    check_command_status(root)
  File "/usr/local/lib/python3.8/dist-packages/gvm/transforms.py", line 49, in check_command_status
    raise GvmResponseError(status=status, message=root.get("status_text"))
gvm.errors.GvmResponseError: Response Error 404. Failed to find report '6714a663-184a-4509-8e00-ad4446a63792'

Thx.

Hi,

could you enhance the logging by using the https://python-gvm.readthedocs.io/en/latest/api/connections.html#gvm.connections.DebugConnection ?

1 Like

Hi,

Thank you for your quick response.

You’ll find the “improved logs” below. Note that I removed a whole chunk of xml data that didn’t seem
relevant.

6714a663-184a-4509-8e00-ad4446a63792
2022-08-11 08:59:50 DEBUG    Sending 75 characters. Data <get_reports report_id="6714a663-184a-4509-8e00-ad4446a63792" details="1"/>
2022-08-11 08:59:51 DEBUG    Read 2080714 characters. Data <get_reports_response status="200" status_text="OK"><report id="6714a663-184a-4509-8e00-ad4446a63792" format_id="" extension="" content_type="application/xml"><owner><name>admin</name></owner><name>2022-08-11T07:30:42Z</name><comment></comment><creation_time>2022-08-11T07:30:42Z</creation_time><modification_time></modification_time><writable>0</writable><in_use>0</in_use><task id="4450d9fd-3154-4355-a2f9-1a31fec61856"><name>Workstation</name></task><report id="6714a663-184a-4509-8e00-ad4446a63792"><gmp><version>21.4</version></gmp><sort><field>name<order>ascending</order></field></sort><filters id=""><term>apply_overrides=0 min_qod=70 first=1 rows=10 sort=name</term><filter>High</filter><filter>Medium</filter><filter>Low</filter><filter>Log</filter><keywords><keyword><column>apply_overrides</column><>=</
...

...
name><value>8010::F3B7C1135BA19D7E802188C2936C2FA054BE387200AEF60E952C8EF1A90AA44D</value><source><type>nvt</type><name>1.3.6.1.4.1.25623.1.0.103692</name><description>SSL/TLS Certificate Information</description></source><extra></extra></detail><detail><name>SSLInfo</name><value>2905::81CB6E25CBC2C9627A5C86F14C014098B58553A724C659484620683BE86D9C8D</value><source><type>nvt</type><name>1.3.6.1.4.1.25623.1.0.103692</name><description>SSL/TLS Certificate Information</description></source><extra></extra></detail><detail><name>SSLInfo</name><value>8015::C491851E713B1500CECE6C3AADE278355654BDE71E37B578EC6F97803C670D21</value><source><type>nvt</type><name>1.3.6.1.4.1.25623.1.0.103692</name><description>SSL/TLS Certificate Information</description></source><extra></extra></detail><detail><name>SSLInfo</name><value>21::9E55891D852A2EFEAC6FCC9CC89B96849DFB6CDF7EEB3D39CFFEF279D3350F79</value><source><type>nvt</type><name>1.3.6.1.4.1.25623.1.0.103692</name><description>SSL/TLS Certificate Information</description></source><extra></extra></detail></host><scan_end></scan_end><errors><count>0</count></errors></report></report><filters id=""><term>apply_overrides=0 min_qod=70 first=1 rows=10 sort=name</term><keywords><keyword><column>apply_overrides</column><relation>=</relation><value>0</value></keyword><keyword><column>min_qod</column><relation>=</relation><value>70</value></keyword><keyword><column>first</column><relation>=</relation><value>1</value></keyword><keyword><column>rows</column><relation>=</relation><value>10</value></keyword><keyword><column>sort</column><relation>=</relation><value>name</value></keyword></keywords></filters><sort><field>name<order>ascending</order></field></sort><reports start="1" max="1000"/><report_count>1<filtered>1</filtered><page>1</page></report_count></get_reports_response>
<Element get_reports_response at 0x7f5ec37d9300>
2022-08-11 08:59:51 DEBUG    Sending 65 characters. Data <delete_report report_id="6714a663-184a-4509-8e00-ad4446a63792"/>
2022-08-11 08:59:51 DEBUG    Read 113 characters. Data <delete_report_response status="404" status_text="Failed to find report '6714a663-184a-4509-8e00-ad4446a63792'"/>
2022-08-11 08:59:51 WARNING  Lost the connection to GVM. So, kill the container.
Traceback (most recent call last):
  File "mapper.py", line 289, in fetch_reports
    gmp.delete_report(report.get("id"))
  File "/usr/local/lib/python3.8/dist-packages/gvm/protocols/gmpv208/entities/reports.py", line 45, in delete_report
    return self._send_xml_command(cmd)
  File "/usr/local/lib/python3.8/dist-packages/gvm/protocols/base.py", line 86, in _send_xml_command
    return self.send_command(xmlcmd.to_string())
  File "/usr/local/lib/python3.8/dist-packages/gvm/protocols/base.py", line 142, in send_command
    return self._transform(response)
  File "/usr/local/lib/python3.8/dist-packages/gvm/protocols/base.py", line 78, in _transform
    return transform(data)
  File "/usr/local/lib/python3.8/dist-packages/gvm/transforms.py", line 79, in __call__
    check_command_status(root)
  File "/usr/local/lib/python3.8/dist-packages/gvm/transforms.py", line 49, in check_command_status
    raise GvmResponseError(status=status, message=root.get("status_text"))
gvm.errors.GvmResponseError: Response Error 404. Failed to find report '6714a663-184a-4509-8e00-ad4446a63792'

Thanks. Seems that the XML doesn’t contain additional info sadly. There is a suspicious message in your logs

2022-08-11 08:59:51 WARNING  Lost the connection to GVM. So, kill the container.

It interpret this message that gvmd has exit in some way. Could you check the output in gvmd.log file?

2 Likes

I checked in the output of the gvmd.log file but couldn’t find any indication on what happened.

In the meantime, I decided to delete the whole task once it’s done which also removes the linked reports.
I don’t need to remove individual reports anymore.

Thx for the help though!