4.4.4. Tags

Warning

This API is deprecated.

Axonius API v2 is now available, we recommend you move to API v2.

New features will no longer be added to this API. Axonius will only provide bug fixes.

Read about API v2

API for working with tags for assets.

class axonius_api_client.api.assets.labels.Labels(parent)[source]

Bases: ChildMixins

API for working with tags for the parent asset type.

Examples

Parameters:

parent (axonius_api_client.api.mixins.Model) –

get()[source]

Get all known tags. :rtype: typing.List[str]

Examples

Get all known tags for this asset type

>>> import axonius_api_client as axonapi
>>> connect_args: dict = axonapi.get_env_connect()
>>> client: axonapi.Connect = axonapi.Connect(**connect_args)
>>> apiobj: axonapi.api.assets.AssetMixin = client.devices
>>>       # or client.users or client.vulnerabilities
>>> apiobj.labels.get()
['tag1', 'tag2', 'tag3']
get_expirable_names()[source]

Get all known expirable tags. :rtype: typing.List[str]

Examples

Get all known expirable tags for this asset type

>>> import axonius_api_client as axonapi
>>> connect_args: dict = axonapi.get_env_connect()
>>> client: axonapi.Connect = axonapi.Connect(**connect_args)
>>> apiobj: axonapi.api.assets.AssetMixin = client.devices
>>>       # or client.users or client.vulnerabilities
>>> apiobj.labels.get_expirable_names()
['tag1', 'tag2']
static _set_expirable_tags(expirations)[source]

Get dict with tags as keys and expiration date as values expiration date can be as either

  • date as a string (YYYY-MM-DD)

  • int specify the “days from now”

Converts it to a List of dicts for each tag

Parameters:
  • expirations (dict) – Dict with tag name and tag expiration date

  • {'tag1' – ‘2024-01-01’, ‘tag2’: 5}

Return type:

typing.List[dict]

Returns:

List of dicts, each dict contains single tag name and tag expiration date [{‘name’: ‘tag1’, ‘expiration_date’: ‘2024-01-01’}, …]

add(rows, labels, invert_selection=False, expirable_tags=None)[source]

Add tags to assets.

Examples

Get some assets to tag

>>> import axonius_api_client as axonapi
>>> connect_args: dict = axonapi.get_env_connect()
>>> client: axonapi.Connect = axonapi.Connect(**connect_args)
>>> apiobj: axonapi.api.assets.AssetMixin = client.devices
>>>       # or client.users or client.vulnerabilities
>>> rows = apiobj.get(wiz_entries=[{'type': 'simple', 'value': 'name equals test'}])
>>> len(rows)
1
>>> apiobj.labels.add(
        rows=rows,
        labels=['api tag 1', 'api tag 2'],
        expirable_tags={'api tag 1': '2024-01-25', 'api tag 2': 5},
    )
1
Parameters:
  • rows (typing.Union[typing.List[dict], str]) – list of internal_axon_id strs or list of assets returned from a get method

  • labels (typing.List[str]) – tags to add

  • invert_selection (bool) – True=add tags to assets that ARE NOT supplied in rows; False=add tags to assets that ARE supplied in rows

  • expirable_tags (typing.Optional[dict]) – Dict with tag name and expiration_date (string or int) as keys - expiration_date as string is a date (YYYY-MM-DD) - expiration_date as int is days from now

Return type:

int

_add(labels, ids, include=True, expirable_tags=None)[source]

Direct API method to add labels/tags to assets.

Parameters:
  • labels (typing.List[str]) – tags to process

  • ids (typing.List[str]) – internal_axon_id of assets to add tags to

  • include (bool) – True=add tags to assets that ARE supplied in rows; False=add tags to assets that ARE NOT supplied in rows

  • expirable_tags (typing.Optional[typing.List[dict]]) – List of dicts, each dict with tag name and expiration_date

Return type:

axonius_api_client.api.json_api.generic.IntValue

remove(rows, labels, invert_selection=False)[source]

Remove tags from assets.

Examples

Get some assets to un-tag >>> import axonius_api_client as axonapi >>> connect_args: dict = axonapi.get_env_connect() >>> client: axonapi.Connect = axonapi.Connect(**connect_args) >>> apiobj: axonapi.api.assets.AssetMixin = client.devices >>> # or client.users or client.vulnerabilities >>> data = apiobj.get(wiz_entries=[{‘type’: ‘simple’, ‘value’: ‘name equals test’}]) >>> len(data) 1 >>> apiobj.labels.remove(rows=data, labels=[‘api tag 1’, ‘api tag 2’]) 1

Parameters:
  • rows (typing.List[dict]) – list of internal_axon_id strs or list of assets returned from a get method

  • labels (typing.List[str]) – tags to remove

  • invert_selection (bool) – True=remove tags from assets that ARE NOT supplied in rows; False=remove tags from assets that ARE supplied in rows

Return type:

int

_remove(labels, ids, include=True)[source]

Direct API method to remove labels/tags from assets.

Parameters:
  • labels (typing.List[str]) – tags to process

  • ids (typing.List[str]) – internal_axon_id of assets to remove tags from

  • include (bool) – True=remove tags from assets that ARE supplied in rows; False=remove tags from assets that ARE NOT supplied in rows

Return type:

axonius_api_client.api.json_api.generic.IntValue

static _get_ids(rows)[source]

Get the internal_axon_id from a list of assets.

Parameters:

rows (typing.Union[typing.List[dict], str]) – list of internal_axon_id strs or list of assets returned from a get method

Return type:

typing.List[str]

property asset_type: str

Get the asset type of the parent AssetMixin.

_get()[source]

Direct API method to get all known labels/tags.

Return type:

typing.List[axonius_api_client.api.json_api.generic.StrValue]

_get_expirable_names()[source]

Direct API method to get all known expirable labels/tags.

Return type:

typing.List[axonius_api_client.api.json_api.generic.StrValue]

LOG: logging.Logger = None

Logger for this object.

__init__(parent)

Mixins model for API child objects.

Parameters:

parent (axonius_api_client.api.mixins.Model) – parent API model of this child

__repr__()

Show info for this model object.

Return type:

str

__str__()

Show info for this model object.

Return type:

str

_init(parent)

Post init method for subclasses to use for extra setup.

Parameters:

parent (axonius_api_client.api.mixins.Model) – parent API model of this child

auth: axonius_api_client.auth.model.AuthModel = None

Authentication model with bound Http object to use for requests.

http: axonius_api_client.http.Http = None

Http object to use for requests.

parent: axonius_api_client.api.mixins.Model = None

Parent API model of this child.