Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
AlertNotifier.cs
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Threading.Tasks;
7using Waher.Events;
8
10{
14 public class AlertNotifier : EventSink
15 {
20 public AlertNotifier(string ObjectID)
21 : base(ObjectID)
22 {
23 }
24
29 public override Task Queue(Event Event)
30 {
31 StringBuilder Markdown = new StringBuilder();
32
33 if (!Event.Message.Contains("=======" + Environment.NewLine))
34 {
35 Markdown.AppendLine(Event.Type.ToString());
36 Markdown.AppendLine("===============");
37 Markdown.AppendLine();
38 }
39
40 Markdown.AppendLine(Event.Message);
41
42 Markdown.AppendLine();
43 Markdown.AppendLine("| Information ||");
44 Markdown.AppendLine("|:------|:-----|");
45
46 this.AppendLabel("Timestamp", Event.Timestamp.ToShortDateString() + ", " + Event.Timestamp.ToLongTimeString(), Markdown);
47 this.AppendLabel("Event ID", Event.EventId, Markdown);
48 this.AppendLabel("Actor", Event.Actor, Markdown);
49 this.AppendLabel("Object", Event.Object, Markdown);
50 this.AppendLabel("Module", Event.Module, Markdown);
51 this.AppendLabel("Facility", Event.Facility, Markdown);
52
53 if (!(Event.Tags is null) && Event.Tags.Length > 0)
54 {
55 foreach (KeyValuePair<string, object> P in Event.Tags)
56 this.AppendLabel(P.Key, P.Value?.ToString(), Markdown);
57 }
58
59 return Gateway.SendNotification(Markdown.ToString());
60 }
61
62 private void AppendLabel(string Label, string Value, StringBuilder Markdown)
63 {
64 bool First = true;
65
66 Markdown.Append("| ");
67 Markdown.Append(MarkdownDocument.Encode(Label));
68 Markdown.Append(" | ");
69
70 if (Value.Length > 2 && Value.StartsWith(":") && Value.EndsWith(":") &&
71 EmojiUtilities.TryGetEmoji(Value.Substring(1, Value.Length - 2), out EmojiInfo _))
72 {
73 Markdown.Append(Value);
74 }
75 else
76 {
77 foreach (string Row in Value.Trim().Replace("\r\n", "\n").Replace("\r", "\n").Split('\n'))
78 {
79 if (First)
80 First = false;
81 else
82 Markdown.Append("<br/>");
83
84 Markdown.Append(MarkdownDocument.Encode(Row));
85 }
86 }
87
88 Markdown.AppendLine(" |");
89 }
90 }
91}
Contains information about an emoji.
Static class that provide methods for managing emojis.
static bool TryGetEmoji(string ShortName, out EmojiInfo Emoji)
Tries to get information about an emoji, given its short name.
Contains a markdown document. This markdown document class supports original markdown,...
static string Encode(string s)
Encodes all special characters in a string so that it can be included in a markdown document without ...
Class representing an event.
Definition: Event.cs:10
string Message
Free-text event message.
Definition: Event.cs:131
EventType Type
Type of event.
Definition: Event.cs:121
string Object
Object related to the event.
Definition: Event.cs:136
string Actor
Actor responsible for the action causing the event.
Definition: Event.cs:141
string Module
Module where the event is reported.
Definition: Event.cs:156
DateTime Timestamp
Timestamp of event.
Definition: Event.cs:116
KeyValuePair< string, object >[] Tags
Variable set of tags providing event-specific information.
Definition: Event.cs:166
string EventId
Computer-readable Event ID identifying type of even.
Definition: Event.cs:146
string Facility
Facility can be either a facility in the network sense or in the system sense.
Definition: Event.cs:151
Base class for event sinks.
Definition: EventSink.cs:9
virtual string ObjectID
Object ID, used when logging events.
Definition: LogObject.cs:25
Event sink that forwards events as notification messages to administrators.
AlertNotifier(string ObjectID)
Event sink that forwards events as notification messages to administrators.
override Task Queue(Event Event)
Queues an event to be output.
Static class managing the runtime environment of the IoT Gateway.
Definition: Gateway.cs:126
static Task SendNotification(Graph Graph)
Sends a graph as a notification message to configured notification recipients.
Definition: Gateway.cs:3826