Each Action has many properties that determine its behavior. The required properties are:
Check out Action Properties for details on all available properties and how to use them.
As a demonstration, below we'll create an Action that outputs the three processes with the highest CPU usage.
Create an Action with Op using the following syntax:
action <name> = <command>.
Begin by defining an Action named
high_cpu_actionand set the command property to the following:op>action high_cpu_action = `ps -Ao comm,pid,pcpu --sort=-pcpu | head -n 4`
Created action 'high_cpu_action'.
Understanding Action Resource Query
However, if you wish to manually execute an Action or use it in context outside of the normal automated remediation loop, you'll need to specify the Action's resource_query property.op>high_cpu_action()
Error: Linux commands must be preceded by a resource query
Set the resource_query property to execute against all containers with names containing
"shoreline"op>high_cpu_action.resource_query = container | name=~"shoreline"
Updated action 'high_cpu_action'.
Try manually executing the Action once againop>high_cpu_action()
ID | TYPE | NAME | STDOUT 8 | CONTAINER | test10-cust.shoreline-67ln6.shoreline | COMMAND PID %CPU | | | metric_scraper 224 1.9 | | | python3 201 0.8 | | | python3 236 0.8 | | | 17 | CONTAINER | test10-cust.shoreline-2ghfk.shoreline | COMMAND PID %CPU | | | metric_scraper 223 2.3 | | | python3 199 0.9 | | | python3 235 0.9 | | | 38 | CONTAINER | test10-cust.shoreline-2kkh2.shoreline | COMMAND PID %CPU | | | metric_scraper 220 5.6 | | | python3 234 2.0 | | | python3 233 1.8 | | |
Now that the Action knows which Resources to execute against we get the expected results.
See the full Action.resource_query property description for more details.