Пример #1
0
        public void CreateAlarmParser()
        {
            var configpath = "some_path_to_config_file";
            var parser     = new AlarmParser(configpath);

            Assert.AreEqual(configpath, parser.ConfigFileFullPath, "Config Path");
        }
        public void LogsError_OnImproperlyFormattedJson()
        {
            // Arrange
            // no commas
            string data = "{\"created\":1539035437937\"modified\":1539035437937\"rule.description\":\"description\"\"rule.severity\":\"Warning\"}";

            // Act
            var result = AlarmParser.ParseAlarmList(data, this.loggerMock.Object);

            // Assert
            this.loggerMock.Verify(x => x.Error(It.IsAny <string>(), It.IsAny <Func <object> >()));
            Assert.Empty(result);
        }
Пример #3
0
        /**
         * Processes all alarms and executes any actions associated with the alarms
         */
        public async Task ProcessEventsAsync(PartitionContext context, IEnumerable <EventData> messages)
        {
            foreach (EventData eventData in messages)
            {
                if (eventData.Body.Array != null)
                {
                    string data = Encoding.UTF8.GetString(eventData.Body.Array);
                    IEnumerable <AsaAlarmApiModel> alarms = AlarmParser.ParseAlarmList(data, this.logger);
                    await this.actionManager.ExecuteAlarmActions(alarms);
                }
            }

            await context.CheckpointAsync();
        }
Пример #4
0
        public void GetNextAlarm()
        {
            var alarmsConfig = @"
10:45 file1
12:00 file2
22:00 file3
22:30 file4
";
            var lines        = alarmsConfig.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
            var parser       = new AlarmParser("invalid_config_file");
            var result       = parser.GetNextAlarm(TimeSpan.FromHours(11.00), parser.Parse(lines));

            result.ShouldBeEquivalentTo(new AlarmConfig
            {
                Time      = TimeSpan.FromHours(12.00),
                SoundPath = "file2",
            });
        }
Пример #5
0
        public void ParseAlarm()
        {
            var alarmsConfig = @"
10:45 file1

11:30 url1

12:00 file2
22:00 url2
22:30 file3
23:00 url3
";
            var lines        = alarmsConfig.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
            var parser       = new AlarmParser("invalid_config_file");
            var result       = parser.Parse(lines);

            result.Should().Equal(
                new AlarmConfig[] {
                new AlarmConfig {
                    Time = TimeSpan.FromHours(10.75), SoundPath = "file1"
                },
                new AlarmConfig {
                    Time = TimeSpan.FromHours(11.5), SoundPath = "url1"
                },
                new AlarmConfig {
                    Time = TimeSpan.FromHours(12), SoundPath = "file2"
                },
                new AlarmConfig {
                    Time = TimeSpan.FromHours(22), SoundPath = "url2"
                },
                new AlarmConfig {
                    Time = TimeSpan.FromHours(22.5), SoundPath = "file3"
                },
                new AlarmConfig {
                    Time = TimeSpan.FromHours(23), SoundPath = "url3"
                }
            }
                );
        }
        public void CanParse_ProperlyFormattedJson()
        {
            // Arrange
            string data = "{\"created\":1539035437937,\"modified\":1539035437937,\"rule.description\":\"description\",\"rule.severity\":\"Warning\",\"rule.id\":\"TestRuleId\",\"rule.actions\":[{\"Type\":\"Email\",\"Parameters\":{\"Notes\":\"Test Note\",\"Subject\":\"Test Subject\",\"Recipients\":[\"[email protected]\"]}}],\"device.id\":\"Test Device Id\",\"device.msg.received\":1539035437937}" +
                          "{\"created\":1539035437940,\"modified\":1539035437940,\"rule.description\":\"description2\",\"rule.severity\":\"Info\",\"rule.id\":\"1234\",\"device.id\":\"Device Id\",\"device.msg.received\":1539035437940}";

            // Act
            var result = AlarmParser.ParseAlarmList(data, this.loggerMock.Object);

            // Assert
            AsaAlarmApiModel[] resultArray = result.ToArray();
            Assert.Equal(2, resultArray.Length);
            Assert.Equal("description", resultArray[0].RuleDescription);
            Assert.Equal("description2", resultArray[1].RuleDescription);
            Assert.Equal(1, resultArray[0].Actions.Count);
            var action = resultArray[0].Actions[0];

            Assert.Equal(ActionType.Email, action.Type);
            var recipients = ((EmailAction)action).GetRecipients();

            Assert.Single(recipients);
            Assert.Equal("*****@*****.**", recipients[0]);
        }