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.
import json
from datetime import datetime
from airflow.models import DAG
from airflow.models.param import Param
from airflow.providers.http.operators.http import SimpleHttpOperator
from airflow.operators.python import PythonOperator
import logging
from Success import *
from Failure import *
DAG definition calls must supply the parameters required by the action.
myParams = {
    "notification_obj": {}
}
DAG definition requires the dag name (dag_id), schedule interval, start date, parameters, and references to the success and failure callbacks.
dag_id='{{tcsa.dag_name}}',
    schedule_interval=None,
    start_date=datetime(2023,6,2),
    params=myParams,
    is_paused_upon_creation=False,
    catchup=False,
    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 User-Defined Action
import json
from datetime import datetime
from airflow.models import DAG
from airflow.models.param import Param
from airflow.providers.http.operators.http import SimpleHttpOperator
from airflow.operators.python import PythonOperator
import logging
from Success import *
from Failure import *

def task_edit_notif_func(**context) -> None:
    updatedNotif = context["params"]["notification_obj"]
    updatedNotif["UserDefined3"] = '{{tcsa.UserDefined3Value}}'
    updatedNotif["UserDefined4"] = "GotUpdatedByAction4"
    updatedNotif["UserDefined5"] = "GotUpdatedByAction5"
    return json.dumps(updatedNotif)

myParams = {
    "notification_obj": {}
}

with DAG(
    dag_id='{{tcsa.dag_name}}',
    schedule_interval=None,
    start_date=datetime(2023,6,2),
    params=myParams,
    is_paused_upon_creation=False,
    catchup=False,
    on_success_callback =success,
    on_failure_callback =failure
) as dag:

    # 1. get notification from opensearch
    task_edit_notif = PythonOperator(task_id='task_edit_notif',
        python_callable=task_edit_notif_func,
        dag=dag,
        on_success_callback = success,
        on_failure_callback =failure
    )


    # 2. get event causes 
    task_update_notif = SimpleHttpOperator(
        task_id='task_update_notif',
        method='PUT',
        http_conn_id='{{tcsa.task_update_notif_conn_id}}',
        endpoint='vsa_events/_doc/Name:[[ params.notification_obj.Name]]$Source:[[ params.notification_obj.Source]]$' ,
        headers={"Accept":"application/json","Content-Type":"application/json"},
        data = '[[ ti.xcom_pull(task_ids=["task_edit_notif"][0]) ]]',
        extra_options = {'verify':False},
        do_xcom_push=True,
        log_response=True,
        on_success_callback =success,
        on_failure_callback =failure
    )

    task_edit_notif >> task_update_notif
The tasks must be specified at the bottom of the file. The following sequence implies that task task_edit_notif is executed first. Then on task task_edit_notif success, task task_update_notif is executed. If task task_edit_notif fails, task task_update_notif cannot run as the upstream task, and it fails.
task_edit_notif >> task_update_notif

How to Use a Connection and a Parameter for a User-Defined Action

For creating a new Escalation or Remediation Rule with a user-defined action, you can use Connections and pass values to the Parameters.
  • If you want to create an user-defined action, you can refer to the HTTP/REST connection id with a parameterized name as given in the sample user-defined action.
    http_conn_id='{{tcsa.task_update_notif_conn_id}}'
  • Define an action parameter with the name UserDefined3Value as follows:CustomParameter
  • Update the parameter name as shown in the sample user-defined action.
    updatedNotif["UserDefined3"] = '{{tcsa.UserDefined3Value}}'
  • When creating a Remediation Rule with that action, you will be prompted to update a value for the UserDefined3Values parameter field.CustomAction
    • Select a relevant connection which in this case is the connection to VMware Telco Cloud Service Assurance Opensearch named es_http.
    • Pass a value to the relevant UserDefined3Value parameter.
    CustomParameterUI