Gvm-cli XML output question


#1

Hi All,

I’m trying to play with gvm-cli to parse XML output in scripting. With omp XML output contained newline after each parameter. With gvm-cli, there is no more newlines. XML output is bulk XML, which makes it harder for parsing.

I was wondering of any tool available to ease xml parsing. Any suggestions welcome !

Thanks


#2

You could pipe the output through xmllint --format but maybe it’s better for your use case to write a gmp script.


#3

Well the issue is you have to know python… which I don’t :frowning:
Currently my bash scripts does what I need, so it’s fine. I just need to make it work with gvm. The main problem I have is that with omp you could retrieve informations directly (such as tasks), while with gvm you have to send XML instructions. And XML is kind of cryptic to me.


#4

The documentation of the xml based Greenbone Management Protocol (GMP) can be found at

https://docs.greenbone.net/API/GMP/gmp-7.0.html

Most of the commands are straight forward like <get_tasks/>, <get_reports/>, … to get data but understanding XML is crucial for extracting specific data from the responses.


#5

Yes, you are perfectly right and that’s what I’m trying to at the moment. But I can’t figure out how to extract a sub data from XML. For instance, I have several tasks called:

Target A, subnet 1
Target A, subnet 2

Target B, subnet 1
Target B, subnet 2

Now I want to extract all target IDs of group “Target A” and not Target B. How do you achieve this with xmlstartlet ?

Thanks !


#6

I assume a Powerfilter will solve your challenge:

https://docs.greenbone.net/GSM-Manual/gos-4/en/gui_introduction.html#powerfilter

Perhaps in your case something like

<get_tasks filter=’“Target A”’/>

You can play with the GUI to find the right filter and then copy the string from there into your GMP script.


#7

I am not sure what you exactly want to read from the response. E.g. an XPath for getting the task ids for all tasks using the target with name Target A from a <get_tasks/> response would be

task[target[name="Target A"]]/@id

#8

Thank you guys for your replies. Thanks to your inputs I was able to do what I was looking for. So now I’m able to get my reports in csv using gvm-cli. I’m still struggling with some data consistencies issues between openvas8/openvas9 that will be another post.

Thanks !