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 deals with . This page provides an example that uses the C# language to send e-mails when an alarm has been triggered.

Because it Since this is a characteristic of the group, to use this feature, set the column "NotificationMethod" on Alarm / Groups with to the method that will handle the email sending. This mean means that the method will be will be called ever whenever an alarm of in that respective group is triggered.This page describes how to configure your project to send an email using the NotificationMethod feature when an alarm is active.

On this page:

Table of Contents
maxLevel3
minLevel2
stylenone

Tip
titleSolution Example

Alarms Email and SMS Example



Configuration Process

To ensure the properly proper functioning of this tool, it is needed necessary to make shore confirm two things: if the sending method is correctly correctly described,  and 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 like as the following.

Code Block
public void NotificationMethod(AlarmEventInfo[] events)

This means the method needs a parameter typed AlarmEventInfo[] which contains the AlarmItens information like TagName, Group, Message, Area and data and time of this eventFor 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

It can 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, you can write either by writing the full FrameworX's method path or do it through by using the visual interface, clicking on "..." button on right side of this field.

If you chose to write the full FrameworkX's 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 chose choose to do it by the interface, a display like this will appear:

Image Modified

The Script.Class three tree shows every class with the domain Server. 

To select a method, only open the Scripts navigate through this tree and select the method that will be used for the call back callback when an alarm happens. Note that the full path appears in the label "Asset Path".

Click OK and it's done.to save the changes. 


Example:

larm Example 1 -

Sending E-mail C#

Creating Tags and Interface

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

Image Removed

Image Removed

Display Configuration

Image Removed

Create a Class Method

Image Removed

Setting Alarm

Is necessary to create an item and configure the "NotificationMethod" to the group, like the following image.

Image RemovedImage Removed

Notification Method

C#

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

Image Removed

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 code below:

Code Blockpublic void AlarmEvents(AlarmEventInfo[] events) { }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 RemovedImage AddedImage Added


The last steps are to create a display, configure the email, and generate some alarmsNotificationMethod then receives the alarm events that are being generated. 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.

of code below in which an email is sent from a template called "MyEmailSettings"

Code Block
public void SendEmail(AlarmEventInfo[] events)
{
 //Protection in case events its null
	if (events == null)
		return;
	
	//Get the first event
	AlarmEventInfo eventX = events[0];
	if  (eventX.State != 1)
		return;
	
	//Get information about the alarm event to create the body of the email	
	string body = "Time: " + eventX.ActiveLocalTime.ToString() + "\n" +
	"Message = " + 	eventX.Message + "\n" +
	"Area = " + eventX.Area + "\n" +
	"Group = " + eventX.Group + "\n" +
	"Tag = " + 	eventX.TagName + "\n"	 ;   
    
	//Code to send email			
	try 
	{
	    //Configuring the SMTP Client
		System.Net.Mail.SmtpClient mySmtpClient = new System.Net.Mail.SmtpClient(@Tag.MyEmailSettings.Server_SMTP, 587);
Code Block
DateTimeOffset AckTime 
         DateTimeOffset ActiveLocalTime 
         DateTimeOffset ActiveTime 
         string Area 
         string Category 
         string ColorBG 
         string ColorFG 
         string Comment 
         int Condition 
         DateTimeOffset DateCreated 
        mySmtpClient.DeliveryMethod string Deadband = System.Net.Mail.SmtpDeliveryMethod.Network;
        mySmtpClient.EnableSsl string= DetailsValue true;
        mySmtpClient.UseDefaultCredentials int= Disable false;
         TimeSpan Duration mySmtpClient.Credentials = new System.Net.NetworkCredential(@Tag.MyEmailSettings.senderEmail, @Tag.MyEmailSettings.senderPassword);
        //mySmtpClient.Credentials = string Group new System.Net.NetworkCredential("welliton.faturas@hotmail.com", "AGBDLCID3aA");
       
		//Sending the string Level 
    email
		mySmtpClient.Send(@Tag.MyEmailSettings.senderEmail, @Tag.MyEmailSettings.recipientEmail, "Email notification", body);
     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
	}
	catch (Exception ex)
	{
		@Info.Trace("Error sending message: " + ex.Message);
	}
	
}



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 
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 
string Setpoint 
string SetpointDeadband            
string TagName 
string UserName 
string Value

Once you have defined the NotificationMethod, you can do other actions besides sending an emailOnce in the NotificationMethod, you can do everything you want, 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