4.3.1. Adapters

API for working with adapters.

class axonius_api_client.api.adapters.adapters.Adapters(auth, **kwargs)[source]

Bases: axonius_api_client.api.mixins.ModelMixins

API model for working with adapters.

Examples

Create a client using axonius_api_client.connect.Connect

Notes

All methods use the Core instance by default, but you can work with another instance by passing the name of the instance to node.

Supplying unknown keys/values for configurations will throw an error showing the valid keys/values.

Parameters

auth (axonius_api_client.auth.models.Model) –

get()[source]

Get all adapters on all nodes.

Examples

Create a client using axonius_api_client.connect.Connect.

Get all adapters

>>> adapters = client.adapters.get()

Get details of each adapter

>>> for adapter in adapters:
...     print(adapter["name"])  # name of adapter
...     print(adapter["node_name"])  # name of node adapter is running on
Return type

typing.List[dict]

get_by_name(name, node=None)[source]

Get an adapter by name on a single node.

Examples

Create a client using axonius_api_client.connect.Connect.

Get an adapter by name

>>> adapter = client.adapters.get_by_name(name="aws")

Get details of adapter

>>> adapter['status']               # overall adapter status
'success'
>>> adapter['cnx_count_total']      # total connection count
1
>>> adapter['cnx_count_broken']     # broken connection count
0
>>> adapter['cnx_count_working']    # working connection count
1

Get details of each connection of the adapter

>>> for cnx in adapter["cnx"]:
...     print(cnx["working"])  # bool if connection is working or not
...     print(cnx["error"])  # error from last fetch attempt
...     print(cnx["config"])  # configuration of connection
...     print(cnx["id"])  # ID of connection
...     print(cnx["uuid"])  # UUID of connection
Parameters
Raises

NotFoundError – when no node found or when no adapter found on node

Return type

dict

config_get(name, node=None, config_type='generic')[source]

Get the advanced settings for an adapter.

Examples

Create a client using axonius_api_client.connect.Connect.

Get the generic advanced settings for an adapter

>>> config = client.adapters.config_get(name="aws")

Get the adapter specific advanced settings for an adapter

>>> config = client.adapters.config_get(name="aws", config_type="specific")

Get the discovery advanced settings for an adapter

>>> config = client.adapters.config_get(name="aws", config_type="discovery")

See the current values of a configuration

>>> import pprint
>>> pprint.pprint(config['config'])
{'connect_client_timeout': 300,
 'fetching_timeout': 43200,
 'last_fetched_threshold_hours': 48,
 'last_seen_prioritized': False,
 'last_seen_threshold_hours': 24,
 'minimum_time_until_next_fetch': None,
 'realtime_adapter': False,
 'user_last_fetched_threshold_hours': 48,
 'user_last_seen_threshold_hours': None}

Investigate the schema and current values of a configuration

>>> for setting, info in config['schema'].items():
...    current_value = config['config'][setting]
...    title = info['title']
...    description = info.get('description')
...    print(f"name of setting: {setting}")
...    print(f"  title of setting in GUI: {title}")
...    print(f"  description of setting: {description}")
...    print(f"  current value of setting: {current_value}")
Parameters
  • name (str) – name of adapter to get advanced settings of

  • node (typing.Optional[str]) – name of node to get adapter from

  • config_type (str) – One of generic, specific, or discovery

Return type

dict

config_update(name, node=None, config_type='generic', **kwargs)[source]

Update the advanced settings for an adapter.

Examples

Create a client using axonius_api_client.connect.Connect.

Update the generic advanced settings for the adapter

>>> updated_config = client.adapters.config_update(
...     name="aws", last_seen_threshold_hours=24
... )

Update the adapter specific advanced settings

>>> updated_config = client.adapters.config_update(
...     name="aws", config_type="specific", fetch_s3=True
... )

Update the discovery advanced settings >>> # XXX currently broken!

Parameters
  • name (str) – name of adapter to update advanced settings of

  • node (typing.Optional[str]) – name of node to get adapter from

  • config_type (str) – One of generic, specific, or discovery

  • **kwargs – configuration to update advanced settings of config_type

Return type

dict

file_upload(name, field_name, file_name, file_content, file_content_type=None, node=None)[source]

Upload a file to a specific adapter on a specific node.

Examples

Create a client using axonius_api_client.connect.Connect.

Upload content as a file for use in a connection later

