Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 
 

Understand User-Defined Actions and Functions

When creating rules, Paragon Automation Platform includes the ability to run user-defined actions (UDAs) as part of a trigger. A Rule executes UDAs as Python scripts. For example, you might configure a rule with a trigger that reacts to some critical interface going down and responds to the event by calling a function to send an SMS alert. You can write the logic to send the SMS in a UDA python script.

In Paragon Automation, you can schedule UDAs and notifications. This is useful when you deploy multiple parallel instances of Paragon Automation Platform in different locations. You can schedule UDAs to run alternatively from UDA schedulers located in different regions. In the event of a node failure, the UDA scheduler running in a parallel instance continues to execute your UDA and notifications. To enable UDA scheduler, see Enable UDA Scheduler in Trigger Action.

You can also includes the ability to run user-defined functions (UDFs). Also created as Python scripts, UDFs provide the ability to process incoming telemetry data from a device and store the processed value in the time-series database for that device/device-group. For example, the device may be sending FPC temperature in Celsius but you want to process it to be stored as Fahrenheit values in the database.

The processing of UDF fields is handled by microservices called UDF farm unless, you declare global variables in Python scripts. This approach allows for Paragon Insights to process multiple data points from multiple devices and fields at the same time (parallel processing). The result is a 4 to 5 times increase in processing performance for UDA/UDF.

Global Variables in Python Scripts

TAND executes Python scripts that use global variables. Global variables retain a value across multiple UDFs.

The following is an example function to calculate cumulative sum and store the value in global variable sum.

When you use global variables in Python scripts, the UDFs are processed by TAND instead of UDF farms.

As an alternative to global variables, you can use the Python construct **kwargs to capture values that must be retained across different functions. When Paragon Insights calls a function (defined in a UDF), it sends topic name, rule name, device group, point time, and device ID that are captured using the construct **kwargs. In case of UDAs, Paragon Automation sends topic name and rule name while executing the Python script.

Along with infrastructure values, Paragon Insights also sends a parameter called hb_store in **kwargs that fetches the last computed value for a variable.

To illustrate how hb_store works in the cumulative addition example:

Each time a function with the above code is called, it performs addition of last stored value in ’sum’ with the value of a and value of b. The new value of addition operation is displayed and stored in ’sum’.