Different pdf reports ... with gmp tools

hello i want to save a report from a script … it worked well, but the report ist different to the pdf report from gsad …

how can I set the filter?

I tried this:

response = gmp.get_report(report_id=report_id, filter="apply_overrides=0 levels=hml rows=100 min_qod=70 first=1 sort-reverse=severity",report_format_id=pdf_report_format_id)

in my create python script … but with no success:

import sys
from base64 import b64decode
from pathlib import Path
import datetime
import time
import os

def create_report(tname,reportid):
    time1 = datetime.datetime.now()
    timestamp=time1.strftime('%Y-%m-%d_%H_%M')
    pdf_filename = "/tmp/" + tname + "-" + timestamp + ".pdf"
    pdf_report_format_id = "c402cc3e-b531-11e1-9163-406186ea4fc5"
    response = gmp.get_report(report_id=report_id, filter="apply_overrides=0 levels=hml rows=100 min_qod=70 first=1 sort-reverse=severity",report_format_id=pdf_report_format_id)
    report_element = response.find("report")
    content = report_element.find("report_format").tail
    binary_base64_encoded_pdf = content.encode('ascii')
    binary_pdf = b64decode(binary_base64_encoded_pdf)
    pdf_path = Path(pdf_filename).expanduser()
    pdf_path.write_bytes(binary_pdf)
    print("PDF: " + pdf_filename + " created")
    return pdf_filename

task_name=sys.argv[4]
report_id=sys.argv[5]
create_report(task_name,report_id)

the gvm-cli script worked

#!/bin/bash
REPORTID=$1
PDF=$2
FORMATID="c402cc3e-b531-11e1-9163-406186ea4fc5"
gvm-cli tls --hostname=scanner  --xml "<get_reports report_id=\"$REPORTID\" filter=\"apply_overrides=0 levels=hml rows=100 min_qod=70 first=1 sort-reverse=severity\" format_id=\"$FORMATID\" details=\"True\"/>" | grep -oP '(?<=</report_format>)[^<]+'|base64 -d > $PDF

Could you use backticks to reformat your code (see https://guides.github.com/features/mastering-markdown/). It is very difficult to read without a good formatting.

2 Likes

done … ok so far?

gmp.get_report(
        report_id=report_id, report_format_id=pdf_report_format_id
    )

Where can I find information about the arguments for the function gmp.get_report. I find information for the function get_reports … but not all of them fit to get_report?

That depends of course on the used GVM version on your side. Here is the link for the GVM 20.08 API https://python-gvm.readthedocs.io/en/latest/api/gmpv208.html#gvm.protocols.gmpv208.Gmp.get_report

1 Like

Looking at your code I think you just forgot to add the details=True argument.

3 Likes

This was the solution …

1 Like