Toolbox.Scenario.OutputAction (toolbox v1.1.0)

Struct representing side effects produced by run. There are several constructor functions to simplify and standardize side effect definition.

Instances of this struct are being parsed and then passed to output server.

Link to this section Summary

Functions

Constructor for calling SQL query.

Constructor for create new asset side effect.

Constructor for create edge between assets side effect.

Constructor for delete asset side effect.

Constructor for event side effect.

Constructor for new incident (add_asset) action

Constructor for notification side effect.

Constructor for update existing asset side effect.

Constructor for upsert asset side effect.

Constructor for upsert edge between assets side effect.

Link to this section Types

@type t() :: %Toolbox.Scenario.OutputAction{
  body:
    map()
    | Toolbox.Scenario.OutputAction.Asset.t()
    | Toolbox.Scenario.OutputAction.Edge.t()
    | Toolbox.Scenario.OutputAction.AssetPatch.t(),
  svector: [any()],
  timestamp: integer(),
  type: type()
}
@type type() ::
  :notify
  | :create_event
  | :add_asset
  | :edit_asset
  | :upsert_asset
  | :delete_asset
  | :add_edge
  | :upsert_edge
  | :delete_edge
  | :execute_sql
  | :bad_output_action

Link to this section Functions

Link to this function

body(output_action)

@spec body(t()) :: map()
Link to this function

execute_sql_action(timestamp, params)

@spec execute_sql_action(non_neg_integer(), map()) :: t()

Constructor for calling SQL query.

First argument is unix timestamp and second is body, which is map with 4 required keys: db_connection, sql_query, data and type.

  • db_connection - map with database connection info (hostname, username, password, database)
  • sql_query - SQL query.
  • data - list of parameterized data.
  • type - database type, right now only PostgreSQL is supported. It's checked in OutputProcessor and the value must be :postgresql.

If :run_id is present in data, it's replaced with actual run_id in AssetMap.Api.SqlExecutor.

Link to this function

new(type, body)

@spec new(type(), map()) :: t()
Link to this function

new_create_asset_action(id, timestamp, attributes)

@spec new_create_asset_action(binary(), non_neg_integer(), map()) :: t()

Constructor for create new asset side effect.

Link to this function

new_create_edge_action(id, timestamp, from_id, to_id, type)

@spec new_create_edge_action(
  binary(),
  non_neg_integer(),
  binary(),
  binary(),
  binary()
) :: t()

Constructor for create edge between assets side effect.

Link to this function

new_delete_asset_action(id, timestamp)

@spec new_delete_asset_action(binary(), non_neg_integer()) :: t()

Constructor for delete asset side effect.

Link to this function

new_delete_edge_action(id, timestamp, from_id, to_id, type)

@spec new_delete_edge_action(
  binary(),
  non_neg_integer(),
  binary(),
  binary(),
  binary()
) :: t()
Link to this function

new_event_action(timestamp, params)

@spec new_event_action(non_neg_integer(), map()) :: t()

Constructor for event side effect.

First argument is unix timestamp and second is body, which is map with 3 required keys: actors, type and template.

  • actors - map of actors which are interpolated in the template.
  • params - map of template params that are interpolated in the template.
  • origin_messages - list of raw messages linked with the event itself.
  • template - event's template. See AssetMap.Events.Template.
  • type - type of the event. It's declared in Scenario's Manifest.
Link to this function

new_incident_action(id, attributes)

@spec new_incident_action(binary(), Toolbox.Scenario.OutputAction.Incident.t()) :: t()

Constructor for new incident (add_asset) action

Link to this function

new_notification_action(timestamp, params)

@spec new_notification_action(timestamp :: non_neg_integer(), params :: map()) :: t()

Constructor for notification side effect.

Params describe the notification to be created. It has the following keys

  • :type - string, type of the notification
  • :data - map, data for the template evaluation
  • :primary_asset - string, optional, id of an asset that corresponds to this notification
  • :ids - list of asset ids, optional, to filter recipients, each recipient must have sufficient privileges to see all listed IDs
  • :aqls - map, AQLs which are evaluated, provide further context to the templates, and also can serve the same purpose as ids - filter recipients to only those who can see the whole result of the query. Key is the name of the AQL which can be used in the template. Value is a map with aql (the AQL query) and primary (whether the AQL should also be used to filter recipients) keys.
  • :priority - optional, defaults to :medium, can be :low, :medium, :high, only applicable to some channels
  • :metadata - map, optional, additional metadata which can be used in notification group subscriptions. Should adhere to the format specified in notification/spec.exs.
  • :direct_subscriptions - list of maps, subscriptions to be used additionally to the usual routing. Each map should have the following.
    • :user - map, user object to be used instead of Altworx object, should have notification.email and optionally even notification.language.
    • :templates - list of ids, which templates should be used
    • :channels - list of ids, which channels should be used
  • :attachments - list of maps, optional, attachments that should be sent with the notification. Each map has the following keys.
    • data - binary, content of the attachment
    • filename - string, name of the file
    • content_type - string, optional, MIME type of the data
    • type - whether the attachment is to inlined in the template (:inline) or not (:attachment, this is the default)
Link to this function

new_update_asset_action(id, timestamp, update, delete \\ nil)

@spec new_update_asset_action(binary(), non_neg_integer(), map() | nil, map() | nil) ::
  t()

Constructor for update existing asset side effect.

Link to this function

new_upsert_asset_action(id, timestamp, attributes)

@spec new_upsert_asset_action(binary(), non_neg_integer(), map()) :: t()

Constructor for upsert asset side effect.

Link to this function

new_upsert_edge_action(id, timestamp, from_id, to_id, type)

@spec new_upsert_edge_action(
  binary(),
  non_neg_integer(),
  binary(),
  binary(),
  binary()
) :: t()

Constructor for upsert edge between assets side effect.

Link to this function

set_body(oa, body)

@spec set_body(t(), map()) :: t()
Link to this function

set_type(oa, type)

@spec set_type(t(), type()) :: t()
Link to this function

type(output_action)

@spec type(t()) :: type()