Action Properties

A list of configurable Action properties.

command

A shell command that is executed by the Action when it triggers.

This property is automatically defined when creating an Action within the CLI:

op>
action name = `<command>`
op>
action high_cpu_action = `ps -Ao comm,pid,pcpu --sort=-pcpu | head -n 4`

name

The name of the Action. This value must contain only alphanumeric or underscore characters, and must be globally unique.

op>
action name = `<command>`

params

Pass dynamic arguments to your Action by setting the params property.

Consider the following Action that evaluates current CPU usage and compares it to a static value of 10.

op>
action high_cpu_action = `if [ $[100-$(vmstat 1 2|tail -1|awk '{print $15}')] -gt 10 ]; then exit 1; fi`
Instead, you can replace the static value with a parameter of $cpu_threshold.
op>
action high_cpu_action = `if [ $[100-$(vmstat 1 2|tail -1|awk '{print $15}')] -gt $cpu_threshold ]; then exit 1; fi`
Then set the params property to an array containing the cpu_threshold property.
op>
high_cpu_action.params = ["cpu_threshold"]
To use a parameterized Action just pass the named argument and value within the Alarm fire_query or clear_query:
op>
alarm high_cpu_alarm = high_cpu_action(cpu_threshold=10) == 1
op>
high_cpu_alarm.clear_query = high_cpu_action(cpu_threshold=10) == 0
op>
high_cpu_alarm.resource_query = host
op>
enable high_cpu_alarm

res_env_var

Set res_env_var to an environment variable name that is returned by the Action instead of the shell command's exit code.

op>
high_cpu_action.res_env_var = "<ENV_VAR_NAME>"
op>
high_cpu_action.res_env_var = "AVG_CPU_USAGE"
Updated action 'high_cpu_action'.
Using res_env_var Example

res_env_var is most useful when an Alarm's fire_query or clear_query executes an Action.

Consider the following Action that sets the AVG_CPU_USAGE environment variable to the current CPU usage.

op>
action high_cpu_action = `AVG_CPU_USAGE=$[100-$(vmstat 1 2|tail -1|awk '{print $15}')]`
Created action 'high_cpu_action'.

Set res_env_var to the AVG_CPU_USAGE environment variable.

op>
high_cpu_action.res_env_var = "AVG_CPU_USAGE"
Updated action 'high_cpu_action'.

The value returned by high_cpu_action is no longer the default exit status code. Instead, the value of AVG_CPU_USAGE is returned.

Next, create an Alarm with a fire_query evaluating the result of the high_cpu_action. Here we're firing the Alarm when AVG_CPU_USAGE is at least 10.

op>
alarm high_cpu_alarm = high_cpu_action >= 10
op>
high_cpu_alarm.clear_query = high_cpu_action < 10
op>
high_cpu_alarm.resource_query = host
Lastly, enable the Alarm.
op>
enable high_cpu_alarm
The high_cpu_alarm now executes the high_cpu_action, which internally returns the value of the environment variable set in res_env_var. Below we're filtering to find host Resources on which the high_cpu_alarm has fired:
op>
host | filter((events | type="alarm" | name="high_cpu_alarm"))
 ID | TYPE | NAME                | REGION    | AZ
 2  | HOST | i-0a7803bd4fa45dcac | us-west-2 | us-west-2a
 3  | HOST | i-010a03bf359e54b1b | us-west-2 | us-west-2b
Filters excluded 1/3 hosts

The res_env_var property allows you to create complex Action and Alarm relationships based on any environment variables on the Resource.

resource_query

An Action determines which Resources are executed against in two different ways, depending on the context in which it was triggered.

Auto-Remediated Execution

The Resources defined by the Alarm's resource_query property are used by both the Action and the Alarm whenever an Action is automatically triggered by an Alarm.

In this scenario, the Action's resource_query property is ignored, in favor of the triggering Alarm's resource_query.

This flow of an Alarm automatically triggering an Action is the standard scenario for most Shoreline configurations.

Manual Execution

In some instances you may need to manually execute an Action via Op. You can execute Actions directly from the CLI. Alternatively, you can also execute an Action as part of another query statement, such as an Alarm's fire_query.

When an Action is executed outside of the standard auto-remediation loop, the Action must have a valid resource_query property defined. Since this Action doesn't have a triggering Alarm that it can inherit the resource_query from, the Action executes against the Resources defined by its own resource_query property.

op>
high_cpu_action.resource_query = <resource_query>
op>
high_cpu_action.resource_query = pod

Template Properties

These template properties are for convenience and allow you to describe Action-related events better.

  • start_title_template
op>
high_cpu_action.start_title_template = "high cpu remediation has started"
  • start_short_template
op>
high_cpu_action.start_short_template = "high cpu started"
  • error_title_template
op>
high_cpu_action.error_title_template = "high cpu remediation resulted in error"
  • error_short_template
op>
high_cpu_action.error_short_template = "high cpu error"
  • complete_title_template
op>
high_cpu_action.complete_title_template = "high cpu remediation has completed"
  • complete_short_template
op>
high_cpu_action.complete_short_template = "high cpu completed"