Gvm-cli, get_assets: How to "<tag> *Short info on an individual tag (only if details were requested)."

Hi, I’m trying to get the full response when issuing the get_assets command, i.e. I want to request the details…
I know it is possible (gsa does it) but I can’t find any documentation on how to request the details.
The xml part of the command looks like this:

“<get_assets type=“host” filter=“ip=10.0.0.11” ignore_pagination=“true”/>”

Background: I just want to generate a list of tags attached to the specified host.
TIA
Jürgen

gvm-cli 21.1.0 (API version 21.1.3)

Please use the latest version of python-gvm and gvm-tools for these commands.
They are also documented here. E.g. get_host.

You can use gvm-tools's gvm-pyshell to run API calls.
Here is an example:

(.venv) bash-3.2$ gvm-pyshell --gmp-username=xxx --gmp-password=xxx ssh --hostname foo.bar.baz
GVM Interactive Console 21.6.2.dev1 API 21.6.0. Type "help" to get information about functionality.
>>> resp = gmp.get_hosts(filter_string="ip=10.0.0.1")
>>> pretty_print(resp)
<get_assets_response status="200" status_text="OK">
  <filters id="">
    <term>ip=10.0.0.1 first=1 rows=100 sort=name</term>
    <keywords>
      <keyword>
        <column>ip</column>
        <relation>=</relation>
        <value>10.0.0.1</value>
      </keyword>
      <keyword>
        <column>first</column>
        <relation>=</relation>
        <value>1</value>
      </keyword>
      <keyword>
        <column>rows</column>
        <relation>=</relation>
        <value>100</value>
      </keyword>
      <keyword>
        <column>sort</column>
        <relation>=</relation>
        <value>name</value>
      </keyword>
    </keywords>
  </filters>
  <sort>
    <field>name<order>ascending</order></field>
  </sort>
  <assets start="1" max="100"/>
  <asset_count>3329<filtered>0</filtered><page>0</page></asset_count>
</get_assets_response>
>>> resp = gmp.get_hosts(filter_string="ip=127.0.0.1")
>>> pretty_print(resp)
<get_assets_response status="200" status_text="OK">
  <asset id="7300767c-9c99-4ce3-b6f2-b983be7d42c8">
    <owner>
      <name>jloechte</name>
    </owner>
    <name>127.0.0.1</name>
    <comment/>
    <creation_time>2021-01-15T20:28:34Z</creation_time>
    <modification_time>2021-01-16T18:19:26Z</modification_time>
    <writable>1</writable>
    <in_use>0</in_use>
    <permissions>
      <permission>
        <name>Everything</name>
      </permission>
    </permissions>
    <identifiers>
      <identifier id="64b8b16f-9420-49c2-b6ad-0fbcc9560a9c">
        <name>ip</name>
        <value>127.0.0.1</value>
        <creation_time>2021-01-16T18:19:26Z</creation_time>
        <modification_time>2021-01-16T18:19:26Z</modification_time>
        <source id="0dbdeabc-ab07-403c-968b-86873a6c345b">
          <type>Report Host</type>
          <data/>
          <deleted>0</deleted>
          <name/>
        </source>
      </identifier>
      <identifier id="0d5abccf-0858-4cfb-8221-afec22c295fc">
        <name>ip</name>
        <value>127.0.0.1</value>
        <creation_time>2021-01-16T02:03:56Z</creation_time>
        <modification_time>2021-01-16T02:03:56Z</modification_time>
        <source id="f54ed443-29e5-478a-b605-e49db06e6687">
          <type>Report Host</type>
          <data/>
         ...
      </detail>
    </host>
  </asset>
  <filters id="">
    <term>ip=127.0.0.1 first=1 rows=100 sort=name</term>
    <keywords>
      <keyword>
        <column>ip</column>
        <relation>=</relation>
        <value>127.0.0.1</value>
      </keyword>
      <keyword>
        <column>first</column>
        <relation>=</relation>
        <value>1</value>
      </keyword>
      <keyword>
        <column>rows</column>
        <relation>=</relation>
        <value>100</value>
      </keyword>
      <keyword>
        <column>sort</column>
        <relation>=</relation>
        <value>name</value>
      </keyword>
    </keywords>
  </filters>
  <sort>
    <field>name<order>ascending</order></field>
  </sort>
  <assets start="1" max="100"/>
  <asset_count>3329<filtered>1</filtered><page>1</page></asset_count>
