4.5.1. Enforcements

API for working with enforcements.

class axonius_api_client.api.enforcements.enforcements.Enforcements(auth, **kwargs)[source]

Bases: ModelMixins

API working with enforcements.

Whats 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. Also 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, see :method:`attach_full_set`.

TBD:

get_tasks run

Parameters

auth (axonius_api_client.auth.models.Model) –

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

Get an enforcement set by name or UUID.

Parameters
  • value (MULTI_SET) – enforcement set model or str with name or uuid

  • refetch (bool) –

  • cache (typing.Optional[typing.List[axonius_api_client.api.json_api.enforcements.SetFull]]) –

Raises
Returns

enforcement set model

Return type

MODEL_SET_FULL

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

Get all enforcement sets.

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

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

Return type

typing.Union[typing.Generator[typing.Union[axonius_api_client.api.json_api.enforcements.SetBasic, axonius_api_client.api.json_api.enforcements.SetFull], None, None], typing.List[typing.Union[axonius_api_client.api.json_api.enforcements.SetBasic, axonius_api_client.api.json_api.enforcements.SetFull]]]

get_sets_generator(full=True)[source]

Get all enforcement sets using a generator.

Parameters

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

Yields

GEN_SET – Generator

Return type

typing.Generator[typing.Union[axonius_api_client.api.json_api.enforcements.SetBasic, axonius_api_client.api.json_api.enforcements.SetFull], None, None]

attach_full_set(value)[source]

Fetch the full model of an enforcement set and attach the basic model to it.

Parameters

value (MODEL_SET_BASIC) – Previously fetched basic model

Returns

Full model with basic model embedded

Return type

MODEL_SET_FULL

Raises

ApiError – if value is incorrect type

check_set_exists(value)[source]

Check if an enforcement set already exists.

Parameters

value (MULTI_SET) – 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 (MULTI_ACTION_TYPE) – action type model or str with name

Returns

action type model

Return type

MODEL_ACTION_TYPE

Raises
get_action_types()[source]

Get all action types.

Returns

action type models

Return type

List[MODEL_ACTION_TYPE]

copy(value, name, copy_triggers=True)[source]

Copy an enforcement set.

Parameters
  • value (MULTI_SET) – enforcement set model or str with name or uuid

  • name (str) – name to assign to copy

  • copy_triggers (bool, optional) – copy triggers to new set

Returns

copied enforcement set

Return type

MODEL_SET_FULL

update_name(value, name)[source]

Update the name of an enforcement set.

Parameters
  • value (MULTI_SET) – enforcement set model or str with name or uuid

  • name (str) – name to update

Returns

updated enforcement set

Return type

MODEL_SET_FULL

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

Update the main action of an enforcement set.

Parameters
  • value (MULTI_SET) – enforcement set model or str with name or uuid

  • name (str) – name to assign to action

  • action_type (str) – action type

  • config (Optional[dict], optional) – action configuration

Returns

updated enforcement set

Return type

MODEL_SET_FULL

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

Add an action to an enforcement set.

Parameters
  • value (MULTI_SET) – enforcement set model or str with name or uuid

  • category (Union[ActionCategory, str]) – action category to add action to

  • name (str) – name of action to add

  • action_type (str) – action type

  • config (Optional[dict], optional) – action configuration

Returns

updated enforcement set

Return type

MODEL_SET_FULL

update_action_remove(value, category, name)[source]

Remove an action from an enforcement set.

Parameters
  • value (MULTI_SET) – enforcement set model or str with name or uuid

  • category (Union[ActionCategory, str]) – action category to remove action from

  • name (str) – name of action to remove

Returns

updated enforcement set

Return type

MODEL_SET_FULL

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

Update the query of an enforcement set.

Parameters
  • value (MULTI_SET) – enforcement set model or str with name or uuid

  • query_name (str) – name of saved query

  • query_type (Union[QueryType, str], optional) – type of saved query

Returns

updated enforcement set

Return type

MODEL_SET_FULL

update_query_remove(value)[source]

Remove the query from an enforcement set.

Parameters

value (MULTI_SET) – enforcement set model or str with name or uuid

Returns

updated enforcement set

Return type

MODEL_SET_FULL

update_schedule_never(value)[source]

Set the schedule of an enforcement set to never run.

Parameters

value (MULTI_SET) – enforcement set model or str with name or uuid

Returns

updated enforcement set

Return type

MODEL_SET_FULL

update_schedule_discovery(value)[source]

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

Parameters

value (MULTI_SET) – enforcement set model or str with name or uuid

Returns

updated enforcement set

Return type

MODEL_SET_FULL

update_schedule_hourly(value, recurrence)[source]

