Ejemplo n.º 1
0
        public void AddMessage(TimeStampedMessage <T> message, string messageIdentifier)
        {
            AggregatedMessage <T> value;

            if (Collection.TryGetValue(messageIdentifier, out value))
            {
                value.AmountCounter++;
                if (message.TimeStamp < value.FirstOccurrence)
                {
                    value.FirstOccurrence = message.TimeStamp;
                }
                if (message.TimeStamp > value.LastOccurrence)
                {
                    value.LastOccurrence = message.TimeStamp;
                }
            }
            else
            {
                var newTracker = new AggregatedMessage <T>();
                newTracker.AmountCounter   = 1;
                newTracker.Message         = message.Message;
                newTracker.FirstOccurrence = newTracker.LastOccurrence = message.TimeStamp;
                Collection.Add(messageIdentifier, newTracker);
            }
        }
        public void SendAggregatedAlarm(AggregatedMessage <AlarmMessage> aggregated)
        {
            var payload = new Payload();

            payload.Username = aggregated.Message.Origin;
            var msgText = $"{aggregated.Message.Origin} caused an alarm flood.";
            var att     = new Payload.Attachment();

            att.Fallback  = msgText;
            att.Color     = GetAlarmColour(aggregated.Message.Level);
            att.Pretext   = msgText;
            att.Title     = $"{aggregated.Message.Message}";
            att.TitleLink = "";
            var amountField = new Payload.AttachmentField();

            amountField.Title = $"Number of occurrences: {aggregated.AmountCounter}";
            var firstField = new Payload.AttachmentField();
            var lastField  = new Payload.AttachmentField();

            firstField.Title = "First occurrence";
            firstField.Value = $"{aggregated.FirstOccurrence} UTC";
            lastField.Title  = "Last occurrence";
            lastField.Value  = $"{aggregated.LastOccurrence} UTC";
            firstField.Short = lastField.Short = true;
            att.Fields.Add(amountField);
            att.Fields.Add(firstField);
            att.Fields.Add(lastField);
            payload.Attachments.Add(att);
            PostMessage(payload);
        }