public void SendAlarm(AlarmMessage message)
        {
            var payload = new Payload();
            var msgText = $"{message.Level} level alarm raised by {message.Origin}";
            var att     = new Payload.Attachment();

            att.Fallback  = msgText;
            att.Color     = GetAlarmColour(message.Level);
            att.Pretext   = msgText;
            att.Title     = $"{message.Message}";
            att.TitleLink = "";

            if (message.StorageID != null)
            {
                var field = new Payload.AttachmentField();
                field.Title = $"StorageID";
                field.Value = message.StorageID;
                field.Short = true;
                att.Fields.Add(field);
            }
            if (message.ExceptionMessage != null)
            {
                var field = new Payload.AttachmentField();
                field.Title = $"Caught Exception";
                field.Value = message.ExceptionMessage;
                field.Short = true;
                att.Fields.Add(field);
            }

            payload.Attachments.Add(att);
            payload.Username = message.Origin;
            PostMessage(payload);
        }
Exemple #2
0
        public void SendAlarm(AlarmMessage message)
        {
            var con = Collection.Where(c => c.Level == message.Level);

            foreach (var connection in con)
            {
                connection.Channel.SendAlarm(message);
            }
        }
            public void RuleTriggeredByTimeout(TimeBetweenOperations rule)
            {
                var msg = new AlarmMessage(rule.AlarmLevel, rule.ProgramName, $"Rule {rule.RuleName} triggered. Message: {rule.AlarmMessage}");

                AlarmMessageManager.RaiseAlarm(msg);
#if DEBUG
                Debug.WriteLine($"ALARM! {rule.AlarmLevel} level. From {rule.ProgramName}. Message: {rule.AlarmMessage}");
#endif
            }
Exemple #4
0
 public void RaiseAlarm(AlarmMessage message)
 {
     try
     {
         Queue.SendMessage(message);
     }
     catch (Exception)
     {
         //retry once;
         Queue.SendMessage(message);
     }
 }
            private void MainLoop()
            {
                if (EventQueue.TryDequeue(out SystemEvent fromQ))
                {
                    Parallel.ForEach(Rules.Where(r => string.IsNullOrEmpty(r.Value.OperationName) || r.Value.OperationName.Equals(fromQ.OperationName)), rule =>
                    {
                        if (rule.Value.AddAndCheckIfTriggered(fromQ))
                        {
                            var msg = new AlarmMessage(rule.Value.AlarmLevel, fromQ.AppInfo.ApplicationName, $"Rule {rule.Value.RuleName} triggered. Message: {rule.Value.AlarmMessage}", fromQ.CaughtException.Message, fromQ.ID);
                            AlarmMessageManager.RaiseAlarm(msg);
#if DEBUG
                            Debug.WriteLine($"ALARM! {rule.Value.AlarmLevel} level. From {fromQ.AppInfo.ApplicationName}. Message: {rule.Value.AlarmMessage}");
#endif
                        }
                    });
                }
                else
                {
                    AnalyzerChangeState(State.Stopped);
                }
            }
            public void StartAnalyzer()
            {
                var analyzerThread = new Thread(() =>
                {
                    try
                    {
                        AnalyzerChangeState(State.Running);
                        while (State == State.Running)
                        {
                            MainLoop();
                        }
                        while (EventQueue.Count > 0)
                        {
                            MainLoop();
                        }
                        AnalyzerChangeState(State.Stopped);
                    }
                    catch (Exception ex)
                    {
                        try
                        {
                            AnalyzerChangeState(State.Stopped);
                            var message = $"Exception in {nameof(ProgramAnalyzer)}.{nameof(StartAnalyzer)} for {ProgramName}.";
                            OnReportException?.Invoke(message, ex);
                            var alarmMessage = new AlarmMessage(AlarmLevel.Medium, AppDomain.CurrentDomain.FriendlyName, message, ex.InnerException?.Message ?? ex.Message);
                            AlarmMessageManager.RaiseAlarm(alarmMessage);
                        }
                        catch (Exception ex2)
                        {
                            OnReportException?.Invoke("Exception in Exception handling", ex2);
                        }
                    }
                }
                                                );

                analyzerThread.Priority = ThreadPriority.Highest;
                analyzerThread.Name     = nameof(analyzerThread) + "_" + ProgramName;
                analyzerThread.Start();
            }
        /// <summary>
        /// Starts the engine task.
        /// </summary>
        /// <returns></returns>
        private void StartEngine()
        {
            var engineThread = new Thread(() =>
            {
                try
                {
                    ChangeState(State.Running);
                    AddMessage("Main engine thread started.");
                    while (State == State.Running)
                    {
                        MainLoop();
                    }
                    AddMessage($"Shutting down. Running main loop until main queue is empty. {MainEventQueue.Count} events in queue.");
                    while (MainEventQueue.Count > 0)
                    {
                        MainLoop();
                    }
                    AddMessage("Main queue emptied. Shutting down analyzers");
                    foreach (var analyzer in Analyzers)
                    {
                        AddMessage($"Stopping analyzer for {analyzer.Key}");
                        analyzer.Value.StopAnalyzer();
                    }
                }
                catch (Exception ex)
                {
                    ChangeState(State.Stopped);
                    var message = $"Exception in {nameof(AnalyzerEngine)}.{nameof(StartEngine)}. Engine is down. Engine will try to restart.";
                    OnReportException?.Invoke(message, ex);
                    var alarmMessage = new AlarmMessage(AlarmLevel.Medium, AppDomain.CurrentDomain.FriendlyName, message, ex.Message);
                    AlarmMessageManager.RaiseAlarm(alarmMessage);
                }
            });

            engineThread.Priority = ThreadPriority.Highest;
            engineThread.Name     = nameof(engineThread);
            engineThread.Start();
        }
Exemple #8
0
 public async Task RaiseAlarmAsync(AlarmMessage message)
 {
     await Queue.SendMessageAsync(message);
 }