4.5.1. Enforcements

API for working with enforcements.

class axonius_api_client.api.enforcements.enforcements.Enforcements(auth, log_level='debug', **kwargs)[source]

Bases: ModelMixins

API working with enforcements.

What’s the deal with BASIC vs FULL?

The REST API exposes an endpoint to page through the enforcement sets, but the details about the actions and triggers configured are limited.

In order to get the full details of the actions and triggers, one call must be made to fetch the FULL details of each enforcement set by UUID.

To make things more fun, the FULL model is lacking details that are only provided by the BASIC model: triggers_last_triggered, triggers_times_triggered, updated_by, last_triggered, last_updated.

Finally, the “human friendly” description of trigger schedule is only available from BASIC.

We overcome this by getting the FULL object and attaching the BASIC object as FULL.BASIC.

Parameters
  • auth (axonius_api_client.auth.model.AuthModel) –

  • log_level (typing.Union[int, str]) –

property folders: FoldersEnforcements

Get the folders api for this object type.

get_set(value, refetch=True, cache=None)[source]

Get an enforcement set by name or UUID.

Parameters
  • value (typing.Union[str, dict, axonius_api_client.api.json_api.enforcements.EnforcementBasicModel, axonius_api_client.api.json_api.enforcements.EnforcementFullModel, axonius_api_client.api.json_api.enforcements.UpdateEnforcementResponseModel]) – enforcement set model or str with name or uuid

  • refetch (bool) – refetch the enforcement set from the API

  • cache (typing.Optional[typing.List[axonius_api_client.api.json_api.enforcements.EnforcementFullModel]]) – cache of enforcement sets

Raises
Returns

enforcement set model

Return type

EnforcementFullModel

get_sets_cached(**kwargs)[source]

Get all enforcements cached.

Return type

typing.List[typing.Union[axonius_api_client.api.json_api.enforcements.EnforcementBasicModel, axonius_api_client.api.json_api.enforcements.EnforcementFullModel]]

get_sets(generator=False, full=True)[source]

Get all enforcement sets.

Parameters
  • generator (bool) – return an iterator for objects

  • full (bool) – get the full model of each enforcement set

Return type

typing.Union[typing.Generator[typing.Union[axonius_api_client.api.json_api.enforcements.EnforcementBasicModel, axonius_api_client.api.json_api.enforcements.EnforcementFullModel], None, None], typing.List[typing.Union[axonius_api_client.api.json_api.enforcements.EnforcementBasicModel, axonius_api_client.api.json_api.enforcements.EnforcementFullModel]]]

get_sets_generator(full=True)[source]

Get all enforcement sets using a generator.

Parameters

full (bool) – get the full model of each enforcement set

Yields

t.Generator[t.Union[EnforcementBasicModel, EnforcementFullModel], None, None] – Generator

Return type

typing.Generator[typing.Union[axonius_api_client.api.json_api.enforcements.EnforcementBasicModel, axonius_api_client.api.json_api.enforcements.EnforcementFullModel], None, None]

check_set_exists(value)[source]

Check if an enforcement set already exists.

Parameters

value (typing.Union[str, dict, axonius_api_client.api.json_api.enforcements.EnforcementBasicModel, axonius_api_client.api.json_api.enforcements.EnforcementFullModel, axonius_api_client.api.json_api.enforcements.UpdateEnforcementResponseModel]) – enforcement set model or str with name or uuid

Raises

ApiError – if enforcement set already exists

get_action_type(value)[source]

Get an action type.

Parameters

value (typing.Union[str, dict, axonius_api_client.api.json_api.enforcements.ActionType]) – action type model or str with name

Returns

action type model

Return type

ActionType

Raises
get_action_types()[source]

Get all action types.

Returns

action type models

Return type

t.List[ActionType]

copy(value, name, copy_triggers=True, folder=None, create=True, echo=True)[source]

Copy an enforcement set.

Parameters
  • value (typing.Union[str, dict, axonius_api_client.api.json_api.enforcements.EnforcementBasicModel, axonius_api_client.api.json_api.enforcements.EnforcementFullModel, axonius_api_client.api.json_api.enforcements.UpdateEnforcementResponseModel]) – enforcement set model or str with name or uuid

  • name (str) – name to assign to copy

  • copy_triggers (bool) – copy triggers to new set

  • folder (typing.Union[str, axonius_api_client.api.json_api.folders.enforcements.Folder, None]) – folder to put object in

  • create (bool) – if folder supplied does not exist, create it

  • echo (bool) – echo output to console during create/etc

Returns

updated enforcement set

Return type

EnforcementFullModel

