4.2. Connection Handler

Easy all-in-one connection handler.

class axonius_api_client.connect.Connect(url, key, secret, log_console=False, log_file=False, certpath=None, certverify=False, certwarn=True, proxy=None, **kwargs)[source]

Bases: object

Easy all-in-one connection handler for using the API client.

Examples

>>> #!/usr/bin/env python
>>> # -*- coding: utf-8 -*-
>>> '''Base example for setting up the API client.'''
>>> import axonius_api_client as axonapi
>>>
>>> # get the URL, API key, API secret, & certwarn from the default ".env" file
>>> client_args = axonapi.get_env_connect()
>>>
>>> # OR override OS env vars with the values from a custom .env file
>>> # client_args = axonapi.get_env_connect(ax_env="/path/to/envfile", override=True)
>>>
>>> # create a client using the url, key, and secret from OS env
>>> client = axonapi.Connect(**client_args)
>>>
>>> j = client.jdump  # json dump helper
>>>
>>> client.start()  # connect to axonius
>>> devices = client.devices  # work with device assets
>>> users = client.users  # work with user assets
>>> adapters = client.adapters  # work with adapters and adapter connections
>>> enforcements = client.enforcements  # work with enforcements
>>> instances = client.instances  # work with instances
>>> dashboard = client.dashboard  # work with dashboards and discovery cycles
>>> system_users = client.system_users  # work with system users
>>> system_roles = client.system_roles  # work with system roles
>>> meta = client.meta  # work with instance meta data
>>> settings_global = client.settings_global  # work with global system settings
>>> settings_gui = client.settings_gui  # work with gui system settings
>>> settings_lifecycle = client.settings_lifecycle  # work with lifecycle system settings
Parameters
__init__(url, key, secret, log_console=False, log_file=False, certpath=None, certverify=False, certwarn=True, proxy=None, **kwargs)[source]

Easy all-in-one connection handler.

Parameters
  • url (str) – URL, hostname, or IP address of Axonius instance

  • key (str) – API Key from account page in Axonius instance

  • secret (str) – API Secret from account page in Axonius instance

  • log_console (bool) – enable logging to console

  • log_file (bool) – enable logging to file

  • certpath (typing.Union[str, pathlib.Path, None]) – path to CA bundle file to use when verifying certs offered by url

  • certverify (bool) – raise exception if cert is self-signed or only if cert is invalid

  • certwarn (bool) – show insecure warning once or never show insecure warning

  • proxy (typing.Optional[str]) – proxy to use when making https requests to url

  • **kwargs – documented as properties

url: str

URL of Axonius instance to use

TIMEOUT_CONNECT: int

Seconds to wait for connections to open to url kwargs=timeout_connect

TIMEOUT_RESPONSE: int

Seconds to wait for responses from url kwargs=timeout_response

CERT_CLIENT_KEY: Optional[Union[str, pathlib.Path]]

Private key file for cert_client_cert kwargs=cert_client_key

CERT_CLIENT_CERT: Optional[Union[str, pathlib.Path]]

cert file to offer to url kwargs=cert_client_cert

CERT_CLIENT_BOTH: Optional[Union[str, pathlib.Path]]

cert file with both private key and cert to offer to url kwargs=cert_client_both

SAVE_HISTORY: bool

append responses to axonius_api_client.http.Http.HISTORY kwargs=save_history

LOG_LEVEL: Union[str, int]

log level for this class kwargs=log_level

LOG_REQUEST_ATTRS: Optional[List[str]]

request attrs to log axonius_api_client.constants.logs.REQUEST_ATTR_MAP kwargs=log_request_attrs

LOG_RESPONSE_ATTRS: Optional[List[str]]

response attrs to log axonius_api_client.constants.logs.RESPONSE_ATTR_MAP kwargs=log_response_attrs

LOG_REQUEST_BODY: bool

log request bodies kwargs=log_request_body

LOG_RESPONSE_BODY: bool

log response bodies kwargs=log_response_body

LOG_LOGGER: logging.Logger

logger to use as package root logger kwargs=log_logger

LOG_LEVEL_PACKAGE: Union[str, int]

log level for entire package kwargs=log_level_package

