How to Use Cumulocity IoT Streaming Analytics EPL apps to send emails for alarms

Introduction

As an IoT platform developer, you might be responsible for monitoring alarms and ensuring that they are fixed ASAP. Setting up email alerts for your alarms is one thing that may greatly simplify your job. In Cumulocity IoT, Streaming Analytics EPL apps could be the solution you need.

Prerequisite

Before you dive in, it’s important to note that you need to have SMTP configured to enable an app to send an email based on an alarm.

Once you have SMTP configured, here’s how you can use the EPL apps to send those emails and take your alarm monitoring game to the next level.

This solution has been written on Cumulocity IoT version 10.16, but should work for all versions newer than 10.4.6.

Accessing Streaming Analytics EPL Apps and the samples

To modify or add the necessary app to trigger the email, you can use Streaming Analytics EPL apps and the associated samples. Here’s how:

In Streaming Analytics on the EPL Apps page click on “New EPL App” and then “Samples” to access example code for sending emails. In version 10.16 there is a sample called “Perform an operation or send an email or SMS if a specified alarm is received”.

Take advantage of the documentation available to you by visiting this link: SendEmail

Sending an email with Streaming Analytics EPL Apps

Here’s an example of how to send an email using the SendEmail() function:

Use the following code to set up your email:

SendEmail("<Email Subject>",
          "<Email Body>",
          "<email reply to (Example: noreply@customer.com)>",
          ["recipient_1@customer.com", "recipient_2@customer.com"],
          ["cc_recipient_1@customer.com", "cc_recipient_2@customer.com"],
          "bcc_recipient_1@customer.com, bcc_recipient_2@customer.com",
          {"assetId": "10XXX"}
) to SendEmail.SEND_CHANNEL;

Replace the placeholders with your desired email information.

Developing a periodic control to send a warning

If you’re looking to develop a periodic control to send a warning if there’s a fault somewhere, EPL apps can also help. Here’s how:

Use the following code to set up your periodic control:

var ctrl = apama.control.createPeriodicControl("MyControl", 60.0);  

ctrl.onTick = function() {  

// Check for faults here  
// If there's a fault, use the SendEmail() function to send an email  

}

Replace the placeholder with your desired periodic control time.

Relevant Articles

1 Like