</get_assets_response>
>>>
1 Like

Alternatively you can use gvm-cli and use the xml you mentioned.

The trick here is to not mix up the quotes. Use single quotations for the xml and double quotes within the xml:

(.venv) bash-3.2$ gvm-cli --gmp-username=xxx --gmp-password=xxx ssh --hostname foo.bar.baz --xml '<get_assets type="host" filter="ip=10.0.0.11" ignore_pagination="true"/>'
<get_assets_response status="200" status_text="OK"><filters id=""><term>ip=10.0.0.11 first=1 rows=100 sort=name</term><keywords><keyword><column>ip</column><relation>=</relation><value>10.0.0.11</value></keyword><keyword><column>first</column><relation>=</relation><value>1</value></keyword><keyword><column>rows</column><relation>=</relation><value>100</value></keyword><keyword><column>sort</column><relation>=</relation><value>name</value></keyword></keywords></filters><sort><field>name<order>ascending</order></field></sort><assets start="1" max="100"/><asset_count>3329<filtered>0</filtered><page>0</page></asset_count></get_assets_response>
1 Like

Oh sorry, I just saw that the escaping backslashes in the first posting are gone…
I’ve gotten no error in the response (I used double quotes outside and escaped double quotes inside the xml) in response to my gvm-cli command.
The problem was that I’m only getting the tag count(!) but nothing else (no uuids an so on).
I need these uuids to detach some tags from the assets.
The documentation states that I have to request “the details”… But how??

Ahh! Ok. Here you are:

(.venv) bash-3.2$ gvm-cli --gmp-username=xxx --gmp-password=xxx ssh --hostname foo.bar.baz --xml '<get_assets type="host" filter="ip=10.0.0.11" ignore_pagination="true" details="1"/>'
<get_assets_response status="200" status_text="OK"><asset id="1e3aa7b9-7db3-494c-ab20-d6ec9a2a9402"><owner><name>jloechte</name></owner><name>10.0.0.11</name><comment>bloob bloob</comment><creation_time>2021-08-05T05:31:49Z</creation_time><modification_time>2021-08-05T05:31:49Z</modification_time><writable>1</writable><in_use>0</in_use><permissions><permission><name>Everything</name></permission></permissions><user_tags><count>1</count><tag id="e7865804-ea4d-4a36-ba25-35e0be9c4efd"><name>moos:bunnamed</name><value>sssd</value><comment>asfsd</comment></tag></user_tags><identifiers><identifier id="d024b231-496a-4d51-9fc1-a0b637148e3a"><name>ip</name><value>10.0.0.11</value><creation_time>2021-08-05T05:31:49Z</creation_time><modification_time>2021-08-05T05:31:49Z</modification_time><source id="3d74cfb5-a7bf-4c7e-b25d-0a719ec3f32a"><type>User</type><data></data><deleted>0</deleted><name>jloechte</name></source></identifier></identifiers><type>host</type><host><severity><value></value></severity></host></asset><filters id=""><term>ip=10.0.0.11 first=1 rows=100 sort=name</term><keywords><keyword><column>ip</column><relation>=</relation><value>10.0.0.11</value></keyword><keyword><column>first</column><relation>=</relation><value>1</value></keyword><keyword><column>rows</column><relation>=</relation><value>100</value></keyword><keyword><column>sort</column><relation>=</relation><value>name</value></keyword></keywords></filters><sort><field>name<order>ascending</order></field></sort><assets start="1" max="100"/><asset_count>3330<filtered>1</filtered><page>1</page></asset_count></get_assets_response>

Set details="1"!

2 Likes

Ahhh, thank you! I was quite sure that I tested it that way already :slight_smile:
Now it works!
Regards
Juergen

Just curious: Where did you find it in the docs?
I couldn’t find it here:https://docs.greenbone.net/API/GMP

Yes I have seen, that it is missing. I will contact the responsible person, to add it!

1 Like