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

Table of Contents
maxLevel3
minLevel2


Installation Notes

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.

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 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 FrameworkXFrameworX'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.



Configuration Example

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


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 Block
public void AlarmEvents(AlarmEventInfo[] events)
{
	//Protection in case events its null
	if (events == null)
		return;
	
	//Get the first event
	AlarmEventInfo event = events[0];
	if  (event.State != 1)
		return;
	
	//Get information about the alarm event to create the body of the email	
	string body = "Time: " + event.ActiveLocalTime.ToString() + "\n" +
	"Message = " + 	event.Message + "\n" +
	"Area = " + event.Area + "\n" +
	"Group = " + event.Group + "\n" +
	"Tag = " + 	event.TagName + "\n"	 ;
	
	//Code to send email			
	try 
	{
	    	//Configuring the SMTP Client
		System.Net.Mail.SmtpClient mySmtpClient = new System.Net.Mail.SmtpClient(@Tag.smtpServer, 587);
        		mySmtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
        		mySmtpClient.EnableSsl = true;
        		mySmtpClient.UseDefaultCredentials = false;
        		mySmtpClient.Credentials = new System.Net.NetworkCredential(@Tag.fromEmail, @Tag.passFromEmail);
       
		//Sending the email
		mySmtpClient.Send(@Tag.fromEmail, @Tag.toEmail, "Dmail notification", body);
      
	}
	catch (Exception ex)
	{
		@Info.Trace("Error sending message: " + ex.Message);
	}
}


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


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



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

Page Tree
root@parent
spacesV10