update_folder(value, folder, create=True, echo=True)[source]

Update the name of an enforcement set.

Parameters
  • value (typing.Union[str, dict, axonius_api_client.api.json_api.enforcements.EnforcementBasicModel, axonius_api_client.api.json_api.enforcements.EnforcementFullModel, axonius_api_client.api.json_api.enforcements.UpdateEnforcementResponseModel]) – enforcement set model or str with name or uuid

  • folder (typing.Union[str, axonius_api_client.api.json_api.folders.enforcements.FolderModel]) – folder to put object in

  • create (bool) – if folder supplied does not exist, create it

  • echo (bool) – echo output to console during create/etc

Returns

updated enforcement set

Return type

EnforcementFullModel

update_name(value, name)[source]

Update the name of an enforcement set.

Parameters
  • value (typing.Union[str, dict, axonius_api_client.api.json_api.enforcements.EnforcementBasicModel, axonius_api_client.api.json_api.enforcements.EnforcementFullModel, axonius_api_client.api.json_api.enforcements.UpdateEnforcementResponseModel]) – enforcement set model or str with name or uuid

  • name (str) – name to update

Returns

updated enforcement set

Return type

EnforcementFullModel

update_description(value, description, append=False)[source]

Update the description of an enforcement set.

Parameters
  • value (typing.Union[str, dict, axonius_api_client.api.json_api.enforcements.EnforcementBasicModel, axonius_api_client.api.json_api.enforcements.EnforcementFullModel, axonius_api_client.api.json_api.enforcements.UpdateEnforcementResponseModel]) – enforcement set model or str with name or uuid

  • description (str) – description to update

  • append (bool) – append to existing description

Returns

updated enforcement set

Return type

EnforcementFullModel

update_action_main(value, name, action_type, config=None)[source]

Update the main action of an enforcement set.

Parameters
  • value (typing.Union[str, dict, axonius_api_client.api.json_api.enforcements.EnforcementBasicModel, axonius_api_client.api.json_api.enforcements.EnforcementFullModel, axonius_api_client.api.json_api.enforcements.UpdateEnforcementResponseModel]) – enforcement set model or str with name or uuid

  • name (str) – name to assign to action

  • action_type (str) – action type

  • config (typing.Optional[dict]) – action configuration

Returns

updated enforcement set

Return type

EnforcementFullModel

update_action_add(value, category, name, action_type, config=None)[source]

Add an action to an enforcement set.

Parameters
  • value (typing.Union[str, dict, axonius_api_client.api.json_api.enforcements.EnforcementBasicModel, axonius_api_client.api.json_api.enforcements.EnforcementFullModel, axonius_api_client.api.json_api.enforcements.UpdateEnforcementResponseModel]) – enforcement set model or str with name or uuid

  • category (typing.Union[axonius_api_client.api.json_api.enforcements.ActionCategory, str]) – action category to add action to

  • name (str) – name of action to add

  • action_type (str) – action type

  • config (typing.Optional[dict]) – action configuration

Returns

updated enforcement set

Return type

EnforcementFullModel

update_action_remove(value, category, name)[source]

Remove an action from an enforcement set.

Parameters
  • value (typing.Union[str, dict, axonius_api_client.api.json_api.enforcements.EnforcementBasicModel, axonius_api_client.api.json_api.enforcements.EnforcementFullModel, axonius_api_client.api.json_api.enforcements.UpdateEnforcementResponseModel]) – enforcement set model or str with name or uuid

  • category (typing.Union[axonius_api_client.api.json_api.enforcements.ActionCategory, str]) – action category to remove action from

  • name (str) – name of action to remove

Returns

updated enforcement set

Return type

EnforcementFullModel

update_query(value, query_name, query_type='devices')[source]

Update the query of an enforcement set.

Parameters
  • value (typing.Union[str, dict, axonius_api_client.api.json_api.enforcements.EnforcementBasicModel, axonius_api_client.api.json_api.enforcements.EnforcementFullModel, axonius_api_client.api.json_api.enforcements.UpdateEnforcementResponseModel]) – enforcement set model or str with name or uuid

  • query_name (str) – name of saved query

  • query_type (typing.Union[axonius_api_client.api.json_api.saved_queries.QueryTypes, str]) – type of saved query

Returns

updated enforcement set

Return type

EnforcementFullModel

update_query_remove(value)[source]

Remove the query from an enforcement set.

Parameters

value (typing.Union[str, dict, axonius_api_client.api.json_api.enforcements.EnforcementBasicModel, axonius_api_client.api.json_api.enforcements.EnforcementFullModel, axonius_api_client.api.json_api.enforcements.UpdateEnforcementResponseModel]) – enforcement set model or str with name or uuid

