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

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)[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

Return type

dict

get_by_uuid(value)[source]

Get a saved query by uuid.

Examples

Get a saved query by uuid

>>> sq = apiobj.saved_query.get_by_uuid(value="5f76721ce4557d5cba93f59e")
Parameters

value (str) – uuid of saved query

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)[source]

Get all saved queries.

Examples

Get all saved queries

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

generator (bool) – return an iterator

Return type

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

get_generator()[source]

Get Saved Queries using a generator.

Return type

typing.Generator[dict, None, None]

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, always_cached=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[str], typing.List[dict]]) – list of UUIDs or rows previously fetched saved queries to delete

Return type

typing.List[str]

_add(name, view, description='', always_cached=False, private=False, tags=None)[source]

Direct API method to create a saved query.

Parameters
Return type

str

_delete(uuid)[source]

Direct API method to delete saved queries.

Parameters
  • ids – list of uuid’s to delete

  • uuid (str) –

Return type

axonius_api_client.api.json_api.generic.Metadata

_get(limit=2000, offset=0)[source]

Direct API method to get all users.

Parameters
  • limit (int) – limit to N rows per page

  • offset (int) – start at row N

Return type

typing.List[axonius_api_client.api.json_api.saved_queries.SavedQuery]

__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