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 | ||||||
---|---|---|---|---|---|---|
|
Tip | ||
---|---|---|
| ||
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:
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:
Alarm Example 1 -Sending E-mail C#
Creating Tags and Interface
To send an e-mail, some information is needed, such as the source e-mail, the target e-mail, the SMTP link, and the password for the source account. Then, we need one tag for each of these properties. To better organize the solution tags, we will use a template specifically for these settings. Furthermore, the “Sensor” tag will be used to trigger the alarm condition. In order for your project to In order to your project send an email when an alarm happensoccurs, you need to configure some alarm items. See the image images below:
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.
Create a Class Method
The next step is to configure the NotificationMethod column in the Alarms / Groups section like the following image:
The NotificationMethod then 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 of code below :in which an email is sent from a template called "MyEmailSettings"
Code Block |
---|
public void AlarmEventsSendEmail(AlarmEventInfo[] events) { //Protection in case events its null if (events == null) return; //Get the first event AlarmEventInfo eventeventX = events[0]; if (eventeventX.State != 1) return; //Get information about the alarm event to create the body of the email string body = "Time: " + eventeventX.ActiveLocalTime.ToString() + "\n" + "Message = " + eventeventX.Message + "\n" + "Area = " + eventeventX.Area + "\n" + "Group = " + eventeventX.Group + "\n" + "Tag = " + eventeventX.TagName + "\n" ; //Code to send email try { //Configuring the SMTP Client System.Net.Mail.SmtpClient mySmtpClient = new System.Net.Mail.SmtpClient(@Tag.MyEmailSettings.smtpServerServer_SMTP, 587); mySmtpClient.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network; mySmtpClient.EnableSsl = true; mySmtpClient.UseDefaultCredentials = false; mySmtpClient.Credentials = new System.Net.NetworkCredential(@Tag.fromEmailMyEmailSettings.senderEmail, @Tag.passFromEmail.MyEmailSettings.senderPassword); //mySmtpClient.Credentials = new System.Net.NetworkCredential("welliton.faturas@hotmail.com", "AGBDLCID3aA"); //Sending the email mySmtpClient.Send(@Tag.MyEmailSettings.fromEmailsenderEmail, @Tag.toEmailMyEmailSettings.recipientEmail, "DmailEmail 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 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 | ||||
---|---|---|---|---|
|