Returns

updated enforcement set

Return type

EnforcementFullModel

update_schedule_never(value)[source]

Set the schedule of an enforcement set to never run.

Parameters

value (typing.Union[str, dict, axonius_api_client.api.json_api.enforcements.EnforcementBasicModel, axonius_api_client.api.json_api.enforcements.EnforcementFullModel, axonius_api_client.api.json_api.enforcements.UpdateEnforcementResponseModel]) – enforcement set model or str with name or uuid

Returns

updated enforcement set

Return type

EnforcementFullModel

update_schedule_discovery(value)[source]

Set the schedule of an enforcement set to run every discovery.

Parameters

value (typing.Union[str, dict, axonius_api_client.api.json_api.enforcements.EnforcementBasicModel, axonius_api_client.api.json_api.enforcements.EnforcementFullModel, axonius_api_client.api.json_api.enforcements.UpdateEnforcementResponseModel]) – enforcement set model or str with name or uuid

Returns

updated enforcement set

Return type

EnforcementFullModel

update_schedule_hourly(value, recurrence)[source]

Set the schedule of an enforcement set to run hourly.

Parameters
  • value (typing.Union[str, dict, axonius_api_client.api.json_api.enforcements.EnforcementBasicModel, axonius_api_client.api.json_api.enforcements.EnforcementFullModel, axonius_api_client.api.json_api.enforcements.UpdateEnforcementResponseModel]) – enforcement set model or str with name or uuid

  • recurrence (int) – run schedule every N hours (N = 1-24)

Returns

updated enforcement set

Return type

EnforcementFullModel

update_schedule_daily(value, recurrence, hour=13, minute=0)[source]

Set the schedule of an enforcement set to run daily.

Parameters
  • value (typing.Union[str, dict, axonius_api_client.api.json_api.enforcements.EnforcementBasicModel, axonius_api_client.api.json_api.enforcements.EnforcementFullModel, axonius_api_client.api.json_api.enforcements.UpdateEnforcementResponseModel]) – enforcement set model or str with name or uuid

  • recurrence (int) – run enforcement every N days (N = 1-~)

  • hour (int) – hour of day to run schedule

  • minute (int) – minute of hour to run schedule

Returns

updated enforcement set

Return type

EnforcementFullModel

update_schedule_weekly(value, recurrence, hour=13, minute=0)[source]

Set the schedule of an enforcement set to run weekly.

Parameters
  • value (typing.Union[str, dict, axonius_api_client.api.json_api.enforcements.EnforcementBasicModel, axonius_api_client.api.json_api.enforcements.EnforcementFullModel, axonius_api_client.api.json_api.enforcements.UpdateEnforcementResponseModel]) – enforcement set model or str with name or uuid

  • recurrence (typing.Union[str, typing.List[typing.Union[str, int]]]) – run enforcement on days of week

  • hour (int) – hour of day to run schedule

  • minute (int) – minute of hour to run schedule

Returns

updated enforcement set

Return type

EnforcementFullModel

update_schedule_monthly(value, recurrence, hour=13, minute=0)[source]

Set the schedule of an enforcement set to run monthly.

Parameters
  • value (typing.Union[str, dict, axonius_api_client.api.json_api.enforcements.EnforcementBasicModel, axonius_api_client.api.json_api.enforcements.EnforcementFullModel, axonius_api_client.api.json_api.enforcements.UpdateEnforcementResponseModel]) – enforcement set model or str with name or uuid

  • recurrence (typing.Union[str, typing.List[typing.Union[str, int]]]) – run enforcement on days of month

  • hour (int) – hour of day to run schedule

  • minute (int) – minute of hour to run schedule

Returns

updated enforcement set

Return type

EnforcementFullModel

update_only_new_assets(value, update)[source]

Update enforcement set to only run against newly added assets from last automated run.

Parameters
  • value (typing.Union[str, dict, axonius_api_client.api.json_api.enforcements.EnforcementBasicModel, axonius_api_client.api.json_api.enforcements.EnforcementFullModel, axonius_api_client.api.json_api.enforcements.UpdateEnforcementResponseModel]) – enforcement set model or str with name or uuid

  • update (bool) – False=run against all assets each automated run, True=only run against newly added assets from last automated run

Returns

updated enforcement set

Return type

EnforcementFullModel

update_on_count_increased(value, update)[source]

Update enforcement set to only run if asset count increased from last automated run.

