A remediation action is a Directed Acyclic Graph (DAG) that uses Python.

  • Each action is composed of one or more tasks.
  • Each task uses a particular operator. For example, HTTP/ssh/slack/python for connecting to external services.
  • The tasks for HTTP/ssh/slack can refer to the Connections when connecting to an external service. For example, for a HTTP GET/POST operation.
  • The python-operator task is used for writing a Python function that works on the data received from or to is sent to external services.
  • You must specify the paths for the operators and Python modules in the import section of the Python action file.
You must import the success and failure callbacks.
from Success import *
from Failure import *
DAG definition calls must supply the parameters required by the action with default values.
myParams = { 
"param1":"defaultvalue1", 
“param2”:”defaultvalue2” 
}
DAG definition requires the dag name (dag_id), parameters, and references to the success and failure callbacks.
with DAG(
	dag_id='cisco_router_action',
       params=myParams,
       on_success_callback =success,
       on_failure_callback =failure
) as dag:
Each task of a DAG must specify the task_id, dag name, optional connection id/command, and success and failure callbacks.
# example task 1. run a command on a Cisco router
# ssh-cisco connection id is defined under Connections 
t1 = SSHOperator(ssh_conn_id='ssh-cisco',  
  task_id='t1',
  command='show ip route',
  dag=dag,
  on_success_callback = success,
  on_failure_callback =failure)
# example task 2, using a HTTP operator on a GET endpoint
# rest_svc_connection connection_id is defined under Connections
t2 = SimpleHttpOperator(
        task_id='t2’,
        method='GET',
        http_conn_id='rest_svc_connection',
        endpoint='rest/api/getdata/',
        headers={"Accept":"application/json","Content-Type":"application/json"},
        data = json.dumps({“foo”: “bar” }),
        extra_options = {'verify':False},
        response_filter=lambda response: response.json()['id'],
        on_success_callback = success,
        on_failure_callback =failure
    )
The tasks must be specified at the bottom of the file. The following sequence implies that task t1 is executed first. Then on task t1 success, task t2 is executed. If task t1 fails, task t2 cannot run as the upstream task, and it fails.
t1 >> t2