Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Overview

Sending notifications by e-mail is done through scripts. This page provides an example that uses the C# language to send e-mails when an alarm has been triggered.

Since this is a characteristic of the group, to use this feature, set the column "NotificationMethod" on Alarm / Groups to the method that will handle the email sending. This means that the method will be called whenever an alarm in that respective group is triggered.

On this page:

Table of Contents
maxLevel3
minLevel2
stylenone

Tip
titleSolution Example

Alarms Email and SMS Example



Configuration Process

To ensure the proper functioning of this tool, it is necessary to confirm two things: if the sending method is correctly described, and if the alarm is triggering properly.

Creating a Sending Method

The notification method is the script that will run when the alarm was triggered.

Go to Scripts / Classes and create C# class from the Server domain, then create a public method as the following.

Code Block
public void NotificationMethod(AlarmEventInfo[] events)

For this example, the name "NotificationMethod" was chosen, but any name is possible. The essential thing is that the method is public and that the arguments are as described.

Binding Method to Alarm Group

After creating a method, we need to bind it with an AlarmGroup. This can be done through the "NotificationMethod" column in the Alarms / Groups table.

There are two ways to set this field, either by writing the full method path or by using the visual interface, clicking on "..." button on right side of this field.

If you chose to write the full path, the string will be like this: 

Script.Class.<CLASS NAME>.<METHOD NAME>

For this example, it would be: "Script.Class.NotificationsHandle.sendEmail".

If you choose to do it by the interface, a display like this will appear:

Image Added

Easy Heading Macro
headingIndent40
navigationTitleOn this page
selectorh2,h3
wrapNavigationTexttrue
navigationExpandOptiondisable-expand-collapse
This page describes how to configure your project to send an email using the NotificationMethod feature when an alarm is active.

Installation Notes

You can find the NotificationMethod column in the Alarm → Group table.

The Script.Class tree

When you double-click on the NotificationMethod column, it shows every class with the domain Server. After you select the server class, it will show which Method  

To select a method, navigate through this tree and select the method that will be used for the call back callback when an alarm happens. However, the NotificationMethod must follow this prototype:

Code Block
public void NotificationMethod(AlarmEventInfo[] events)

Note that the full path appears in the label "Asset Path".

Click OK to save the changes. 


Example: Sending E-mail C#

Creating Tags and Interface

To send an e-mail, some information is needed, such as the source e-mail, the target e-mail, the SMTP link, and the password for the source account. Then, we need one tag for each of these properties. To better organize the solution tags, we will use a template specifically for these settings. Furthermore, the “Sensor” tag will be used to trigger the alarm condition. In order for your project to

Configuration Example

In order to your project send an email when an alarm happensoccurs, you need to configure some alarm items. See the image images below:

Image Removed

Image AddedImage Added

Display Configuration

To send an e-mail, we'll need the previously created information. You also need to add a way to change the sensor value and visualize the alarms.

Image AddedImage Added


Create a Class Method

Image Added


The next step is to configure the NotificationMethod column in the Alarms / Groups section like the following image:

Image AddedImage Added


The NotificationMethod then After the items are configured, configure a server class to have a NotificationMethod that receives the alarm events that are being generated. See an example of code below :in which an email is sent from a template called "MyEmailSettings"

Code Block
public void AlarmEventsSendEmail(AlarmEventInfo[] events)
{
	 //Protection in case events its null
	if (events == null)
		return;
	
	//Get the first event
	AlarmEventInfo eventeventX = events[0];
	if  (eventeventX.State != 1)
		return;
	
	//Get information about the alarm event to create the body of the email	
	string body = "Time: " + eventeventX.ActiveLocalTime.ToString() + "\n" +
	"Message = " + 	eventeventX.Message + "\n" +
	"Area = " + eventeventX.Area + "\n" +
	"Group = " + eventeventX.Group + "\n" +
	"Tag = " + 	eventeventX.TagName + "\n"	 ;
	   
    
	//Code to send email			
	try 
	{
	    	//Configuring the SMTP Client
		System.Net.Mail.SmtpClient mySmtpClient = new System.Net.Mail.SmtpClient(@Tag.smtpServerMyEmailSettings.Server_SMTP, 587);
        		mySmtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
        		mySmtpClient.EnableSsl = true;
        		mySmtpClient.UseDefaultCredentials = false;
        		mySmtpClient.Credentials = new System.Net.NetworkCredential(@Tag.MyEmailSettings.fromEmailsenderEmail, @Tag.passFromEmailMyEmailSettings.senderPassword);
        //mySmtpClient.Credentials = new System.Net.NetworkCredential("welliton.faturas@hotmail.com", "AGBDLCID3aA");
       
		//Sending the email
		mySmtpClient.Send(@Tag.MyEmailSettings.fromEmailsenderEmail, @Tag.toEmailMyEmailSettings.recipientEmail, "DmailEmail notification", body);
      
	}
	catch (Exception ex)
	{
		@Info.Trace("Error sending message: " + ex.Message);
	}
	
}
The next step is to configure the NotificationMethod column in the Alarm → Group section:

Image Removed

The last steps are to create a display, configure the email, and generate some alarms. See an example below:

Image Removed



Execution

Every time an alarm happens when the project is running, the method configured in the NotificationMethod column is called. The method will receive an Array of the AlarmEventInfo class as a parameter. The following members can be used for the AlarmEventInfo class.

Code Block
DateTimeOffset AckTime 
         DateTimeOffset ActiveLocalTime 
         DateTimeOffset ActiveTime 
DateTimeOffset DateCreated  
DateTimeOffset NormTime     

string Area 
         string Category 
         string ColorBG 
         string ColorFG 
         string Comment 
         int Condition 
         DateTimeOffset DateCreated 
         string Deadband 
         string DetailsValue 
string Setpoint 
string SetpointDeadband   

int Condition  
int Disable 
int UnAck  
int Priority 
int Quality 
int State
 
TimeSpan Duration 
         

string Group 
         string Level 
         string Limit 
         string Limit1 
         string Limit2 
         string Message 
         DateTimeOffset NormTime 
         int Priority 
         int Quality 
         string Setpoint 
         string SetpointDeadband 
             int State 
         string TagName 
         int UnAck 
         string UserName 
         string Value

Once in you have defined the NotificationMethod, you can do everything you wantother actions besides sending an email, such as send an email, send such as sending a message box, speech creating sound for an alarm message, etc.

→ Check out our Alarms Email and SMS Example.


In this section

...

:

Page Tree
root@parent
spacesV10