Parameters
  • value (typing.Union[str, dict, axonius_api_client.api.json_api.enforcements.EnforcementBasicModel, axonius_api_client.api.json_api.enforcements.EnforcementFullModel, axonius_api_client.api.json_api.enforcements.UpdateEnforcementResponseModel]) – enforcement set model or str with name or uuid

  • update (bool) – False=run regardless if asset count increased, True=only perform automated run if asset count increased

Returns

updated enforcement set

Return type

EnforcementFullModel

update_on_count_decreased(value, update)[source]

Update enforcement set to only run if asset count decreased from last automated run.

Parameters
  • value (typing.Union[str, dict, axonius_api_client.api.json_api.enforcements.EnforcementBasicModel, axonius_api_client.api.json_api.enforcements.EnforcementFullModel, axonius_api_client.api.json_api.enforcements.UpdateEnforcementResponseModel]) – enforcement set model or str with name or uuid

  • update (bool) – False=run regardless if asset count decreased, True=only perform automated run if asset count decreased

Returns

updated enforcement set

Return type

EnforcementFullModel

update_on_count_above(value, update)[source]

Update enforcement set to only run automatically if asset count is above N.

Parameters
  • value (typing.Union[str, dict, axonius_api_client.api.json_api.enforcements.EnforcementBasicModel, axonius_api_client.api.json_api.enforcements.EnforcementFullModel, axonius_api_client.api.json_api.enforcements.UpdateEnforcementResponseModel]) – enforcement set model or str with name or uuid

  • update (typing.Optional[int]) – None to always run automatically regardless of asset count, integer to only run automatically if asset count is above N

Returns

updated enforcement set

Return type

EnforcementFullModel

update_on_count_below(value, update)[source]

Update enforcement set to only run automatically if asset count is below N.

Parameters
  • value (typing.Union[str, dict, axonius_api_client.api.json_api.enforcements.EnforcementBasicModel, axonius_api_client.api.json_api.enforcements.EnforcementFullModel, axonius_api_client.api.json_api.enforcements.UpdateEnforcementResponseModel]) – enforcement set model or str with name or uuid

  • update (typing.Optional[int]) – None to always run automatically regardless of asset count, integer to only run automatically if asset count is below N

Returns

updated enforcement set

Return type

EnforcementFullModel

update_from_model(value)[source]

Update an enforcement set from the values in a model.

Parameters

value (axonius_api_client.api.json_api.enforcements.EnforcementFullModel) – enforcement set model to update

Returns

updated enforcement set

Return type

EnforcementFullModel

create(name, main_action_name, main_action_type, query_name=None, query_type='devices', main_action_config=None, description='', schedule_type='never', schedule_hour=13, schedule_minute=0, schedule_recurrence=None, only_new_assets=False, on_count_above=None, on_count_below=None, on_count_increased=False, on_count_decreased=False, folder=None, create=True, echo=True)[source]

Create an enforcement set.

Parameters
  • name (str) – Name to assign to enforcement set

  • description (typing.Optional[str]) – Description to assign to enforcement set

  • query_name (typing.Optional[str]) – Saved Query name to use for trigger

  • query_type (str) – Saved Query type

  • main_action_name (str) – name to assign to main action

  • main_action_type (str) – action type to use for main action

  • main_action_config (typing.Optional[dict]) – action config for main action

  • schedule_type (typing.Union[axonius_api_client.api.json_api.enforcements.EnforcementSchedule, str]) – EnforcementSchedule type for automation

  • schedule_hour (int) – Hour of day to use for schedule_type

  • schedule_minute (int) – Minute of hour to use for schedule_type

  • schedule_recurrence (typing.Union[int, typing.List[str], None]) – recurrence value to use for schedule_type

  • only_new_assets (bool) – only run set against assets added since last run

  • on_count_above (typing.Optional[int]) – only run if asset count above N

  • on_count_below (typing.Optional[int]) – only run if asset count below N

  • on_count_increased (bool) – only run if asset count increased since last run

  • on_count_decreased (bool) – only run if asset count decreased since last run

  • folder (typing.Union[str, axonius_api_client.api.json_api.folders.enforcements.FolderModel, None]) – folder to create set in

  • create (bool) – create folder if it doesn’t exist

  • echo (bool) – echo folder creation

Returns

created enforcement set

Return type

EnforcementFullModel

delete(value)[source]

Delete an enforcement set.

Parameters

value (typing.Union[str, dict, axonius_api_client.api.json_api.enforcements.EnforcementBasicModel, axonius_api_client.api.json_api.enforcements.EnforcementFullModel, axonius_api_client.api.json_api.enforcements.UpdateEnforcementResponseModel]) – enforcement set model or str with name or uuid

Returns

deleted enforcement set

Return type

EnforcementFullModel