LOG_LEVEL_HTTP: Union[str, int]

log level for axonius_api_client.http.Http kwargs=log_level_http

LOG_LEVEL_AUTH: Union[str, int]

log level for axonius_api_client.auth.models.Mixins kwargs=log_level_auth

LOG_LEVEL_API: Union[str, int]

log level for axonius_api_client.api.mixins.ModelMixins kwargs=log_level_api

LOG_LEVEL_CONSOLE: Union[str, int]

log level for logs sent to console kwargs=log_level_console

LOG_LEVEL_FILE: Union[str, int]

log level for logs sent to file kwargs=log_level_file

LOG_CONSOLE_FMT: str

logging format to use for logs sent to console kwargs=log_console_fmt

LOG_FILE_FMT: str

logging format to use for logs sent to file kwargs=log_file_fmt

LOG_FILE_NAME: Union[str, pathlib.Path]

name of file to write logs to under LOG_FILE_PATH kwargs=log_file_name

LOG_FILE_PATH: Union[str, pathlib.Path]

path to write LOG_FILE_NAME to kwargs=log_file_path

LOG_FILE_MAX_MB: int

rollover file logs at this many MB kwargs=log_file_max_mb

LOG_FILE_MAX_FILES: int

number of rollover file logs to keep kwargs=log_file_max_files

WRAPERROR: bool

wrap errors in human friendly way or show full traceback kwargs=wraperror

LOG: logging.Logger

logger object to use

STARTED: bool

track if start() has been called

HANDLER_CON: logging.StreamHandler

console logging handler

HANDLER_FILE: logging.handlers.RotatingFileHandler

file logging handler

HTTP_ARGS: dict

arguments to use for creating HTTP

AUTH_ARGS: dict

arguments to use for creating AUTH

HTTP

axonius_api_client.http.Http client to use for AUTH

AUTH

axonius_api_client.auth.api_key.ApiKey auth method to use for all API models

API_ARGS: dict

arguments to use for all API models

SIGNUP

Easy access to signup.

start()[source]

Connect to and authenticate with Axonius.

property users

Work with user assets.

Return type

axonius_api_client.api.assets.users.Users

property devices

Work with device assets.

Return type

axonius_api_client.api.assets.devices.Devices

property adapters

Work with adapters and adapter connections.

Return type

axonius_api_client.api.adapters.adapters.Adapters

property instances

Work with instances.

Return type

axonius_api_client.api.system.instances.Instances

property dashboard

Work with dashboards and discovery cycles.

Return type

axonius_api_client.api.system.dashboard.Dashboard

property enforcements

Work with Enforcement Center.

Return type

axonius_api_client.api.enforcements.enforcements.Enforcements

property run_action

Work with Enforcement Center actions.

Return type

axonius_api_client.api.enforcements.actions.RunAction

property central_core

Work with central core config DEPRECATED.

property system

Work with users, roles, global settings, and more DEPRECATED.

property system_users

Work with system users.

Return type

axonius_api_client.api.system.system_users.SystemUsers

property system_roles

Work with system roles.

Return type

axonius_api_client.api.system.system_roles.SystemRoles

property meta

Work with instance metadata.

Return type

axonius_api_client.api.system.meta.Meta

property settings_global

Work with core system settings.

Return type

axonius_api_client.api.system.settings_global.SettingsGlobal

property settings_gui

Work with gui system settings.

Return type

axonius_api_client.api.system.settings_gui.SettingsGui

property settings_lifecycle

Work with lifecycle system settings.

Return type

axonius_api_client.api.system.settings_lifecycle.SettingsLifecycle

__str__()[source]

Show object info.

Return type

str

__repr__()[source]

Show object info.

Return type

str

classmethod _get_exc_reason(exc)[source]

Trim exceptions down to a more user friendly display.

Uses REASON_RES to do regex substituions.

Parameters

exc (Exception) –

Return type

str

static jdump(obj, **kwargs)[source]

JSON dump utility.

REASON_RES: List[str] = [re.compile('.*?object at.*?\\>\\: ([a-zA-Z0-9\\]\\[: ]+)'), re.compile('.*?\\] (.*) ')]

patterns to look for in exceptions that we can pretty up for user display.