4.4.6.1. Base¶
Base callbacks.
- class axonius_api_client.api.asset_callbacks.base.Base(apiobj, store, state=None, getargs=None)[source]¶
Bases:
object
Callbacks for formatting asset data.
Examples
args_map()
for callback generic arguments to format assets.args_map_custom()
for callback specific arguments to format and export data.
- Parameters:
store (
dict
) –state (
typing.Optional
[dict
]) –getargs (
typing.Optional
[dict
]) –
- classmethod args_map()[source]¶
Get all the argument names and their defaults for this callbacks object. :rtype:
dict
Examples
Create a
client
usingaxonius_api_client.connect.Connect
and assumeapiobj
is eitherclient.devices
orclient.users
>>> import axonius_api_client as axonapi >>> connect_args: dict = axonapi.get_env_connect() >>> client: axonapi.Connect = axonapi.Connect(**connect_args) >>> apiobj: axonapi.api.assets.AssetMixin = client.devices >>> # or client.users or client.vulnerabilities
Flatten complex fields - Will take all sub-fields of complex fields and put them on the root level with their values index correlated to each other.
>>> assets = apiobj.get(fields=["network_interfaces"], field_flatten=True)
Explode a single field - will take that field and create new rows for list item.
>>> assets = apiobj.get(field_explode="hostname")
Exclude fields - Will remove fields from the final output.
>>> assets = apiobj.get(field_excludes=["internal_axon_id", "adapter_list_length"])
Use field titles - Will change internal field names to their titles.
>>> assets = apiobj.get(field_titles=True)
Join fields - Will join multi value fields with carriage returns.
>>> assets = apiobj.get(field_join=True)
Join fields with no trim and custom join value - Will join multi value fields with
;;
and do not trim the joined value to excels maximum cell length.>>> assets = apiobj.get(field_join=True, field_join_value=";;", field_join_trim=0)
Add fields as empty values for fields that did not return.
>>> assets = apiobj.get(field_null=True)
Add fields as empty values for fields that did not return with a custom null value.
>>> assets = apiobj.get( ... field_null=True, ... field_null_value="EMPTY", ... field_null_value_complex="EMPTY LIST", ... )
Add and remove tags to all assets returned.
>>> assets = apiobj.get(tags_add=["tag1", "tag2"], tags_remove=["tag3", "tag4"])
Generate a report of adapters that are missing from each asset.
>>> assets = apiobj.get(report_adapters_missing=True)
Generate a report of installed software that does not match a list of regex for each asset.
>>> assets = apiobj.get(report_software_whitelist=["chrome", "^adobe.*acrobat"])
Echo to STDERR progress messages.
>>> assets = apiobj.get(do_echo=True)
Change the amount of assets that echo page progress when do_echo is true.
>>> assets = apiobj.get(do_echo=True, page_progress=100)
Supply a set of custom callbacks to process each row before all builtin callbacks are run. Custom callbacks receive two arguments:
self
(the current callback object) androws
(the current rows being processed). Custom callbacks must return a list of rows.>>> def custom_cb1(self, rows): ... for row in rows: ... row["internal_axon_id"] = row["internal_axon_id"].upper() ... return rows ... >>> assets = apiobj.get(custom_cbs=[custom_cb1])
See also
args_map_custom()
for callback specific arguments to format and export data.
Notes
These arguments can be supplied as extra kwargs passed to
axonius_api_client.api.assets.users.Users.get()
oraxonius_api_client.api.assets.devices.Devices.get()
- classmethod args_map_custom()[source]¶
Get the custom argument names and their defaults for this callbacks object. :rtype:
dict
See also
args_map()
for the arguments for all callback objects.Notes
This callback object has no custom arguments.
- classmethod args_map_base()[source]¶
Get the map of arguments that can be supplied to GETARGS.
- Return type:
- get_arg_value(arg)[source]¶
Get an argument value.
- Parameters:
arg (
str
) – key to get fromGETARGS
with a default value fromargs_map()
- Return type:
- set_arg_value(arg, value)[source]¶
Set an argument value.
- Parameters:
value (
typing.Any
) – value to set for key
- __init__(apiobj, store, state=None, getargs=None)[source]¶
Callbacks base class for assets.
- Parameters:
apiobj (
axonius_api_client.api.assets.asset_mixin.AssetMixin
) – Asset object that created this callbackstore (
dict
) – store tracker of get method that created this callbackstate (
typing.Optional
[dict
]) – state tracker of get method that created this callbackgetargs (
typing.Optional
[dict
]) – kwargs passed to assets get method that created this callback
-
LOG:
logging.Logger
¶ logger for this object.
- do_pre_row(rows)[source]¶
Pre-processing callbacks for current row.
- Parameters:
rows (
typing.Union
[typing.List
[dict
],dict
]) – rows to process- Return type:
- process_row(row)[source]¶
Process the callbacks for current row.
- Parameters:
row (
typing.Union
[typing.List
[dict
],dict
]) – row to process- Return type:
- do_row(rows)[source]¶
Execute the callbacks for current row.
- Parameters:
rows (
typing.Union
[typing.List
[dict
],dict
]) – rows to process- Return type:
- do_custom_cbs(rows)[source]¶
Execute any custom callbacks for current row.
- Parameters:
rows (
typing.Union
[typing.List
[dict
],dict
]) – rows to process- Return type:
- do_add_null_values(rows)[source]¶
Null out missing fields.
- Parameters:
rows (
typing.Union
[typing.List
[dict
],dict
]) – rows to process- Return type:
- do_excludes(rows)[source]¶
Asset callback to remove fields from row.
- Parameters:
rows (
typing.Union
[typing.List
[dict
],dict
]) – rows to process- Return type:
- _do_excludes(row)[source]¶
Asset callback to remove fields from row.
- Parameters:
row (
dict
) – row being processed
- do_join_values(rows)[source]¶
Join values.
- Parameters:
rows (
typing.Union
[typing.List
[dict
],dict
]) – rows to process- Return type:
- do_change_field_replace(rows)[source]¶
Asset callback to replace characters.
- Parameters:
rows (
typing.Union
[typing.List
[dict
],dict
]) – rows to process- Return type:
- property field_replacements: List[Tuple[str, str]]¶
Parse the supplied list of field name replacements.
- do_change_field_compress(rows)[source]¶
Asset callback to shorten field names.
- Parameters:
rows (
typing.Union
[typing.List
[dict
],dict
]) – rows to process- Return type:
- do_change_field_titles(rows)[source]¶
Asset callback to change qual name to title.
- Parameters:
rows (
typing.Union
[typing.List
[dict
],dict
]) – rows to process- Return type:
- _do_change_field_titles(row)[source]¶
Asset callback to change qual name to title.
- Parameters:
row (
dict
) – row being processed
- do_flatten_fields(rows)[source]¶
Asset callback to flatten complex fields.
- Parameters:
rows (
typing.Union
[typing.List
[dict
],dict
]) – rows to process- Return type:
- do_explode_entities(rows)[source]¶
Explode a row into a row for each asset entity.
- Parameters:
rows (
typing.Union
[typing.List
[dict
],dict
]) – rows being processed- Return type:
- _do_explode_entities(row)[source]¶
Explode a row into multiple rows for each asset entity.
- Parameters:
row (
dict
) – row being processed- Return type:
- do_explode_field(rows)[source]¶
Explode a field into multiple rows.
- Parameters:
rows (
typing.Union
[typing.List
[dict
],dict
]) – rows being processed- Return type:
- _do_explode_field(row)[source]¶
Explode a field into multiple rows.
- Parameters:
row (
dict
) – row being processed- Return type:
- process_tags_to_add(rows)[source]¶
Add assets to tracker for adding tags.
- Parameters:
rows (
typing.Union
[typing.List
[dict
],dict
]) – rows to process- Return type:
- process_tags_to_remove(rows)[source]¶
Add assets to tracker for removing tags.
- Parameters:
rows (
typing.Union
[typing.List
[dict
],dict
]) – rows to process- Return type:
- add_report_software_whitelist(rows)[source]¶
Process report: Software whitelist.
- Parameters:
rows (
typing.Union
[typing.List
[dict
],dict
]) – rows to process- Return type:
- _add_report_software_whitelist(row)[source]¶
Process report: Software whitelist.
- Parameters:
row (
dict
) – row being processed
- add_include_dates(rows)[source]¶
Process report: Add dates (history and current)
- Parameters:
rows (
typing.Union
[typing.List
[dict
],dict
]) – rows to process- Return type:
- add_report_adapters_missing(rows)[source]¶
Process report: Missing adapters.
- Parameters:
rows (
typing.Union
[typing.List
[dict
],dict
]) – rows to process- Return type:
- _add_report_adapters_missing(row)[source]¶
Process report: Missing adapters.
- Parameters:
row (
dict
) – row being processed
- echo(msg, debug=False, error=False, warning=False, level='info', level_debug='debug', level_error='error', level_warning='warning', abort=True)[source]¶
Echo a message to console or log it.
- Parameters:
msg (
typing.Union
[str
,typing.List
[str
]]) – message to echoerror (
typing.Union
[bool
,str
,typing.Type
[Exception
]]) – message is an errorwarning (
bool
) – message is a warninglevel (
str
) – logging level for non error/non warning messageslevel_debug (
str
) – logging level for debug messageslevel_error (
str
) – logging level for error messageslevel_warning (
str
) – logging level for warning messagesabort (
bool
) – sys.exit(1) if error is truedebug (
bool
) – message is a debug message
- get_sub_schemas(schema)[source]¶
Get all the schemas of sub-fields for a complex field.
- Parameters:
schema (
dict
) – schema of complex field- Return type:
- property args_strs: List[str]¶
Get a list of strings that describe each arg in
args_map()
.
-
FIND_KEYS:
typing.List
[str
] = ['name', 'name_qual', 'column_title']¶ field schema keys to use when finding a fields schema
- APIOBJ = None¶
assets object.
-
CURRENT_ROWS:
typing.Optional
[typing.List
[dict
]] = None¶ current rows being processed
-
TAG_ROWS_ADD:
typing.List
[dict
] = None¶ tracker of assets to add tags to in
do_tagging()
.
-
TAG_ROWS_REMOVE:
typing.List
[dict
] = None¶ tracker of assets to remove tags from in
do_tagging()
.
-
CUSTOM_CB_EXC:
typing.List
[dict
] = None¶ tracker of custom callbacks that have been executed by
do_custom_cbs()
- class axonius_api_client.api.asset_callbacks.base.ExportMixins(apiobj, store, state=None, getargs=None)[source]¶
Bases:
Base
Export mixins for callbacks.
- Parameters:
store (
dict
) –state (
typing.Optional
[dict
]) –getargs (
typing.Optional
[dict
]) –
- APIOBJ = None¶
assets object.
-
CURRENT_ROWS:
typing.Optional
[typing.List
[dict
]] = None¶ current rows being processed
-
CUSTOM_CB_EXC:
typing.List
[dict
] = None¶ tracker of custom callbacks that have been executed by
do_custom_cbs()
-
FIND_KEYS:
typing.List
[str
] = ['name', 'name_qual', 'column_title']¶ field schema keys to use when finding a fields schema
-
TAG_ROWS_ADD:
typing.List
[dict
] = None¶ tracker of assets to add tags to in
do_tagging()
.
-
TAG_ROWS_REMOVE:
typing.List
[dict
] = None¶ tracker of assets to remove tags from in
do_tagging()
.
- __init__(apiobj, store, state=None, getargs=None)¶
Callbacks base class for assets.
- Parameters:
apiobj (
axonius_api_client.api.assets.asset_mixin.AssetMixin
) – Asset object that created this callbackstore (
dict
) – store tracker of get method that created this callbackstate (
typing.Optional
[dict
]) – state tracker of get method that created this callbackgetargs (
typing.Optional
[dict
]) – kwargs passed to assets get method that created this callback
- _add_report_adapters_missing(row)¶
Process report: Missing adapters.
- Parameters:
row (
dict
) – row being processed
- _add_report_software_whitelist(row)¶
Process report: Software whitelist.
- Parameters:
row (
dict
) – row being processed
- _do_add_null_values(row, schema, key='name_qual')¶
Null out missing fields.
- _do_change_field_titles(row)¶
Asset callback to change qual name to title.
- Parameters:
row (
dict
) – row being processed
- _do_excludes(row)¶
Asset callback to remove fields from row.
- Parameters:
row (
dict
) – row being processed
- _do_explode_entities(row)¶
Explode a row into multiple rows for each asset entity.
- Parameters:
row (
dict
) – row being processed- Return type:
- _do_explode_field(row)¶
Explode a field into multiple rows.
- Parameters:
row (
dict
) – row being processed- Return type:
- _do_flatten_fields(row, schema)¶
Asset callback to flatten complex fields.
- _init()¶
Post init setup.
- add_include_dates(rows)¶
Process report: Add dates (history and current)
- Parameters:
rows (
typing.Union
[typing.List
[dict
],dict
]) – rows to process- Return type:
- add_report_adapters_missing(rows)¶
Process report: Missing adapters.
- Parameters:
rows (
typing.Union
[typing.List
[dict
],dict
]) – rows to process- Return type:
- add_report_software_whitelist(rows)¶
Process report: Software whitelist.
- Parameters:
rows (
typing.Union
[typing.List
[dict
],dict
]) – rows to process- Return type:
- classmethod args_map()¶
Get all the argument names and their defaults for this callbacks object. :rtype:
dict
Examples
Create a
client
usingaxonius_api_client.connect.Connect
and assumeapiobj
is eitherclient.devices
orclient.users
>>> import axonius_api_client as axonapi >>> connect_args: dict = axonapi.get_env_connect() >>> client: axonapi.Connect = axonapi.Connect(**connect_args) >>> apiobj: axonapi.api.assets.AssetMixin = client.devices >>> # or client.users or client.vulnerabilities
Flatten complex fields - Will take all sub-fields of complex fields and put them on the root level with their values index correlated to each other.
>>> assets = apiobj.get(fields=["network_interfaces"], field_flatten=True)
Explode a single field - will take that field and create new rows for list item.
>>> assets = apiobj.get(field_explode="hostname")
Exclude fields - Will remove fields from the final output.
>>> assets = apiobj.get(field_excludes=["internal_axon_id", "adapter_list_length"])
Use field titles - Will change internal field names to their titles.
>>> assets = apiobj.get(field_titles=True)
Join fields - Will join multi value fields with carriage returns.
>>> assets = apiobj.get(field_join=True)
Join fields with no trim and custom join value - Will join multi value fields with
;;
and do not trim the joined value to excels maximum cell length.>>> assets = apiobj.get(field_join=True, field_join_value=";;", field_join_trim=0)
Add fields as empty values for fields that did not return.
>>> assets = apiobj.get(field_null=True)
Add fields as empty values for fields that did not return with a custom null value.
>>> assets = apiobj.get( ... field_null=True, ... field_null_value="EMPTY", ... field_null_value_complex="EMPTY LIST", ... )
Add and remove tags to all assets returned.
>>> assets = apiobj.get(tags_add=["tag1", "tag2"], tags_remove=["tag3", "tag4"])
Generate a report of adapters that are missing from each asset.
>>> assets = apiobj.get(report_adapters_missing=True)
Generate a report of installed software that does not match a list of regex for each asset.
>>> assets = apiobj.get(report_software_whitelist=["chrome", "^adobe.*acrobat"])
Echo to STDERR progress messages.
>>> assets = apiobj.get(do_echo=True)
Change the amount of assets that echo page progress when do_echo is true.
>>> assets = apiobj.get(do_echo=True, page_progress=100)
Supply a set of custom callbacks to process each row before all builtin callbacks are run. Custom callbacks receive two arguments:
self
(the current callback object) androws
(the current rows being processed). Custom callbacks must return a list of rows.>>> def custom_cb1(self, rows): ... for row in rows: ... row["internal_axon_id"] = row["internal_axon_id"].upper() ... return rows ... >>> assets = apiobj.get(custom_cbs=[custom_cb1])
See also
args_map_custom()
for callback specific arguments to format and export data.
Notes
These arguments can be supplied as extra kwargs passed to
axonius_api_client.api.assets.users.Users.get()
oraxonius_api_client.api.assets.devices.Devices.get()
- classmethod args_map_base()¶
Get the map of arguments that can be supplied to GETARGS.
- Return type:
- classmethod args_map_custom()¶
Get the custom argument names and their defaults for this callbacks object. :rtype:
dict
See also
args_map()
for the arguments for all callback objects.Notes
This callback object has no custom arguments.
- property args_strs: List[str]¶
Get a list of strings that describe each arg in
args_map()
.
- do_add_null_values(rows)¶
Null out missing fields.
- Parameters:
rows (
typing.Union
[typing.List
[dict
],dict
]) – rows to process- Return type:
- do_change_field_compress(rows)¶
Asset callback to shorten field names.
- Parameters:
rows (
typing.Union
[typing.List
[dict
],dict
]) – rows to process- Return type:
- do_change_field_replace(rows)¶
Asset callback to replace characters.
- Parameters:
rows (
typing.Union
[typing.List
[dict
],dict
]) – rows to process- Return type:
- do_change_field_titles(rows)¶
Asset callback to change qual name to title.
- Parameters:
rows (
typing.Union
[typing.List
[dict
],dict
]) – rows to process- Return type:
- do_custom_cbs(rows)¶
Execute any custom callbacks for current row.
- Parameters:
rows (
typing.Union
[typing.List
[dict
],dict
]) – rows to process- Return type:
- do_excludes(rows)¶
Asset callback to remove fields from row.
- Parameters:
rows (
typing.Union
[typing.List
[dict
],dict
]) – rows to process- Return type:
- do_explode_entities(rows)¶
Explode a row into a row for each asset entity.
- Parameters:
rows (
typing.Union
[typing.List
[dict
],dict
]) – rows being processed- Return type:
- do_explode_field(rows)¶
Explode a field into multiple rows.
- Parameters:
rows (
typing.Union
[typing.List
[dict
],dict
]) – rows being processed- Return type:
- do_flatten_fields(rows)¶
Asset callback to flatten complex fields.
- Parameters:
rows (
typing.Union
[typing.List
[dict
],dict
]) – rows to process- Return type:
- do_join_values(rows)¶
Join values.
- Parameters:
rows (
typing.Union
[typing.List
[dict
],dict
]) – rows to process- Return type:
- do_pre_row(rows)¶
Pre-processing callbacks for current row.
- Parameters:
rows (
typing.Union
[typing.List
[dict
],dict
]) – rows to process- Return type:
- do_row(rows)¶
Execute the callbacks for current row.
- Parameters:
rows (
typing.Union
[typing.List
[dict
],dict
]) – rows to process- Return type:
- do_tag_add()¶
Add tags to assets.
- do_tag_remove()¶
Remove tags from assets.
- do_tagging()¶
Add or remove tags to assets.
- echo(msg, debug=False, error=False, warning=False, level='info', level_debug='debug', level_error='error', level_warning='warning', abort=True)¶
Echo a message to console or log it.
- Parameters:
msg (
typing.Union
[str
,typing.List
[str
]]) – message to echoerror (
typing.Union
[bool
,str
,typing.Type
[Exception
]]) – message is an errorwarning (
bool
) – message is a warninglevel (
str
) – logging level for non error/non warning messageslevel_debug (
str
) – logging level for debug messageslevel_error (
str
) – logging level for error messageslevel_warning (
str
) – logging level for warning messagesabort (
bool
) – sys.exit(1) if error is truedebug (
bool
) – message is a debug message
- echo_columns(**kwargs)¶
Echo the columns of the fields selected.
- echo_page_progress()¶
Echo progress per N rows using an echo method.
- property field_replacements: List[Tuple[str, str]]¶
Parse the supplied list of field name replacements.
- get_arg_value(arg)¶
Get an argument value.
- Parameters:
arg (
str
) – key to get fromGETARGS
with a default value fromargs_map()
- Return type:
- get_sub_schemas(schema)¶
Get all the schemas of sub-fields for a complex field.
- Parameters:
schema (
dict
) – schema of complex field- Return type:
- is_excluded(schema)¶
Check if a name supplied to field_excludes matches one of FIND_KEYS.
- process_row(row)¶
Process the callbacks for current row.
- Parameters:
row (
typing.Union
[typing.List
[dict
],dict
]) – row to process- Return type:
- process_tags_to_add(rows)¶
Add assets to tracker for adding tags.
- Parameters:
rows (
typing.Union
[typing.List
[dict
],dict
]) – rows to process- Return type:
- process_tags_to_remove(rows)¶
Add assets to tracker for removing tags.
- Parameters:
rows (
typing.Union
[typing.List
[dict
],dict
]) – rows to process- Return type:
- set_arg_value(arg, value)¶
Set an argument value.
- Parameters:
value (
typing.Any
) – value to set for key
- start(**kwargs)¶
Start this callbacks object.
- stop(**kwargs)¶
Stop this callbacks object.
-
LOG:
logging.Logger
¶ logger for this object.
- classmethod args_map_export()[source]¶
Get the export argument names and their defaults for this callbacks object. :rtype:
dict
See also
args_map_custom()
for the arguments specific to this callback object.args_map()
for the arguments for all callback objects.
- axonius_api_client.api.asset_callbacks.base.ARG_DESCRIPTIONS: dict = {'csv_dialect': 'For CSV Export: CSV Dialect to use', 'csv_field_flatten': 'For CSV/XLSX Export: Enable flattening of complex fields', 'csv_field_join': 'For CSV/XLSX Export: Enable joining of list fields', 'csv_field_null': 'For CSV/XLSX Export: Enable null values for missing fields', 'csv_key_extras': 'For CSV Export: What to do with extra CSV columns', 'csv_key_miss': 'For CSV Export: Value to use when keys are missing', 'csv_quoting': 'For CSV Export: CSV quoting style', 'custom_cbs': 'Custom callbacks to perform on assets', 'debug_timing': 'Enable logging of time taken for each callback', 'do_echo': 'Echo messages to console', 'expirable_tags': 'Expiration dates for tags', 'explode_entities': 'Split rows into one row for each asset entity', 'export_backup': 'If export_file exists, rename it with the datetime', 'export_fd': 'Export to a file descriptor', 'export_fd_close': 'Close the file descriptor when done', 'export_file': 'File to export data to', 'export_overwrite': 'Overwrite export_file if it exists', 'export_path': 'Directory to export data to', 'export_schema': 'Export schema of fields', 'field_compress': "Shorten field names in output to 'adapter:field'", 'field_excludes': 'Fields to exclude from output', 'field_explode': 'Field to explode', 'field_flatten': 'Flatten complex fields', 'field_join': 'Join list field values', 'field_join_trim': 'Join list field character limit (0 = None)', 'field_join_value': 'Join list field values using', 'field_null': 'Add null values for missing fields', 'field_null_value': 'Null value to use for missing simple fields', 'field_null_value_complex': 'Null value to use for missing complex fields', 'field_replace': 'Field name character replacements', 'field_titles': 'Rename fields to titles', 'include_dates': 'Include history date and current date as a columns in the output', 'json_flat': 'For JSON Export: Use JSONL format', 'page_progress': 'Echo page progress every N assets', 'report_adapters_missing': 'Add Missing Adapters calculation', 'report_software_whitelist': 'Missing Software to calculate', 'table_api_fields': 'For Table export: Include API fields in output', 'table_format': 'For Table export: Table format to use', 'table_max_rows': 'For Table export: Maximum rows to output', 'tags_add': 'Tags to add to assets', 'tags_add_invert_selection': 'Invert selection for tags to add', 'tags_remove': 'Tags to remove from assets', 'tags_remove_invert_selection': 'Invert selection for tags to remove', 'xlsx_cell_format': 'For XLSX Export: Formatting to apply to every cell', 'xlsx_column_length': 'For XLSX export: Length to use for every column'}¶
Descriptions of all arguments for all callbacks