Example #1
0
        private static string ConstructTextBody(AlertEntry logEntry)
        {
            var builder = new StringBuilder();

            builder.AppendLine("Hi,");
            builder.AppendLine($"File : {logEntry.FileName} : {logEntry.LineNumber}");
            builder.AppendLine($"LogLevel : {logEntry.LogLevel}");
            builder.AppendLine($"At time : {logEntry.LogTime}");

            if (logEntry.Tags != null)
            {
                builder.AppendLine($"Tags : {logEntry.Tags}");
            }

            builder.AppendLine($"Message : {logEntry.Text}");

            if (logEntry.Conclusions != null)
            {
                builder.AppendLine($"Conclusion : {logEntry.Conclusions}");
            }

            if (logEntry.Exception != null)
            {
                builder.AppendLine("Exception: ");
                logEntry.Exception.ToStringBuilder(builder, "");
            }

            builder.AppendLine();
            builder.AppendLine("Automatic message of CK-Glouton");
            builder.AppendLine("A problem ? https://github.com/ZooPin/ck-glouton/issues");

            return(builder.ToString());
        }
Example #2
0
 public void Send(AlertEntry logEntry)
 {
     using (var client = new SmtpClient())
     {
         client.Connect(_configuration.SmtpAddress, _configuration.SmtpPort, SecureSocketOptions.Auto);
         client.Authenticate(_configuration.SmtpUsername, _configuration.SmtpPassword);
         client.Send(ConstructMail(logEntry));
         client.Disconnect(true);
     }
 }
Example #3
0
        public void OnGrandOutputEventInfo(ReceivedData receivedData)
        {
            var version = Convert.ToInt32(receivedData.ServerClientSession.ClientData["LogEntryVersion"]);

            _memoryStream.SetLength(0);
            _memoryStream.Write(receivedData.Data.ToArray(), 0, receivedData.Data.Count);
            _memoryStream.Seek(0, SeekOrigin.Begin);

            var logEntry = LogEntry.Read(_binaryReader, version, out _) as IMulticastLogEntry;

            receivedData.ServerClientSession.ClientData.TryGetValue("AppName", out var appName);
            var alertEntry = new AlertEntry(logEntry, appName);

            List <IAlertModel> faulty = null;

            foreach (var alert in _alerts)
            {
                try
                {
                    if (!alert.Condition(alertEntry))
                    {
                        continue;
                    }

                    _activityMonitor.Info("An alert has been sent");
                    foreach (var sender in alert.Senders)
                    {
                        sender.Send(alertEntry);
                    }
                }
                catch (Exception exception)
                {
                    const string message = "Alert crashed.";
                    _activityMonitor.Fatal(message, exception);
                    if (faulty == null)
                    {
                        faulty = new List <IAlertModel>();
                    }
                    faulty.Add(alert);
                }
            }

            if (faulty == null)
            {
                return;
            }

            foreach (var faultyAlert in faulty)
            {
                _alerts.Remove(faultyAlert);
            }
        }
Example #4
0
        private MimeMessage ConstructMail(AlertEntry logEntry)
        {
            var message = new MimeMessage();

            message.From.Add(_from);
            foreach (var to in _to)
            {
                message.To.Add(to);
            }

            message.Subject = $"CK-Glouton Automatic Alert.";
            message.Body    = new TextPart("plain")
            {
                Text = ConstructTextBody(logEntry)
            };

            return(message);
        }
Example #5
0
        public void Send(AlertEntry logEntry)
        {
            if (logEntry == null)
            {
                throw new ArgumentNullException(nameof(logEntry));
            }

            var values = new Dictionary <string, string>
            {
                { "AppName", logEntry.AppName },
                { "LogType", logEntry.LogType.ToString() },
                { "LogLevel", logEntry.LogLevel.ToString() },
                { "Text", logEntry.Text },
                { "Tags", logEntry.Tags.ToString() },
                { "LogTime", logEntry.LogTime.ToString() },
                { "FileName", logEntry.FileName },
                { "LineNumber", logEntry.LineNumber.ToString() },
                { "MonitorId", logEntry.MonitorId.ToString() },
                { "GroupDepth", logEntry.GroupDepth.ToString() },
                { "PreviousEntryType", logEntry.PreviousEntryType.ToString() },
                { "PreviousLogTime", logEntry.PreviousLogTime.ToString() }
            };

            if (logEntry.Exception != null)
            {
                values.Add("Exception.Message", logEntry.Exception.Message);
                values.Add("Exception.StackTrace", logEntry.Exception.StackTrace);
                values.Add("Exception.FileName", logEntry.Exception.FileName);
            }

            if (logEntry.Conclusions != null)
            {
                var stringBuilder = new StringBuilder();
                foreach (var conclusion in logEntry.Conclusions)
                {
                    stringBuilder.Append($"{conclusion};");
                }
                values.Add("Conclusions", stringBuilder.ToString());
            }

            Client.PostAsync(_url, new FormUrlEncodedContent(values)).GetAwaiter().GetResult();
        }