Set the schedule of an enforcement set to run hourly.

Parameters
  • value (MULTI_SET) – 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

MODEL_SET_FULL

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

Set the schedule of an enforcement set to run daily.

Parameters
  • value (MULTI_SET) – enforcement set model or str with name or uuid

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

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

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

Returns

updated enforcement set

Return type

MODEL_SET_FULL

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

Set the schedule of an enforcement set to run weekly.

Parameters
  • value (MULTI_SET) – enforcement set model or str with name or uuid

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

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

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

Returns

updated enforcement set

Return type

MODEL_SET_FULL

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

Set the schedule of an enforcement set to run monthly.

Parameters
  • value (MULTI_SET) – enforcement set model or str with name or uuid

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

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

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

Returns

updated enforcement set

Return type

MODEL_SET_FULL

update_only_new_assets(value, update)[source]

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

Parameters
  • value (MULTI_SET) – 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

MODEL_SET_FULL

update_on_count_increased(value, update)[source]

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

Parameters
  • value (MULTI_SET) – 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

MODEL_SET_FULL

update_on_count_decreased(value, update)[source]

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

Parameters
  • value (MULTI_SET) – 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

MODEL_SET_FULL

update_on_count_above(value, update)[source]

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

Parameters
  • value (MULTI_SET) – enforcement set model or str with name or uuid

  • update (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

MODEL_SET_FULL

update_on_count_below(value, update)[source]

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

Parameters
  • value (MULTI_SET) – enforcement set model or str with name or uuid

  • update (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

MODEL_SET_FULL

update_from_model(value)[source]

Update an enforcement set from the values in a model.

Parameters

value (MODEL_SET_FULL) – enforcement set model to update

Returns

updated enforcement set

Return type

MODEL_SET_FULL

create(name, main_action_name, main_action_type, main_action_config=None, query_name=None, query_type='devices', 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)[source]

Create an enforcement set.

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

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

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

  • main_action_config (Optional[dict], optional) – action config for main action

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

  • query_type (str, optional) – Saved Query type

  • schedule_type (Union[Schedule, str], optional) – Schedule type for automation

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

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

  • schedule_recurrence (Optional[Union[int, List[str]]], optional) – recurrence value, type changes based on schedule_type

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

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

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

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

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

Returns

created enforcement set

Return type

MODEL_SET_FULL

delete(value)[source]

Delete an enforcement set.

Parameters

value (MULTI_SET) – enforcement set model or str with name or uuid

Returns

deleted enforcement set

Return type

MODEL_SET_FULL

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 (MULTI_ACTION_TYPE) – action type to use

  • config (Optional[dict], optional) – 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 (Optional[MODEL_SQ_MULTI], optional) – Name of Saved Query

  • query_type (Union[QueryType, str], optional) – Type of Saved Query

Returns

None if query_name is not supplied, otherwise saved query model

Return type

Optional[MODEL_SQ]

_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

MODEL_SET_FULL

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

Update an enforcement set.

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

  • name (str) – name of set

  • actions (dict) – actions of set

  • triggers (Optional[List[dict]], optional) – triggers of set

Returns

updated set

Return type

MODEL_SET_FULL

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

Create an enforcement set.

Parameters
  • name (str) – name of enforcement to create

  • main (dict) – main action

  • success (Optional[List[dict]], optional) – success actions

  • failure (Optional[List[dict]], optional) – failure actions

  • post (Optional[List[dict]], optional) – post actions

  • triggers (Optional[List[dict]], optional) – saved query trigger

Returns

created set

Return type

MODEL_SET_FULL

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

Get enforcement sets in basic model.

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

  • offset (int, optional) – start at row N

  • sort (Optional[str], optional) – sort based on a model attribute

  • filter (Optional[str], optional) – AQL filter

  • search (str, optional) – search string

Returns

basic models

Return type

List[MODEL_SET_BASIC]

_get_set(uuid)[source]

Get an enforcement set in full model.

Parameters

uuid (str) – UUID of set to get

Returns

full model

Return type

MODEL_SET_FULL

_get_action_types()[source]

Get all action types.

Returns

action type models

Return type

List[MODEL_ACTION_TYPE]

_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, optional) – this was triggered from the EC Page in the GUI

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

Return type

axonius_api_client.api.json_api.generic.Name

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

Run enforcement sets against their triggers.

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

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

  • use_conditions (bool, optional) – 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 (List[str]) – names or UUIDs of enforcement sets to trigger

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

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

Return type

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

__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

LOG: logging.Logger

Logger for this object.

auth

axonius_api_client.auth.models.Mixins authentication object.

http

axonius_api_client.http.Http client to use to send requests,