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.

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.

Let's do it.

Creating a Sending Method

The notification method is the script that will run when the alarm was triggered, it needs to be built as follows.

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)

ps: For this example, the name "NotificationMethod" was chosen here, 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 create creating a method, we need to bind this it with an Alarm Group, It can 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>

in my case it wasFor 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:

learn 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, the SMTP link smtp, 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. In order to for your project to send an email when an alarm happensoccurs, you need to configure some alarm items. See the images below:

Image Removed

Image RemovedImage AddedImage Added

Display Configuration

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

Image RemovedImage AddedImage Added


Create a Class Method

Image RemovedImage Added


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

Image RemovedImage RemovedImage AddedImage Added


The NotificationMethod that then 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 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);
        mySmtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
        mySmtpClient.EnableSsl = true;
        mySmtpClient.UseDefaultCredentials = false;
        mySmtpClient.Credentials = new System.Net.NetworkCredential(@Tag.MyEmailSettings.senderEmail, @Tag.MyEmailSettings.senderPassword);
        //mySmtpClient.Credentials = new System.Net.NetworkCredential("welliton.faturas@hotmail.com", "AGBDLCID3aA");
       
		//Sending the email
		mySmtpClient.Send(@Tag.MyEmailSettings.senderEmail, @Tag.MyEmailSettings.recipientEmail, "Email notification", body);
      
	}
	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 
         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