You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 15 Next »

Overview

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

Because it is a characteristic of the group, to use this feature, set the column "NotificationMethod" on Alarm/Groups with the method that will handle the email sending. This mean that the method will be called ever an alarm of 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:


Configuration Process

To the properly functioning of this tool, is needed to make shore two things: the sending method is correctly described, and the alarm is triggering properly.


Creating a Sending Method

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

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 event.

Binding Method to Alarm Group

It can be done through the "NotificationMethod" column in the Alarms → Groups table. There are two ways to set this field, you can write the full FrameworX's method path or do it through the 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.NotificationsHandle.sendEmail

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

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

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

Click OK and it's done.



larm Example 1 - Sending E-mail C#

Creating Tags and Interface

To sending an e-mail, some information is needed, like the source e-mail, the target e-mail, smtp, password of source account. then we need one tag for each of properties. In order to better organize the solution tags, we will use a template only to these settings. Furthermore, the “Sensor” tag will be used to trigger the alarm condition. In order to your project send an email when an alarm happens, you need to configure some alarm items. See the images below:


Display Configuration

Basically, is needed to get the previously information needed to send an e-mail. Plus add a way to change the sensor value and visualize the alarms.

Create a Class Method


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


The 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"

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.

DateTimeOffset AckTime 
         DateTimeOffset ActiveLocalTime 
         DateTimeOffset ActiveTime 
         string Area 
         string Category 
         string ColorBG 
         string ColorFG 
         string Comment 
         int Condition 
         DateTimeOffset DateCreated 
         string Deadband 
         string DetailsValue 
         int Disable 
         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 the NotificationMethod, you can do everything you want, such as send an email, send a message box, speech an alarm message, etc.



In this section:

The root page @parent could not be found in space v10.

  • No labels