>>> content = "content of file to upload"
>>> file_uuid = client.adapters.file_upload(
...     name="aws",
...     file_name="name_of_file",
...     file_content=content,
...     field_name="name_of_field",
... )
>>> file_uuid
{'uuid': '5f78b7dee33f0a113700a6fc', 'filename': 'name_of_file'}
Parameters
  • name (str) – name of adapter to upload file to

  • node (typing.Optional[str]) – name of node to to upload file to

  • field_name (str) – name of field (should match configuration schema key name)

  • file_name (str) – name of file to upload

  • file_content (typing.Union[str, bytes]) – content of file to upload

  • file_content_type (typing.Optional[str]) – mime type of file to upload

Return type

dict

file_upload_path(path, **kwargs)[source]

Upload the contents of a file to a specific adapter on a specific node.

Examples

Create a client using axonius_api_client.connect.Connect.

Upload a file for use in a connection later

>>> file_uuid = client.adapters.file_upload_path(name="aws", path="test.csv")
>>> file_uuid
{'uuid': '5f78b674e33f0a113700a6fa', 'filename': 'test.csv'}
Parameters
config_refetch(adapter, config_type='generic')[source]

Re-fetch the advanced settings for an adapter.

Parameters
  • adapter (dict) – adapter previously fetched from get_by_name()

  • config_type (str) – One of generic, specific, or discovery

Raises

ApiError – when adapter does not have the supplied config_type

Return type

dict

_init(**kwargs)[source]

Post init method for subclasses to use for extra setup.

property router

Router for this API model.

Return type

axonius_api_client.api.routers.Router

_get()[source]

Private API method to get all adapters.

Return type

dict

_config_update(name_raw, name_config, new_config)[source]

Private API method to set advanced settings for an adapter.

Parameters
  • name_raw (str) – raw name of the adapter i.e. aws_adapter

  • name_config (str) –

    name of advanced settings to set

    • AdapterBase for generic advanced settings

    • AwsSettings for adapter specific advanced settings (name changes per adapter)

    • DiscoverySchema for discovery advanced settings

  • new_config (dict) – the advanced configuration key value pairs to set

Return type

str

_config_get(name_plugin, name_config)[source]

Private API method to set advanced settings for an adapter.

Parameters
  • name_plugin (str) – plugin name of the adapter i.e. aws_adapter_0

  • name_config (str) –

    name of advanced settings to get

    • AdapterBase for generic advanced settings

    • AwsSettings for adapter specific advanced settings (name changes per adapter)

    • DiscoverySchema for discovery advanced settings

Return type

dict

_file_upload(name_raw, node_id, field_name, file_name, file_content, file_content_type=None, file_headers=None)[source]

Private API method to upload a file to a specific adapter on a specifc node.

Parameters
  • name_raw (str) – raw name of the adapter i.e. aws_adapter

  • node_id (str) – ID of node running adapter

  • field_name (str) – name of field (should match configuration schema key name)

  • file_name (str) – name of file to upload

  • file_content (typing.Union[bytes, str]) – content of file to upload

  • file_content_type (typing.Optional[str]) – mime type of file to upload

  • file_headers (typing.Optional[dict]) – headers to use for file

Return type

dict

__init__(auth, **kwargs)

Mixins for API Models.

Parameters
__repr__()

Show info for this model object.

Return type

str

__str__()

Show info for this model object.

Return type

str

_build_err_msg(response, error=None, exc=None)

Build an error message from a response.

Parameters
Return type

str

_check_response_code(response, error_status=True)

Check the status code of a response.

Parameters
  • responserequests.Response object to check

  • error_status (bool) – throw exc if response status code is bad

Raises

ResponseNotOk – if response has a status code that is an error and error_status is True

_check_response_json(response, error_json_bad_status=True, error_json_invalid=True, uses_api_response=False)

Check the text body of a response is JSON.

Parameters
Raises
  • JsonInvalid – if error_json_invalid is True and response has invalid json

  • JsonError – if error_json_bad_status is True and response is a json dict that has a non-empty error key or a status key that == error

Return type

typing.Any

request(path, method='get', raw=False, is_json=True, empty_ok=False, error_status=True, error_json_bad_status=True, error_json_invalid=True, **kwargs)

Send a REST API request.

Parameters
  • path (str) – path to use in request

  • method (str) – method to use in request

  • raw (bool) – return the raw response object

  • is_json (bool) – return the response as deserialized json or just return the text body

  • error_status (bool) – throw error if response has a bad status code

  • error_json_bad_status (bool) – throw error if json response has non-empty error key

  • error_json_invalid (bool) – throw error if response can not be deserialized into json

  • **kwargs – Passed to axonius_api_client.http.Http.__call__()

  • empty_ok (bool) –

Return type

typing.Any

Returns

requests.Response or str or dict or int or list