get_set_action(name, action_type, config=None)[source]

Get the action dictionary needed to add an action to an enforcement set.

Parameters
  • name (str) – name to assign to action

  • action_type (typing.Union[str, dict, axonius_api_client.api.json_api.enforcements.ActionType]) – action type to use

  • config (typing.Optional[dict]) – action config

Returns

action dictionary

Return type

dict

get_trigger_view(query_name=None, query_type='devices')[source]

Get the saved query for use in adding a query to an enforcement.

Parameters
  • query_name (typing.Union[str, dict, axonius_api_client.api.json_api.saved_queries.SavedQuery, None]) – Name of Saved Query

  • query_type (typing.Union[axonius_api_client.api.json_api.saved_queries.QueryTypes, str]) – Type of Saved Query

Returns

None if query_name is not supplied, otherwise saved query model

Return type

SavedQuery

_init(**kwargs)[source]

Post init method for subclasses to use for extra setup.

_delete(uuid)[source]

Delete an enforcement set by UUID.

Parameters

uuid (str) – UUID of set to delete

Returns

deleted model

Return type

json_api.generic.Deleted

_copy(uuid, name, clone_triggers)[source]

Copy an enforcement set.

Parameters
  • uuid (str) – UUID of set to copy

  • name (str) – name to give copy

  • clone_triggers (bool) – copy triggers into new set

Returns

copied set

Return type

EnforcementFullModel

_update_description(uuid, description)[source]

Update the description of an enforcement set.

Parameters
  • uuid (str) – UUID of set to update

  • description (str) – description to set

Return type

None

_update(uuid, name, actions, folder_id='', triggers=None)[source]

Update an enforcement set.

Parameters
Returns

updated set

Return type

EnforcementFullModel

_create_from_model(request_obj)[source]

Pass.

Parameters

request_obj (axonius_api_client.api.json_api.enforcements.CreateEnforcementModel) –

Return type

axonius_api_client.api.json_api.enforcements.EnforcementFullModel

_create(name, main, folder_id='', description='', success=None, failure=None, post=None, triggers=None)[source]

Create an enforcement set.

Parameters
Returns

created set

Return type

EnforcementFullModel

_get_sets(limit=2000, offset=0, sort=None, filter=None, search='')[source]

Get enforcement sets in basic model.

Parameters
Returns

basic models

Return type

t.List[EnforcementBasicModel]

_get_set(uuid)[source]

Get an enforcement set in full model.

Parameters

uuid (str) – UUID of set to get

Returns

full model

Return type

EnforcementFullModel

_get_action_types()[source]

Get all action types.

Returns

action type models

Return type

t.List[ActionType]

_run_set_against_trigger(uuid, ec_page_run=False, use_conditions=False)[source]

Run an enforcement set against its trigger.

Parameters
  • uuid (str) – UUID of enforcement set to trigger

  • ec_page_run (bool) – this was triggered from the EC Page in the GUI

  • use_conditions (bool) – use conditions configured on enforcement set to determine execution

Return type

axonius_api_client.api.json_api.generic.Name

_move_sets(folder_id, enforcements_ids)[source]

Move enforcements to a folder.

Parameters
Return type

axonius_api_client.api.json_api.enforcements.MoveEnforcementsResponseModel

_run_sets_against_trigger(uuids, include=True, use_conditions=False)[source]

Run enforcement sets against their triggers.

Parameters
  • uuids (typing.List[str]) – UUIDs of enforcement sets to trigger

  • include (bool) – select UUIDs in DB or UUIDs NOT in DB

  • use_conditions (bool) – use conditions configured on enforcement set to determine execution

Return type

axonius_api_client.api.json_api.generic.ListDictValue

run(values, use_conditions=False, error=True)[source]

Run enforcement sets against their triggers.

Parameters
  • values (typing.List[str]) – names or UUIDs of enforcement sets to trigger

  • use_conditions (bool) – use conditions configured on enforcement set to determine execution

  • error (bool) – throw error if an enforcement set has no trigger

Return type

typing.List[axonius_api_client.api.json_api.enforcements.EnforcementFullModel]

LOG: logging.Logger = None

Logger for this object.

__init__(auth, log_level='debug', **kwargs)

Mixins for API Models.

Parameters
  • auth (axonius_api_client.auth.model.AuthModel) – object to use for auth and sending API requests

  • log_level (typing.Union[int, str]) – logging level to use for this objects logger

  • **kwargs – passed to _init()

__repr__()

Show info for this model object.

Return type

str

__str__()

Show info for this model object.

Return type

str

_init_auth(**kwargs)

Post init method for subclasses to use for overriding auth setup.

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.