4.4.5. Saved queries

API for working with saved queries for assets.

class axonius_api_client.api.assets.saved_query.SavedQuery(parent)[source]

Bases: axonius_api_client.api.mixins.ChildMixins, axonius_api_client.api.mixins.PagingMixinsObject

API object for working with saved queries for the parent asset type.

Examples

Create a client using axonius_api_client.connect.Connect and assume apiobj is either client.devices or client.users

>>> apiobj = client.devices  # or client.users
Parameters

parent (axonius_api_client.api.mixins.Model) –

get_by_name(value, **kwargs)[source]

Get a saved query by name.

Examples

Get a saved query by name

>>> sq = apiobj.saved_query.get_by_name(name="test")
>>> sq['tags']
['Unmanaged Devices']
>>> sq['description'][:80]
'Devices that have been seen by at least one agent or at least one endpoint manag'
>>> sq['view']['fields']
[
    'adapters',
    'specific_data.data.name',
    'specific_data.data.hostname',
    'specific_data.data.last_seen',
    'specific_data.data.network_interfaces.manufacturer',
    'specific_data.data.network_interfaces.mac',
    'specific_data.data.network_interfaces.ips',
    'specific_data.data.os.type',
    'labels'
]
>>> sq['view']['query']['filter'][:80]
'(specific_data.data.adapter_properties == "Agent") or (specific_data.data.adapte'
Parameters
  • value (str) – name of saved query

  • **kwargs – passed to get()

Return type

dict

get_by_uuid(value, **kwargs)[source]

Get a saved query by uuid.

Examples

Get a saved query by uuid

>>> sq = apiobj.saved_query.get_by_uuid(uuid="5f76721ce4557d5cba93f59e")
Parameters
  • value (str) – uuid of saved query

  • **kwargs – passed to get()

Return type

dict

get_by_tags(value, **kwargs)[source]

Get saved queries by tags.

Examples

Get all saved queries with tagged with ‘AD’

>>> sqs = apiobj.saved_query.get_by_tags('AD')
>>> len(sqs)
2

Get all saved queries with tagged with ‘AD’ or ‘AWS’

>>> sqs = apiobj.saved_query.get_by_tags(['AD', 'AWS'])
>>> len(sqs)
5
Parameters
Raises

NotFoundError – if no saved queries found tagged with supplied tags

Return type

typing.List[dict]

get_tags(**kwargs)[source]

Get all tags for saved queries.

Examples

Get all known tags for all saved queries

>>> tags = apiobj.saved_query.get_tags()
>>> len(tags)
19
Parameters

**kwargs – passed to get()

Return type

typing.List[str]

get(generator=False, **kwargs)[source]

Get all saved queries.

Examples

Get all saved queries

>>> sqs = apiobj.saved_query.get()
>>> len(sqs)
39
Parameters
Return type

typing.Union[typing.Generator[dict, None, None], typing.List[dict]]

add(name, query=None, tags=None, description=None, expressions=None, fields=None, fields_manual=None, fields_regex=None, fields_fuzzy=None, fields_default=True, fields_root=None, sort_field=None, sort_descending=True, column_filters=None, gui_page_size=None, private=False, **kwargs)[source]

Create a saved query.

Examples

Create a saved query using a axonius_api_client.api.wizards.wizard.Wizard

>>> parsed = apiobj.wizard_text.parse(content="simple hostname contains blah")
>>> query = parsed["query"]
>>> expressions = parsed["expressions"]
>>> sq = apiobj.saved_query.add(
...     name="test",
...     query=query,
...     expressions=expressions,
...     description="meep meep",
...     tags=["nyuck1", "nyuck2", "nyuck3"],
... )

Notes

Saved Queries created without expressions will not be editable using the query wizard in the GUI. Use axonius_api_client.api.wizards.wizard.Wizard to produce a query and it’s accordant expressions for the GUI query wizard.

Parameters
Return type

dict

delete_by_name(value, **kwargs)[source]

Delete a saved query by name.

Examples

Delete the saved query by name

>>> deleted = apiobj.saved_query.delete_by_name(name="test")
Parameters
  • value (str) – name of saved query to delete

  • **kwargs – passed to get_by_name()

Return type

dict

delete(rows)[source]

Delete saved queries.

Parameters

rows (typing.Union[str, typing.List[dict]]) – list of UUIDs or rows previously fetched saved queries to delete

Return type

typing.List[dict]

_add(data)[source]

Direct API method to create a saved query.

Parameters

data (dict) – saved query metadata

Return type

str

_delete(ids)[source]

Direct API method to delete saved queries.

Parameters

ids (typing.List[str]) – list of uuid’s to delete

Return type

str

_get(query=None, row_start=0, page_size=2000)[source]

Direct API method to get saved queries.

Parameters
  • query (typing.Optional[str]) – filter rows to return

  • row_start (int) – start at row N

  • page_size (int) – fetch N assets

Return type

typing.List[dict]

__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

get_generator(query=None, max_rows=None, max_pages=None, page_size=2000, page_start=0, page_sleep=0, **kwargs)

Get saved queries using paging.

Parameters
  • query (typing.Optional[str]) – mongo query to filter objects to return

  • max_rows (typing.Optional[int]) – only return N objects

  • max_pages (typing.Optional[int]) – only return N pages

  • page_size (int) – fetch N objects per page

  • page_start (int) – start at page N

  • page_sleep (int) – sleep for N seconds between each page fetch

Return type

typing.Generator[dict, None, None]