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.
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
Setting Alarm
Is necessary to create an item and configure the "NotificationMethod" to the group, like the following image.
Notification Method
C#
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:
public void AlarmEvents(AlarmEventInfo[] events) { }
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.
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: